Skip to content

Commit 7be5080

Browse files
committed
add export functionality
also move global variable definitions out of unityImport function
1 parent 83aa53b commit 7be5080

File tree

2 files changed

+70
-4
lines changed

2 files changed

+70
-4
lines changed

Assets/Integrations/Autodesk/mayalt/scripts/setupUnityUI.mel

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,11 @@ global proc setupUnityUI(){
77
evalDeferred -lowestPriority "buildFileMenu; \
88
$parentMenu = $gMainFileMenu; \
99
$pluginVersion = whatsNewVersion(); \
10+
source \"unityImport\"; \
1011
menuItem -parent $parentMenu -insertAfter $kMenuInsertAfter -divider true -longDivider false -version $pluginVersion $kMenuDivider; \
1112
menuItem -parent $parentMenu -insertAfter $kMenuDivider -subMenu true -label $kMenuLabel -tearOff true -version $pluginVersion $kMenuName; \
1213
menuItem -parent $kMenuName -label \"Import\" -version $pluginVersion -command \"unityImport\"; \
13-
menuItem -parent $kMenuName -label \"Export\" -version $pluginVersion;";
14+
menuItem -parent $kMenuName -label \"Export\" -version $pluginVersion -command \"unityExport\";";
1415
}
1516

1617
global proc string whatsNewVersion(){

Assets/Integrations/Autodesk/mayalt/scripts/unityImport.mel

Lines changed: 68 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
1+
global string $UnityExportSet = "UnityFbxExportSet";
2+
global string $UnityFbxFilePathAttr = "unityFbxFilePath";
3+
global string $UnityFbxFileNameAttr = "unityFbxFileName";
4+
15
global proc unityImport(){
2-
global string $UnityExportSet = "UnityFbxExportSet";
3-
global string $UnityFbxFilePathAttr = "unityFbxFilePath";
4-
global string $UnityFbxFileNameAttr = "unityFbxFileName";
6+
// get the global variables
7+
global string $UnityExportSet;
8+
global string $UnityFbxFilePathAttr;
9+
global string $UnityFbxFileNameAttr;
510

611
loadUnityDependencies;
712

@@ -74,6 +79,66 @@ global proc unityImport(){
7479
}
7580
}
7681

82+
83+
global proc unityExport(){
84+
// get the global variables
85+
global string $UnityExportSet;
86+
global string $UnityFbxFilePathAttr;
87+
global string $UnityFbxFileNameAttr;
88+
89+
if(!loadUnityDependencies()){
90+
return;
91+
}
92+
93+
if(!loadUnityFbxExportSettings()){
94+
return;
95+
}
96+
97+
// select the export set for export, if it exists,
98+
// otherwise take what is currently selected
99+
$origSelection = `ls -sl`;
100+
if (setExists($UnityExportSet)){
101+
select -r -ne $UnityExportSet;
102+
}
103+
104+
$unity_fbx_file_path = getAttribute($UnityExportSet, $UnityFbxFilePathAttr);
105+
$unity_fbx_file_name = getAttribute($UnityExportSet, $UnityFbxFileNameAttr);
106+
107+
$strCmd = "";
108+
if ($unity_fbx_file_path != "" && $unity_fbx_file_name != ""){
109+
$strCmd = "file -force -options \"\" -typ \"FBX export\" -pr -es \"" + $unity_fbx_file_path + "/" + $unity_fbx_file_name + "\"";
110+
}
111+
else {
112+
$strCmd = "SendToUnitySelection";
113+
}
114+
eval $strCmd;
115+
116+
select -cl;
117+
if (size($origSelection) > 0){
118+
select -add -ne $origSelection;
119+
}
120+
}
121+
122+
// Load the Export Settings from file
123+
global proc int loadUnityFbxExportSettings(){
124+
$fileName = `optionVar -q "UnityFbxExportSettings"`;
125+
126+
// check if the file exists
127+
if (`file -q -ex $fileName` == false){
128+
error ("Failed to find Unity Fbx Export Settings at: " + $fileName);
129+
return false;
130+
}
131+
eval ("source \"" + $fileName + "\"");
132+
return true;
133+
}
134+
135+
global proc string getAttribute(string $node, string $attr){
136+
if (`attributeExists $attr $node`){
137+
return `getAttr ($node + "." + $attr)`;
138+
}
139+
return "";
140+
}
141+
77142
global proc storeAttribute(string $node, string $attr, string $attrValue){
78143
$attrType="string";
79144
if (!attributeExists($attr, $node)){

0 commit comments

Comments
 (0)