Skip to content

Commit 21e7287

Browse files
authored
Merge pull request #321 from Unity-Technologies/UNI-39999-fix-export-set-created-with-invalid-chars
UNI-39999 make sure set name doesn't contain invalid chars
2 parents b1cce3d + 4f59bbb commit 21e7287

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

Assets/Integrations/Autodesk/maya/scripts/unityCommands.mel

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,25 @@ proc string checkNamespaceNeedsUpdate(string $unitySet, string $unityFbxNamespac
129129
return $unityFbxNamespace;
130130
}
131131

132+
global proc string formValidObjectName(string $input)
133+
{
134+
string $output = "";
135+
for ($n = 1 ; $n < size($input)+1 ; $n++)
136+
{
137+
string $char = `substring $input $n $n`;
138+
// if starting with a number, add underscore before number
139+
if ($n == 1 && `match "[0-9]" $char` != "")
140+
$output += ("_"+$char);
141+
// if character is alphanumeric, or underscore, add character
142+
else if (`match "[a-zA-Z0-9\_]" $char` != "")
143+
$output += $char;
144+
// otherwise replace with underscore
145+
else
146+
$output += "_";
147+
}
148+
return $output;
149+
}
150+
132151
proc importFile(string $filePathStr){
133152
// get the global variables
134153
global string $UnityExportSets[];
@@ -154,6 +173,8 @@ proc importFile(string $filePathStr){
154173

155174
$fileNameWithoutExt = match("[^@]+", $fileNameWithoutExt);
156175
}
176+
$fileNameWithoutExt = formValidObjectName($fileNameWithoutExt);
177+
157178
$unityExportSet = `format -stringArg $fileNameWithoutExt $UnityExportSetNameFormat`;
158179

159180
string $origNamespace = `namespaceInfo -cur -an`;

0 commit comments

Comments
 (0)