Skip to content

Commit 24621b5

Browse files
committed
create placeholder model file name for dialog
- create path if it doesn't exist when exporting - clean up implementation
1 parent 36f26ab commit 24621b5

File tree

1 file changed

+89
-58
lines changed

1 file changed

+89
-58
lines changed

Integrations/Autodesk/maya/scripts/unityCommands.mel

Lines changed: 89 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -525,7 +525,12 @@ proc exportSet(string $unitySet, int $exportAnim){
525525

526526
string $unityFbxFilePath = getAttribute($unitySet, $pathAttr);
527527
string $unityFbxFileName = getAttribute($unitySet, $nameAttr);
528-
528+
529+
// make sure the file path exists
530+
if(!(`filetest -d $unityFbxFilePath`)){
531+
sysFile -makeDir $unityFbxFilePath;
532+
}
533+
529534
$strCmd = "";
530535
if ($unityFbxFilePath != "" && $unityFbxFileName != ""){
531536
// export selected, relative to given namespace
@@ -616,20 +621,7 @@ proc setupNewExportSet(
616621

617622
string $origNamespace = `namespaceInfo -cur -an`;
618623

619-
if($namespace == ":"){
620-
// do nothing
621-
}
622-
// warn if namespace already exists
623-
else if(`namespace -exists $namespace`){
624-
if(!showConfirmDialog("Warning: " + $modelFilename,
625-
$namespace + " namespace already exists, the selected objects will be added to the existing namespace and export set.",
626-
"Continue", "Cancel"
627-
)){
628-
// cancelled, don't import this fbx
629-
return;
630-
}
631-
}
632-
else{
624+
if($namespace != ":" && !(`namespace -exists $namespace`)){
633625
namespace -add $namespace;
634626
}
635627

@@ -676,9 +668,14 @@ proc setupNewExportSet(
676668

677669
// add to the targetNamespace
678670
// iterate over all selected objects and rename
679-
if ($namespace != ""){
671+
if ($namespace != ":"){
672+
// remove the colon from the beginning of the namespace
673+
// because the $object name does not start with a colon.
674+
$namespace = `substring $namespace 2 (size($namespace))`;
680675
for($object in $selectedObjects){
681-
rename $object ($namespace + ":" + $object);
676+
if(!startsWith($object, $namespace)){
677+
rename $object ($namespace + ":" + $object);
678+
}
682679
}
683680
}
684681

@@ -752,65 +749,37 @@ global proc unityOpenFileDialog(string $textField)
752749
textField -e -text $exportFilePath $textField;
753750
}
754751

755-
proc string createFilePathField(string $label, string $parent){
752+
proc string createFilePathField(string $label, string $parent, int $labelSize, int $textFieldSize){
756753
rowLayout
757754
-numberOfColumns 3
758-
-columnWidth3 150 250 50
755+
-columnWidth3 $labelSize $textFieldSize 50
759756
-columnAlign3 "right" "left" "left"
760757
-p $parent;
761758

762759
string $unityProject = `optionVar -q "UnityProject"`;
763760
$unityProject = $unityProject + "/Assets";
764761

765762
text -label $label;
766-
string $textField = `textField -width 250 -text $unityProject`;
763+
string $textField = `textField -width $textFieldSize -text $unityProject`;
767764
button -label "..." -recomputeSize false -height 15 -command ("unityOpenFileDialog " + $textField);
768765

769766
return $textField;
770767
}
771768

772-
proc string createTextFieldWithLabel(string $label, string $parent)
769+
proc string createTextFieldWithLabel(string $label, string $parent, int $labelSize, int $textFieldSize)
773770
{
774771
rowLayout
775772
-numberOfColumns 2
776-
-columnWidth2 150 250
773+
-columnWidth2 $labelSize $textFieldSize
777774
-columnAlign2 "right" "left"
778775
-p $parent;
779776

780777
text -label $label;
781-
string $textField = `textField -width 250`;
778+
string $textField = `textField -width $textFieldSize`;
782779
return $textField;
783780
}
784781

785-
proc createExportSetDialog(int $exportType){
786-
$origSelection = `ls -sl`;
787-
if(size($origSelection) <= 0){
788-
// nothing selected
789-
print ("Nothing selected");
790-
return;
791-
}
792-
793-
$exportAnim = false;
794-
$exportAnimOnly = false;
795-
switch($exportType){
796-
case 0 /* export animation only */:
797-
$exportAnim = true;
798-
$exportAnimOnly = true;
799-
break;
800-
case 1 /* export model only */:
801-
break;
802-
default: /* export model + animation */
803-
$exportAnim = true;
804-
break;
805-
}
806-
807-
// open up a dialog for choosing the export set options
808-
string $window = `window -title "FBX Export Options" -iconName "Short Name" -widthHeight 475 250`;
809-
810-
string $container = `formLayout -numberOfDivisions 100`;
811-
812-
string $mainOptions = `columnLayout -adjustableColumn true -p $container`;
813-
782+
proc string getCommonNamespace(string $origSelection[]){
814783
// gather up all the unique namespaces
815784
string $selectedNamespaces[];
816785
for($i = 0; $i < size($origSelection); $i++){
@@ -836,29 +805,91 @@ proc createExportSetDialog(int $exportType){
836805
int $intersectionSize = size($intersection);
837806
if($intersectionSize > $maxNamespaceCount ||
838807
// prefer more specific namespaces
839-
($maxNamespaceCount > 0 &&
808+
($maxNamespaceCount > 0 &&
840809
$intersectionSize == $maxNamespaceCount &&
841810
size($currNamespace) > size($commonNamespace))){
842811
$commonNamespace = $currNamespace;
843812
$maxNamespaceCount = $intersectionSize;
844813
}
845814
}
815+
return $commonNamespace;
816+
}
817+
818+
proc createExportSetDialog(int $exportType){
819+
$origSelection = `ls -sl`;
820+
if(size($origSelection) <= 0){
821+
// nothing selected
822+
print ("Nothing selected");
823+
return;
824+
}
825+
826+
$exportAnim = false;
827+
$exportAnimOnly = false;
828+
switch($exportType){
829+
case 0 /* export animation only */:
830+
$exportAnim = true;
831+
$exportAnimOnly = true;
832+
break;
833+
case 1 /* export model only */:
834+
break;
835+
default: /* export model + animation */
836+
$exportAnim = true;
837+
break;
838+
}
839+
840+
// open up a dialog for choosing the export set options
841+
string $window = `window -title "Unity FBX Export Options" -iconName "Short Name" -widthHeight 475 250`;
842+
843+
string $container = `formLayout -numberOfDivisions 100`;
846844

845+
string $mainOptions = `columnLayout -adjustableColumn true -p $container`;
846+
847+
// go through selection to find common namespace to set as default
848+
string $commonNamespace = getCommonNamespace($origSelection);
849+
850+
string $modelFilename = "Untitled";
851+
// if one item selected, take the name of it as the filename
852+
if (size($origSelection) == 1){
853+
// take the name of the selection without the namespace
854+
string $nTokens[];
855+
int $nNumTokens = `tokenize ("" + $origSelection[0]) ":" $nTokens`;
856+
$modelFilename = $nTokens[$nNumTokens-1];
857+
}
858+
else{
859+
// if multi items selected, but one of them is the root, then take the name of the root as the filename
860+
for($i = 0; $i < size($origSelection); $i++){
861+
string $descendents[] = `listRelatives -type "transform" -allDescendents $origSelection[$i]`;
862+
string $intersection[] = getIntersection($origSelection, $descendents);
863+
if (size($intersection) == size($origSelection)-1){
864+
// take the name of the selection without the namespace
865+
string $nTokens[];
866+
int $nNumTokens = `tokenize ("" + $origSelection[$i]) ":" $nTokens`;
867+
$modelFilename = $nTokens[$nNumTokens-1];
868+
break;
869+
}
870+
}
871+
}
872+
873+
int $labelSize = 120;
874+
int $textFieldSize = 300;
875+
847876
// get namespace
848-
string $namespaceField = createTextFieldWithLabel("Unity FBX namespace", $mainOptions);
877+
string $namespaceField = createTextFieldWithLabel("Namespace", $mainOptions, $labelSize, $textFieldSize);
849878
textField -e -text $commonNamespace $namespaceField;
850879

851880
string $modelFilePath = " 0 0";
852881
if(!$exportAnimOnly){
853-
string $modelFilePathField = createFilePathField("Unity FBX Model File Path", $mainOptions);
854-
string $modelFileNameField = createTextFieldWithLabel("Unity FBX Model File Name", $mainOptions);
882+
string $modelFilePathField = createFilePathField("Model File Path", $mainOptions, $labelSize, $textFieldSize);
883+
string $modelFileNameField = createTextFieldWithLabel("Model File Name", $mainOptions, $labelSize, $textFieldSize);
884+
textField -e -text ($modelFilename + ".fbx") $modelFileNameField;
855885
$modelFilePath = " " + $modelFilePathField + " " + $modelFileNameField;
856886
}
857887

858888
string $animFilePath = " 0 0";
859889
if($exportAnim){
860-
string $animFilePathField = createFilePathField("Unity FBX Anim File Path", $mainOptions);
861-
string $animFileNameField = createTextFieldWithLabel("Unity FBX Anim File Name", $mainOptions);
890+
string $animFilePathField = createFilePathField("Anim File Path", $mainOptions, $labelSize, $textFieldSize);
891+
string $animFileNameField = createTextFieldWithLabel("Anim File Name", $mainOptions, $labelSize, $textFieldSize);
892+
textField -e -text ($modelFilename + "@Take1.fbx") $animFileNameField;
862893
$animFilePath = " " + $animFilePathField + " " + $animFileNameField;
863894
}
864895

0 commit comments

Comments
 (0)