@@ -112,20 +112,33 @@ proc importFile(string $filePathStr){
112
112
}
113
113
$unityExportSet = `format -stringArg $nameWithoutExt $UnityExportSetNameFormat`;
114
114
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
+ }
116
127
117
128
// 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;
125
141
}
126
- }
127
- else{
128
- namespace -add $nameWithoutExt;
129
142
}
130
143
131
144
// Gather everything that is in the scene
@@ -134,6 +147,10 @@ proc importFile(string $filePathStr){
134
147
// Get or create the Unity Fbx Export Set
135
148
$setCreated = false;
136
149
if (!setExists($unityExportSet)){
150
+ if(!`namespaceInfo -isRootNamespace $origNamespace`){
151
+ namespace -set ":";
152
+ }
153
+
137
154
// couldn't find export set so create it
138
155
sets -name $unityExportSet;
139
156
$setCreated = true;
@@ -149,12 +166,12 @@ proc importFile(string $filePathStr){
149
166
storeAttribute($unityExportSet, $UnityFbxNamespaceAttr, "");
150
167
}
151
168
152
- if($origNamespace != $nameWithoutExt ){
153
- namespace -set $nameWithoutExt ;
169
+ if(`namespaceInfo -cur -an` != $targetNamespace ){
170
+ namespace -set $targetNamespace ;
154
171
}
155
172
file -import -type "FBX" -ignoreVersion -ra true -mergeNamespacesOnClash true -pr -importFrameRate true -importTimeRange "override" $filePathStr;
156
173
157
- if($origNamespace != $nameWithoutExt ){
174
+ if(`namespaceInfo -cur -an` != $origNamespace ){
158
175
namespace -set $origNamespace;
159
176
}
160
177
@@ -175,7 +192,7 @@ proc importFile(string $filePathStr){
175
192
}
176
193
177
194
if($nameWithoutExt != ""){
178
- storeAttribute($unityExportSet, $UnityFbxNamespaceAttr, `namespaceInfo -an $nameWithoutExt` );
195
+ storeAttribute($unityExportSet, $UnityFbxNamespaceAttr, $targetNamespace );
179
196
}
180
197
181
198
if (setExists($unityExportSet) == true){
0 commit comments