|
1 | 1 | -- MacroScripts that will perform actions
|
2 |
| -macroScript UnityImport category:"File-Import" |
| 2 | +macroScript UnityImport category:"Unity" iconName:"UnityIcons/import" |
3 | 3 | (
|
4 | 4 | origObjects = #()
|
5 | 5 |
|
@@ -45,7 +45,7 @@ macroScript UnityImport category:"File-Import"
|
45 | 45 | callbacks.removeScripts #postImport id:#unityPlugin
|
46 | 46 | )
|
47 | 47 | )
|
48 |
| -macroScript UnityExport category:"File-Export" |
| 48 | +macroScript UnityExport category:"Unity" iconName:"UnityIcons/export" |
49 | 49 | (
|
50 | 50 | fn loadUnityFbxExportSettings = (
|
51 | 51 | fbxExportSettings = getINISetting (GetMAXIniFile()) "Unity" "UnityFbxExportSettings"
|
@@ -84,98 +84,80 @@ macroScript UnityExport category:"File-Export"
|
84 | 84 | )
|
85 | 85 |
|
86 | 86 |
|
87 |
| -fileMenuName = "&File" |
88 |
| -importMenuName = "&Import" |
89 |
| -exportMenuName = "&Export" |
90 |
| -if (maxVersion())[1] < 20000 then( |
91 |
| - importMenuName += "..." |
92 |
| - exportMenuName += "..." |
93 |
| -) |
| 87 | +-- Setup UI using menu manager if using 3ds Max 2018+ |
| 88 | +if (maxVersion())[1] >= 20000 then( |
| 89 | + importMenuName = "File-Import" |
| 90 | + exportMenuName = "File-Export" |
| 91 | + |
| 92 | + -- get the import menu |
| 93 | + fn getImportMenu = ( |
| 94 | + menuMan.findMenu importMenuName |
| 95 | + ) |
94 | 96 |
|
95 |
| -fn getFileSubmenuItem menuName = ( |
96 |
| - foundMenuItem = undefined |
97 |
| - fileMenuItem = menuMan.findMenu fileMenuName |
98 |
| - local notFound = true |
99 |
| - if fileMenuItem != undefined then ( |
100 |
| - for i=1 to fileMenuItem.numItems() while notFound do( |
101 |
| - mi = fileMenuItem.getItem i |
102 |
| - if mi.getTitle() == menuName then( |
103 |
| - foundMenuItem = mi |
104 |
| - notFound = false |
| 97 | + -- get the export menu |
| 98 | + fn getExportMenu = ( |
| 99 | + menuMan.findMenu exportMenuName |
| 100 | + ) |
| 101 | + |
| 102 | + -- Setup UI |
| 103 | + fn setupUnityPluginUI = ( |
| 104 | + importMenu = getImportMenu() |
| 105 | + exportMenu = getExportMenu() |
| 106 | + if importMenu != undefined and exportMenu != undefined do |
| 107 | + ( |
| 108 | + unityImportTitle = "Import from Unity" |
| 109 | + unityExportTitle = "Export to Unity" |
| 110 | + |
| 111 | + -- check if menu items already exists |
| 112 | + foundUnityImport = false |
| 113 | + for i=1 to importMenu.numItems() while not foundUnityImport do( |
| 114 | + mi = importMenu.getItem i |
| 115 | + if mi.getTitle() == unityImportTitle then( |
| 116 | + foundUnityImport = true |
| 117 | + global unityImportAction = mi |
| 118 | + ) |
| 119 | + ) |
| 120 | + foundUnityExport = false |
| 121 | + for i=1 to exportMenu.numItems() while not foundUnityExport do( |
| 122 | + mi = exportMenu.getItem i |
| 123 | + if mi.getTitle() == unityExportTitle then( |
| 124 | + foundUnityExport = true |
| 125 | + global unityExportAction = mi |
| 126 | + ) |
| 127 | + ) |
| 128 | + |
| 129 | + if foundUnityImport == false or foundUnityExport == false then( |
| 130 | + id = genClassID returnValue:true |
| 131 | + if menuMan.registerMenuContext id[1] then |
| 132 | + ( |
| 133 | + if foundUnityImport == false do ( |
| 134 | + global unityImportAction = menuMan.createActionItem "UnityImport" "Unity"; --create an ActionItem from the MacroScript |
| 135 | + unityImportAction.setTitle unityImportTitle; |
| 136 | + unityImportAction.setUseCustomTitle true; |
| 137 | + importMenu.addItem unityImportAction -1; --add the ActionItem to the menu |
| 138 | + ) |
| 139 | + if foundUnityExport == false do ( |
| 140 | + global unityExportAction = menuMan.createActionItem "UnityExport" "Unity"; |
| 141 | + unityExportAction.setTitle unityExportTitle; |
| 142 | + unityExportAction.setUseCustomTitle true; |
| 143 | + exportMenu.addItem unityExportAction -1; |
| 144 | + ) |
| 145 | + menuMan.updateMenuBar() --update the menu bar |
| 146 | + ) |
105 | 147 | )
|
106 | 148 | )
|
107 |
| - ) |
108 |
| - foundMenuItem |
109 |
| -) |
110 |
| - |
111 |
| --- get the import menu |
112 |
| -fn getImportMenu = ( |
113 |
| - getFileSubMenuItem importMenuName |
114 |
| -) |
| 149 | + ); |
| 150 | + setupUnityPluginUI() |
115 | 151 |
|
116 |
| --- get the export menu |
117 |
| -fn getExportMenu = ( |
118 |
| - getFileSubMenuItem exportMenuName |
119 |
| -) |
120 |
| - |
121 |
| --- Setup UI |
122 |
| -fn setupUnityPluginUI = ( |
123 |
| - importMenu = getImportMenu() |
124 |
| - exportMenu = getExportMenu() |
125 |
| - if importMenu != undefined and exportMenu != undefined do |
126 |
| - ( |
127 |
| - unityImportTitle = "Import from Unity" |
128 |
| - unityExportTitle = "Export to Unity" |
129 |
| - |
130 |
| - -- check if menu items already exists |
131 |
| - foundUnityImport = false |
132 |
| - for i=1 to importMenu.numItems() while not foundUnityImport do( |
133 |
| - mi = importMenu.getItem i |
134 |
| - if mi.getTitle() == unityImportTitle then( |
135 |
| - foundUnityImport = true |
136 |
| - global unityImportAction = mi |
137 |
| - ) |
138 |
| - ) |
139 |
| - foundUnityExport = false |
140 |
| - for i=1 to exportMenu.numItems() while not foundUnityExport do( |
141 |
| - mi = exportMenu.getItem i |
142 |
| - if mi.getTitle() == unityExportTitle then( |
143 |
| - foundUnityExport = true |
144 |
| - global unityExportAction = mi |
145 |
| - ) |
146 |
| - ) |
147 |
| - |
148 |
| - if foundUnityImport == false or foundUnityExport == false then( |
149 |
| - id = genClassID returnValue:true |
150 |
| - if menuMan.registerMenuContext id[1] then |
151 |
| - ( |
152 |
| - if foundUnityImport == false do ( |
153 |
| - global unityImportAction = menuMan.createActionItem "UnityImport" importMenuName; --create an ActionItem from the MacroScript |
154 |
| - unityImportAction.setTitle unityImportTitle; |
155 |
| - unityImportAction.setUseCustomTitle true; |
156 |
| - importMenu.addItem unityImportAction -1; --add the ActionItem to the menu |
157 |
| - ) |
158 |
| - if foundUnityExport == false do ( |
159 |
| - global unityExportAction = menuMan.createActionItem "UnityExport" exportMenuName; |
160 |
| - unityExportAction.setTitle unityExportTitle; |
161 |
| - unityExportAction.setUseCustomTitle true; |
162 |
| - exportMenu.addItem unityExportAction -1; |
163 |
| - ) |
164 |
| - menuMan.updateMenuBar() --update the menu bar |
165 |
| - ) |
166 |
| - ) |
167 |
| - ) |
168 |
| -); |
169 |
| -setupUnityPluginUI() |
170 |
| - |
171 |
| --- Make sure that Menu gets removed at shutdown, force menu to reload each time Max is opened |
172 |
| -callbacks.addScript #preSavingMenus ( |
173 |
| - "importMenu = getImportMenu(); \ |
174 |
| - exportMenu = getExportMenu(); \ |
175 |
| - if importMenu != undefined and unityImportAction != undefined then( \ |
176 |
| - importMenu.removeItem unityImportAction; \ |
177 |
| - ) \ |
178 |
| - if exportMenu != undefined and unityExportAction != undefined then( \ |
179 |
| - exportMenu.removeItem unityExportAction; \ |
180 |
| - )" |
| 152 | + -- Make sure that Menu gets removed at shutdown, force menu to reload each time Max is opened |
| 153 | + callbacks.addScript #preSavingMenus ( |
| 154 | + "importMenu = getImportMenu(); \ |
| 155 | + exportMenu = getExportMenu(); \ |
| 156 | + if importMenu != undefined and unityImportAction != undefined then( \ |
| 157 | + importMenu.removeItem unityImportAction; \ |
| 158 | + ) \ |
| 159 | + if exportMenu != undefined and unityExportAction != undefined then( \ |
| 160 | + exportMenu.removeItem unityExportAction; \ |
| 161 | + )" |
| 162 | + ) |
181 | 163 | )
|
0 commit comments