Skip to content

Commit 5b9df87

Browse files
committed
code review fixes
- rename variables - show set name + namespace in popup - return valid namespace in checkNamespaceNeedsUpdate
1 parent ded816d commit 5b9df87

File tree

1 file changed

+43
-42
lines changed

1 file changed

+43
-42
lines changed

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

Lines changed: 43 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -111,20 +111,19 @@ proc string getNewNamespace(string $n1, string $n2){
111111
return $newNamespace;
112112
}
113113

114-
proc checkNamespaceNeedsUpdate(string $unitySet, string $objectNamespace){
115-
global string $UnityFbxNamespaceAttr;
116-
117-
string $unity_fbx_namespace = getAttribute($unitySet, $UnityFbxNamespaceAttr);
118-
string $newNamespace = getNewNamespace($unity_fbx_namespace, $objectNamespace);
119-
if($unity_fbx_namespace != $newNamespace){
114+
proc string checkNamespaceNeedsUpdate(string $unitySet, string $unityFbxNamespace, string $objectNamespace){
115+
string $newNamespace = getNewNamespace($unityFbxNamespace, $objectNamespace);
116+
if($unityFbxNamespace != $newNamespace){
120117
// popup asking to change namespace value to new namespace
121118
if(showConfirmDialog($unitySet,
122-
"Set namespace has been modified from "+$unity_fbx_namespace+" to "+$newNamespace+", update export set namespace attribute?",
119+
"Set namespace has been modified from "+$unityFbxNamespace+" to "+$newNamespace+", update export set namespace attribute?",
123120
"Yes", "No"
124121
)){
125122
storeAttribute($unitySet, $UnityFbxNamespaceAttr, $newNamespace);
123+
return $newNamespace;
126124
}
127125
}
126+
return $unityFbxNamespace;
128127
}
129128

130129
proc importFile(string $filePathStr){
@@ -136,36 +135,37 @@ proc importFile(string $filePathStr){
136135
global string $UnityFbxAnimFileNameAttr;
137136
global string $UnityFbxNamespaceAttr;
138137
global string $UnityExportSetNameFormat;
139-
140-
$tempPath = dirname($filePathStr);
141-
$tempName = basename($filePathStr, "");
142-
$tempAnimPath = "";
143-
$tempAnimName = "";
144-
$nameWithoutExt = basename($filePathStr, ".fbx");
138+
139+
$currentDir = dirname($filePathStr);
140+
$fileName = basename($filePathStr, "");
141+
$currentAnimDir = "";
142+
$animFileName = "";
143+
$fileNameWithoutExt = basename($filePathStr, ".fbx");
145144

146145
$isAnimFile = false;
147146
if(match("@", basename($filePathStr, ".fbx")) != ""){
148147
// import as animation
149148
$isAnimFile = true;
150-
$tempAnimPath = $tempPath;
151-
$tempAnimName = $tempName;
149+
$currentAnimDir = $currentDir;
150+
$animFileName = $fileName;
152151

153-
$nameWithoutExt = match("[^@]+", $nameWithoutExt);
152+
$fileNameWithoutExt = match("[^@]+", $fileNameWithoutExt);
154153
}
155-
$unityExportSet = `format -stringArg $nameWithoutExt $UnityExportSetNameFormat`;
154+
$unityExportSet = `format -stringArg $fileNameWithoutExt $UnityExportSetNameFormat`;
156155

157156
string $origNamespace = `namespaceInfo -cur -an`;
158-
string $targetNamespace = `format -s $origNamespace -s $nameWithoutExt "^1s:^2s"`;
157+
string $targetNamespace = `format -s $origNamespace -s $fileNameWithoutExt "^1s:^2s"`;
159158

160159
$setNamespaceExists = false;
161160
if (setExists($unityExportSet)){
162161
string $unitySetContents[] = `listConnections $unityExportSet`;
163-
if(size($unitySetContents) > 0){
164-
checkNamespaceNeedsUpdate($unityExportSet, getObjectNamespace($unitySetContents[0]));
165-
}
166162

167163
// get namespace from set
168164
$setNamespace = getAttribute($unityExportSet, $UnityFbxNamespaceAttr);
165+
if(size($unitySetContents) > 0){
166+
$setNamespace = checkNamespaceNeedsUpdate($unityExportSet, $setNamespace, getObjectNamespace($unitySetContents[0]));
167+
}
168+
169169
if($setNamespace != "" && `namespace -exists $setNamespace`){
170170
$targetNamespace = $setNamespace;
171171
$setNamespaceExists = true;
@@ -175,8 +175,8 @@ proc importFile(string $filePathStr){
175175
// warn if namespace already exists
176176
if(!$setNamespaceExists){
177177
if(`namespace -exists $targetNamespace`){
178-
if(!showConfirmDialog("Warning",
179-
"Namespace already exists, the imported objects will be added to the existing namespace and export set.",
178+
if(!showConfirmDialog("Warning: " + $fileName,
179+
$targetNamespace + " namespace already exists, the imported objects will be added to the existing namespace and export set.",
180180
"Continue", "Cancel"
181181
)){
182182
// cancelled, don't import this fbx
@@ -222,23 +222,23 @@ proc importFile(string $filePathStr){
222222
namespace -set $origNamespace;
223223
}
224224

225-
if ((!$isAnimFile || ($isAnimFile && $setCreated)) && $tempPath != ""){
226-
storeAttribute($unityExportSet, $UnityFbxFilePathAttr, $tempPath);
225+
if ((!$isAnimFile || ($isAnimFile && $setCreated)) && $currentDir != ""){
226+
storeAttribute($unityExportSet, $UnityFbxFilePathAttr, $currentDir);
227227
}
228228

229-
if ((!$isAnimFile || ($isAnimFile && $setCreated)) && $tempName != ""){
230-
storeAttribute($unityExportSet,$UnityFbxFileNameAttr,$tempName);
229+
if ((!$isAnimFile || ($isAnimFile && $setCreated)) && $fileName != ""){
230+
storeAttribute($unityExportSet,$UnityFbxFileNameAttr,$fileName);
231231
}
232232

233-
if($tempAnimPath != ""){
234-
storeAttribute($unityExportSet,$UnityFbxAnimFilePathAttr,$tempAnimPath);
233+
if($currentAnimDir != ""){
234+
storeAttribute($unityExportSet,$UnityFbxAnimFilePathAttr,$currentAnimDir);
235235
}
236236

237-
if($tempAnimName != ""){
238-
storeAttribute($unityExportSet,$UnityFbxAnimFileNameAttr,$tempAnimName);
237+
if($animFileName != ""){
238+
storeAttribute($unityExportSet,$UnityFbxAnimFileNameAttr,$animFileName);
239239
}
240240

241-
if($nameWithoutExt != ""){
241+
if($fileNameWithoutExt != ""){
242242
storeAttribute($unityExportSet, $UnityFbxNamespaceAttr, $targetNamespace);
243243
}
244244

@@ -306,11 +306,11 @@ global proc unityImport(){
306306
importFile($filePathStr);
307307
}
308308

309-
$tempPath = dirname($filePaths[0]);
309+
$currentDir = dirname($filePaths[0]);
310310
// Change Unity project if fbx is from a different Unity project.
311311
// Get the project based on the folder structure (i.e. folder above Assets)
312-
$head = dirname($tempPath);
313-
$tail = basename($tempPath, "");
312+
$head = dirname($currentDir);
313+
$tail = basename($currentDir, "");
314314
// Check that we are not at the root directory.
315315
// dirname($head) returns the last directory name in the path,
316316
// or head if head is the root directory.
@@ -349,10 +349,10 @@ proc exportSet(string $unitySet, int $exportAnim){
349349
global string $UnityFbxNamespaceAttr;
350350

351351
string $unitySetContents[] = `listConnections $unitySet`;
352-
string $unity_fbx_namespace = getAttribute($unitySet, $UnityFbxNamespaceAttr);
352+
string $unityFbxNamespace = getAttribute($unitySet, $UnityFbxNamespaceAttr);
353353

354354
if(size($unitySetContents) > 0){
355-
checkNamespaceNeedsUpdate($unitySet, getObjectNamespace($unitySetContents[0]));
355+
$unityFbxNamespace = checkNamespaceNeedsUpdate($unitySet, $unityFbxNamespace, getObjectNamespace($unitySetContents[0]));
356356
}
357357

358358
string $animatedObjectSet = "";
@@ -378,13 +378,14 @@ proc exportSet(string $unitySet, int $exportAnim){
378378
$nameAttr = $UnityFbxAnimFileNameAttr;
379379
}
380380

381-
string $unity_fbx_file_path = getAttribute($unitySet, $pathAttr);
382-
string $unity_fbx_file_name = getAttribute($unitySet, $nameAttr);
383-
$unity_fbx_namespace = getAttribute($unitySet, $UnityFbxNamespaceAttr);
381+
string $unityFbxFilePath = getAttribute($unitySet, $pathAttr);
382+
string $unityFbxFileName = getAttribute($unitySet, $nameAttr);
384383

385384
$strCmd = "";
386-
if ($unity_fbx_file_path != "" && $unity_fbx_file_name != ""){
387-
$strCmd = `format -s $unity_fbx_namespace -s $unity_fbx_file_path -s $unity_fbx_file_name "file -force -options \"\" -typ \"FBX export\" -relativeNamespace \"^1s\" -es \"^2s/^3s\""`;
385+
if ($unityFbxFilePath != "" && $unityFbxFileName != ""){
386+
// export selected, relative to given namespace
387+
string $exportFormat = "file -force -options \"\" -typ \"FBX export\" -relativeNamespace \"^1s\" -es \"^2s/^3s\"";
388+
$strCmd = `format -s $unityFbxNamespace -s $unityFbxFilePath -s $unityFbxFileName $exportFormat`;
388389
eval $strCmd;
389390
}
390391

0 commit comments

Comments
 (0)