Skip to content

Commit b2f2b7c

Browse files
committed
only use menu manager to setup UI if using max 2018+
-for max 2017, have to add menu item using UI/ApplicationMenu.xaml -change macroscript category to Unity -set icon paths for the macroscripts
1 parent 08f75c8 commit b2f2b7c

File tree

1 file changed

+74
-92
lines changed

1 file changed

+74
-92
lines changed
Lines changed: 74 additions & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
-- MacroScripts that will perform actions
2-
macroScript UnityImport category:"File-Import"
2+
macroScript UnityImport category:"Unity" iconName:"UnityIcons/import"
33
(
44
origObjects = #()
55

@@ -45,7 +45,7 @@ macroScript UnityImport category:"File-Import"
4545
callbacks.removeScripts #postImport id:#unityPlugin
4646
)
4747
)
48-
macroScript UnityExport category:"File-Export"
48+
macroScript UnityExport category:"Unity" iconName:"UnityIcons/export"
4949
(
5050
fn loadUnityFbxExportSettings = (
5151
fbxExportSettings = getINISetting (GetMAXIniFile()) "Unity" "UnityFbxExportSettings"
@@ -84,98 +84,80 @@ macroScript UnityExport category:"File-Export"
8484
)
8585

8686

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+
)
9496

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+
)
105147
)
106148
)
107-
)
108-
foundMenuItem
109-
)
110-
111-
-- get the import menu
112-
fn getImportMenu = (
113-
getFileSubMenuItem importMenuName
114-
)
149+
);
150+
setupUnityPluginUI()
115151

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+
)
181163
)

0 commit comments

Comments
 (0)