Skip to content

Commit 36f26ab

Browse files
committed
find common namespace to display in dialog
1 parent fec2348 commit 36f26ab

File tree

1 file changed

+28
-12
lines changed

1 file changed

+28
-12
lines changed

Integrations/Autodesk/maya/scripts/unityCommands.mel

Lines changed: 28 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -702,7 +702,7 @@ global proc unityOnCreateExportSet(
702702
print ("Nothing selected");
703703
return;
704704
}
705-
705+
706706
string $namespace = `textField -q -text $namespaceField`;
707707
if ($namespace == ""){
708708
$namespace = ":";
@@ -811,20 +811,36 @@ proc createExportSetDialog(int $exportType){
811811

812812
string $mainOptions = `columnLayout -adjustableColumn true -p $container`;
813813

814-
// go through selection to find common namespace to set as default
815-
string $commonNamespace = ":";
816-
int $maxNamespaceCount = 0;
814+
// gather up all the unique namespaces
815+
string $selectedNamespaces[];
817816
for($i = 0; $i < size($origSelection); $i++){
818817
string $currNamespace = getObjectNamespace($origSelection[$i]);
819-
while ($currNamespace != ":"){
820-
// get contents of namespace
821-
string $namespaceContents[] = `namespaceInfo -ls $currNamespace`;
822-
string $intersection[] = getIntersection($origSelection, $namespaceContents);
823-
if(size($intersection) > $maxNamespaceCount){
824-
$commonNamespace = $currNamespace;
825-
$maxNamespaceCount = size($intersection);
826-
}
818+
while ($currNamespace != ":" && !stringArrayContains($currNamespace, $selectedNamespaces)){
819+
$selectedNamespaces[size($selectedNamespaces)] = $currNamespace;
827820
$currNamespace = `namespaceInfo -p $currNamespace`;
821+
// make sure the namespace always starts with a colon
822+
if(!startsWith($currNamespace, ":")){
823+
$currNamespace = ":" + $currNamespace;
824+
}
825+
}
826+
}
827+
828+
// go through selection to find common namespace to set as default
829+
string $commonNamespace = ":";
830+
int $maxNamespaceCount = 0;
831+
for($i = 0; $i < size($selectedNamespaces); $i++){
832+
$currNamespace = $selectedNamespaces[$i];
833+
// get contents of namespace
834+
string $namespaceContents[] = `namespaceInfo -ls $currNamespace -r`;
835+
string $intersection[] = getIntersection($origSelection, $namespaceContents);
836+
int $intersectionSize = size($intersection);
837+
if($intersectionSize > $maxNamespaceCount ||
838+
// prefer more specific namespaces
839+
($maxNamespaceCount > 0 &&
840+
$intersectionSize == $maxNamespaceCount &&
841+
size($currNamespace) > size($commonNamespace))){
842+
$commonNamespace = $currNamespace;
843+
$maxNamespaceCount = $intersectionSize;
828844
}
829845
}
830846

0 commit comments

Comments
 (0)