Skip to content

Commit 39c1e53

Browse files
committed
use absolute namespaces
- before creating a new namespace, check if there is already an export set for this file. If there is take the namespace defined in the export set. - make sure to add the new set to the root namespace, otherwise will have trouble finding the set
1 parent a4a452e commit 39c1e53

File tree

1 file changed

+32
-15
lines changed

1 file changed

+32
-15
lines changed

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

Lines changed: 32 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -112,20 +112,33 @@ proc importFile(string $filePathStr){
112112
}
113113
$unityExportSet = `format -stringArg $nameWithoutExt $UnityExportSetNameFormat`;
114114

115-
string $origNamespace = `namespaceInfo -cur`;
115+
string $origNamespace = `namespaceInfo -cur -an`;
116+
string $targetNamespace = `format -s $origNamespace -s $nameWithoutExt "^1s:^2s"`;
117+
118+
$setNamespaceExists = false;
119+
if (setExists($unityExportSet)){
120+
// get namespace from set
121+
$setNamespace = getAttribute($unityExportSet, $UnityFbxNamespaceAttr);
122+
if($setNamespace != "" && `namespace -exists $setNamespace`){
123+
$targetNamespace = $setNamespace;
124+
$setNamespaceExists = true;
125+
}
126+
}
116127

117128
// warn if namespace already exists
118-
if(`namespace -exists $nameWithoutExt` || $origNamespace == $nameWithoutExt){
119-
if(!showConfirmDialog("Warning",
120-
"Namespace already exists, the imported objects will be added to the existing namespace and export set.",
121-
"Continue", "Cancel"
122-
)){
123-
// cancelled, don't import this fbx
124-
return;
129+
if(!$setNamespaceExists){
130+
if(`namespace -exists $targetNamespace`){
131+
if(!showConfirmDialog("Warning",
132+
"Namespace already exists, the imported objects will be added to the existing namespace and export set.",
133+
"Continue", "Cancel"
134+
)){
135+
// cancelled, don't import this fbx
136+
return;
137+
}
138+
}
139+
else{
140+
namespace -add $targetNamespace;
125141
}
126-
}
127-
else{
128-
namespace -add $nameWithoutExt;
129142
}
130143

131144
// Gather everything that is in the scene
@@ -134,6 +147,10 @@ proc importFile(string $filePathStr){
134147
// Get or create the Unity Fbx Export Set
135148
$setCreated = false;
136149
if (!setExists($unityExportSet)){
150+
if(!`namespaceInfo -isRootNamespace $origNamespace`){
151+
namespace -set ":";
152+
}
153+
137154
// couldn't find export set so create it
138155
sets -name $unityExportSet;
139156
$setCreated = true;
@@ -149,12 +166,12 @@ proc importFile(string $filePathStr){
149166
storeAttribute($unityExportSet, $UnityFbxNamespaceAttr, "");
150167
}
151168

152-
if($origNamespace != $nameWithoutExt){
153-
namespace -set $nameWithoutExt;
169+
if(`namespaceInfo -cur -an` != $targetNamespace){
170+
namespace -set $targetNamespace;
154171
}
155172
file -import -type "FBX" -ignoreVersion -ra true -mergeNamespacesOnClash true -pr -importFrameRate true -importTimeRange "override" $filePathStr;
156173

157-
if($origNamespace != $nameWithoutExt){
174+
if(`namespaceInfo -cur -an` != $origNamespace){
158175
namespace -set $origNamespace;
159176
}
160177

@@ -175,7 +192,7 @@ proc importFile(string $filePathStr){
175192
}
176193

177194
if($nameWithoutExt != ""){
178-
storeAttribute($unityExportSet, $UnityFbxNamespaceAttr, `namespaceInfo -an $nameWithoutExt`);
195+
storeAttribute($unityExportSet, $UnityFbxNamespaceAttr, $targetNamespace);
179196
}
180197

181198
if (setExists($unityExportSet) == true){

0 commit comments

Comments
 (0)