Skip to content

Commit d59b551

Browse files
committed
finish implementing export set creation and export buttons
1 parent 370ac85 commit d59b551

File tree

1 file changed

+79
-37
lines changed

1 file changed

+79
-37
lines changed

Integrations/Autodesk/maya/scripts/unityCommands.mel

Lines changed: 79 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -573,45 +573,63 @@ proc string[] getUnityExportSets(){
573573
return $unityExportSets;
574574
}
575575

576-
proc setupNewExportSet(
576+
proc setupNewExportSet2(
577577
string $namespace,
578578
string $modelPath,
579579
string $modelFilename,
580580
string $animPath,
581-
string $animFilename){
581+
string $animFilename,
582+
string $selectedObjects[]){
582583

583-
$fileNameWithoutExt = $exportAttrs[$UnityFileNameWithoutExtIndex];
584+
if ($modelFilename == "" && $animFilename == ""){
585+
return;
586+
}
584587

585-
$unityExportSet = getNewExportSetName($fileNameWithoutExt);
588+
if ($modelPath == "" && $animPath == ""){
589+
return;
590+
}
591+
592+
string $exportFileNameWithoutExt = formValidObjectName(basename($modelFilename, ".fbx"));
593+
594+
$unityExportSet = getNewExportSetName($exportFileNameWithoutExt);
586595

587596
string $origNamespace = `namespaceInfo -cur -an`;
588-
string $targetNamespace = getTargetNamespaceName($fileNameWithoutExt);
589597

590-
$setNamespace = getSetNamespace($unityExportSet);
591-
$setNamespaceExists = ($setNamespace != "");
592-
if($setNamespaceExists){
593-
$targetNamespace = $setNamespace;
598+
if($namespace == ":"){
599+
// do nothing
594600
}
595-
else{
596-
// warn if namespace already exists
597-
if(`namespace -exists $targetNamespace`){
598-
if(!showConfirmDialog("Warning: " + $exportFileName,
599-
$targetNamespace + " namespace already exists, the selected objects will be added to the existing namespace and export set.",
600-
"Continue", "Cancel"
601-
)){
602-
// cancelled, don't import this fbx
603-
return;
604-
}
605-
}
606-
else{
607-
namespace -add $targetNamespace;
601+
// warn if namespace already exists
602+
else if(`namespace -exists $namespace`){
603+
if(!showConfirmDialog("Warning: " + $modelFilename,
604+
$namespace + " namespace already exists, the selected objects will be added to the existing namespace and export set.",
605+
"Continue", "Cancel"
606+
)){
607+
// cancelled, don't import this fbx
608+
return;
608609
}
609610
}
611+
else{
612+
namespace -add $namespace;
613+
}
610614

611615
// Get or create the Unity Fbx Export Set
612616
$setCreated = getOrCreateExportSet($unityExportSet, $origNamespace);
613617

614-
setExportSetAttributes($unityExportSet, $isAnimFile, $setCreated, $exportAttrs, $targetNamespace);
618+
global int $UnityFbxFilePathIndex;
619+
global int $UnityFbxFileNameIndex;
620+
global int $UnityFbxAnimFilePathIndex;
621+
global int $UnityFbxAnimFileNameIndex;
622+
global int $UnityFileNameWithoutExtIndex;
623+
624+
// Get the export set attributes
625+
string $exportAttrs[5];
626+
$exportAttrs[$UnityFbxFilePathIndex] = $modelPath;
627+
$exportAttrs[$UnityFbxFileNameIndex] = $modelFilename;
628+
$exportAttrs[$UnityFbxAnimFilePathIndex] = $animPath;
629+
$exportAttrs[$UnityFbxAnimFileNameIndex] = $animFilename;
630+
$exportAttrs[$UnityFileNameWithoutExtIndex] = $exportFileNameWithoutExt;
631+
632+
setExportSetAttributes($unityExportSet, /*$isAnimFile*/ false, $setCreated, $exportAttrs, $namespace);
615633

616634
if (setExists($unityExportSet) == true){
617635
// clear contents of set
@@ -625,12 +643,14 @@ proc setupNewExportSet(
625643

626644
// add to the targetNamespace
627645
// iterate over all selected objects and rename
628-
for($object in $selectedObjects){
629-
rename $object ($targetNamespace + ":" + $object);
646+
if ($namespace != ""){
647+
for($object in $selectedObjects){
648+
rename $object ($namespace + ":" + $object);
649+
}
630650
}
631651

632652
// switch project if file exported to a different Unity project
633-
switchUnityProject($exportPath);
653+
switchUnityProject($modelPath);
634654
}
635655

636656
proc setupNewExportSet(string $exportPath, int $exportAnimOnly, string $selectedObjects[]){
@@ -822,16 +842,37 @@ global proc unityOnCreateExportSet(
822842
string $modelPathField,
823843
string $modelFileField,
824844
string $animPathField,
825-
string $animFileField,
826-
string $origSelection[]){
845+
string $animFileField){
846+
847+
$origSelection = `ls -sl`;
848+
if(size($origSelection) <= 0){
849+
// nothing selected
850+
print ("Nothing selected");
851+
return;
852+
}
827853

828854
string $namespace = `textField -q -text $namespaceField`;
855+
if ($namespace == ""){
856+
$namespace = ":";
857+
}
829858
string $modelPath = `textField -q -text $modelPathField`;
830859
string $modelFilename = `textField -q -text $modelFileField`;
860+
if ($modelFilename != "" && !endsWith($modelFilename, ".fbx")){
861+
$modelFilename = $modelFilename + ".fbx";
862+
}
831863
string $animPath = `textField -q -text $animPathField`;
832864
string $animFilename = `textField -q -text $animFileField`;
865+
if ($animFilename != "" && !endsWith($animFilename, ".fbx")){
866+
$animFilename = $animFilename + ".fbx";
867+
}
833868

834-
//setupNewExportSet("", 0, $origSelection);
869+
setupNewExportSet2(
870+
$namespace,
871+
$modelPath,
872+
$modelFilename,
873+
$animPath,
874+
$animFilename,
875+
$origSelection);
835876

836877
deleteUI -window $window;
837878
}
@@ -897,11 +938,11 @@ global proc unityCreateExportSet(){
897938
// get namespace
898939
string $namespaceField = createTextFieldWithLabel("Unity FBX namespace", $mainOptions);
899940

900-
string $modelFilePath = createFilePathField("Unity FBX Model File Path", $mainOptions);
901-
string $modelFileName = createTextFieldWithLabel("Unity FBX Model File Name", $mainOptions);
941+
string $modelFilePathField = createFilePathField("Unity FBX Model File Path", $mainOptions);
942+
string $modelFileNameField = createTextFieldWithLabel("Unity FBX Model File Name", $mainOptions);
902943

903-
string $animFilePath = createFilePathField("Unity FBX Anim File Path", $mainOptions);
904-
string $animFileName = createTextFieldWithLabel("Unity FBX Anim File Name", $mainOptions);
944+
string $animFilePathField = createFilePathField("Unity FBX Anim File Path", $mainOptions);
945+
string $animFileNameField = createTextFieldWithLabel("Unity FBX Anim File Name", $mainOptions);
905946

906947
int $buttonWidth = 158;
907948
string $buttons = `rowLayout
@@ -910,16 +951,17 @@ global proc unityCreateExportSet(){
910951
-columnWidth3 $buttonWidth $buttonWidth $buttonWidth
911952
-columnAlign3 "center" "center" "center" -p $container`;
912953

913-
string $modelFilePath = " " + $modelFilePath + " " + $modelFileName;
914-
string $animFilePath = " " + $animFilePath + " " + $animFileName;
954+
string $modelFilePath = " " + $modelFilePathField + " " + $modelFileNameField;
955+
string $animFilePath = " " + $animFilePathField + " " + $animFileNameField;
956+
string $createExportSetCommand = "unityOnCreateExportSet " + $window + " " + $namespaceField + $modelFilePath + $animFilePath;
915957

916958
button -label "Create Set and Export"
917959
-width $buttonWidth
918-
-command "sphere"
960+
-command ($createExportSetCommand + ";" + "unityExportModelAnim()")
919961
-p $buttons;
920962
button -label "Create Set"
921963
-width $buttonWidth
922-
-command ("unityOnCreateExportSet " + $window + " " + $namespaceField + $modelFilePath + $animFilePath + " " + $origSelection)
964+
-command ($createExportSetCommand)
923965
-p $buttons;
924966
button -label "Cancel"
925967
-width $buttonWidth

0 commit comments

Comments
 (0)