Skip to content

Commit 370ac85

Browse files
committed
start connecting functionality for creating a set to dialog
1 parent 9dc93b1 commit 370ac85

File tree

1 file changed

+94
-12
lines changed

1 file changed

+94
-12
lines changed

Integrations/Autodesk/maya/scripts/unityCommands.mel

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

576+
proc setupNewExportSet(
577+
string $namespace,
578+
string $modelPath,
579+
string $modelFilename,
580+
string $animPath,
581+
string $animFilename){
582+
583+
$fileNameWithoutExt = $exportAttrs[$UnityFileNameWithoutExtIndex];
584+
585+
$unityExportSet = getNewExportSetName($fileNameWithoutExt);
586+
587+
string $origNamespace = `namespaceInfo -cur -an`;
588+
string $targetNamespace = getTargetNamespaceName($fileNameWithoutExt);
589+
590+
$setNamespace = getSetNamespace($unityExportSet);
591+
$setNamespaceExists = ($setNamespace != "");
592+
if($setNamespaceExists){
593+
$targetNamespace = $setNamespace;
594+
}
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;
608+
}
609+
}
610+
611+
// Get or create the Unity Fbx Export Set
612+
$setCreated = getOrCreateExportSet($unityExportSet, $origNamespace);
613+
614+
setExportSetAttributes($unityExportSet, $isAnimFile, $setCreated, $exportAttrs, $targetNamespace);
615+
616+
if (setExists($unityExportSet) == true){
617+
// clear contents of set
618+
sets -clear $unityExportSet;
619+
620+
// add newly imported items to set
621+
if (size($selectedObjects) > 0){
622+
sets -include $unityExportSet $selectedObjects;
623+
}
624+
}
625+
626+
// add to the targetNamespace
627+
// iterate over all selected objects and rename
628+
for($object in $selectedObjects){
629+
rename $object ($targetNamespace + ":" + $object);
630+
}
631+
632+
// switch project if file exported to a different Unity project
633+
switchUnityProject($exportPath);
634+
}
635+
576636
proc setupNewExportSet(string $exportPath, int $exportAnimOnly, string $selectedObjects[]){
577637
global int $UnityFbxFilePathIndex;
578638
global int $UnityFbxFileNameIndex;
@@ -756,10 +816,22 @@ global proc unityExportModelAnim(){
756816
unityExport($UnityExportModelAnim);
757817
}
758818

759-
global proc onCreateExportSet(string $window, string $contents){
760-
print ("\n" + $contents + "\n");
761-
string $text = `textField -q -text $contents`;
762-
print ("contents: " + $text);
819+
global proc unityOnCreateExportSet(
820+
string $window,
821+
string $namespaceField,
822+
string $modelPathField,
823+
string $modelFileField,
824+
string $animPathField,
825+
string $animFileField,
826+
string $origSelection[]){
827+
828+
string $namespace = `textField -q -text $namespaceField`;
829+
string $modelPath = `textField -q -text $modelPathField`;
830+
string $modelFilename = `textField -q -text $modelFileField`;
831+
string $animPath = `textField -q -text $animPathField`;
832+
string $animFilename = `textField -q -text $animFileField`;
833+
834+
//setupNewExportSet("", 0, $origSelection);
763835

764836
deleteUI -window $window;
765837
}
@@ -830,17 +902,29 @@ global proc unityCreateExportSet(){
830902

831903
string $animFilePath = createFilePathField("Unity FBX Anim File Path", $mainOptions);
832904
string $animFileName = createTextFieldWithLabel("Unity FBX Anim File Name", $mainOptions);
833-
905+
906+
int $buttonWidth = 158;
834907
string $buttons = `rowLayout
835908
-numberOfColumns 3
836909
-adjustableColumn3 1
837-
//-columnWidth3 120 120 120
910+
-columnWidth3 $buttonWidth $buttonWidth $buttonWidth
838911
-columnAlign3 "center" "center" "center" -p $container`;
839912

840-
button -label "Create Set and Export" -command "sphere" -p $buttons;
841-
button -label "Create Set" -command ("onCreateExportSet " + $window + " " + $namespaceField) -p $buttons;
842-
button -label "Cancel" -command ("deleteUI -window " + $window) -p $buttons;
843-
913+
string $modelFilePath = " " + $modelFilePath + " " + $modelFileName;
914+
string $animFilePath = " " + $animFilePath + " " + $animFileName;
915+
916+
button -label "Create Set and Export"
917+
-width $buttonWidth
918+
-command "sphere"
919+
-p $buttons;
920+
button -label "Create Set"
921+
-width $buttonWidth
922+
-command ("unityOnCreateExportSet " + $window + " " + $namespaceField + $modelFilePath + $animFilePath + " " + $origSelection)
923+
-p $buttons;
924+
button -label "Cancel"
925+
-width $buttonWidth
926+
-command ("deleteUI -window " + $window)
927+
-p $buttons;
844928

845929
formLayout -edit
846930
-attachForm $buttons "bottom" 1
@@ -852,6 +936,4 @@ global proc unityCreateExportSet(){
852936

853937
setParent ..;
854938
showWindow $window;
855-
856-
//setupNewExportSet("", 0, $origSelection);
857939
}

0 commit comments

Comments
 (0)