Skip to content

Commit dc30925

Browse files
committed
on export detect and change namespace if set contents namespace changed
1 parent 39c1e53 commit dc30925

File tree

1 file changed

+41
-1
lines changed

1 file changed

+41
-1
lines changed

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

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,32 @@ proc int showConfirmDialog(string $title, string $message, string $confirmButton
8585
return ( $response == $confirmButtonName );
8686
}
8787

88+
// get the namespace of the given object
89+
proc string getObjectNamespace(string $objectName){
90+
string $lsResult[] = `ls -showNamespace -an $objectName`;
91+
return $lsResult[1];
92+
}
93+
94+
proc string getNewNamespace(string $n1, string $n2){
95+
string $n2Tokens[];
96+
int $n2NumTokens = `tokenize $n2 ":" $n2Tokens`;
97+
98+
string $newNamespace = ":";
99+
string $n1BaseName = `namespaceInfo -baseName $n1`;
100+
101+
for($i=$n2NumTokens-1; $i>=0; --$i){
102+
if($n2Tokens[$i] == $n1BaseName){
103+
break;
104+
}
105+
$n2Tokens[$i] = "";
106+
}
107+
$newNamespace = $newNamespace + stringArrayToString($n2Tokens, ":");
108+
if($newNamespace == ":"){
109+
return $n2;
110+
}
111+
return $newNamespace;
112+
}
113+
88114
proc importFile(string $filePathStr){
89115
// get the global variables
90116
global string $UnityExportSets[];
@@ -302,6 +328,20 @@ proc exportSet(string $unitySet, int $exportAnim){
302328
global string $UnityFbxNamespaceAttr;
303329

304330
string $unitySetContents[] = `listConnections $unitySet`;
331+
string $unity_fbx_namespace = getAttribute($unitySet, $UnityFbxNamespaceAttr);
332+
333+
if(size($unitySetContents) > 0){
334+
string $newNamespace = getNewNamespace($unity_fbx_namespace, getObjectNamespace($unitySetContents[0]));
335+
if($unity_fbx_namespace != $newNamespace){
336+
// popup asking to change namespace value to new namespace
337+
if(showConfirmDialog($unitySet,
338+
"Set namespace has been modified from "+$unity_fbx_namespace+" to "+$newNamespace+", update export set namespace attribute?",
339+
"Yes", "No"
340+
)){
341+
storeAttribute($unitySet, $UnityFbxNamespaceAttr, $newNamespace);
342+
}
343+
}
344+
}
305345

306346
string $animatedObjectSet = "";
307347
if($exportAnim){
@@ -328,7 +368,7 @@ proc exportSet(string $unitySet, int $exportAnim){
328368

329369
string $unity_fbx_file_path = getAttribute($unitySet, $pathAttr);
330370
string $unity_fbx_file_name = getAttribute($unitySet, $nameAttr);
331-
string $unity_fbx_namespace = getAttribute($unitySet, $UnityFbxNamespaceAttr);
371+
$unity_fbx_namespace = getAttribute($unitySet, $UnityFbxNamespaceAttr);
332372

333373
$strCmd = "";
334374
if ($unity_fbx_file_path != "" && $unity_fbx_file_name != ""){

0 commit comments

Comments
 (0)