Skip to content

Commit 6adfe57

Browse files
committed
add Unity menu to main menu bar
-set variables as local/global where appropriate -for max 2018: delete + recreate menu items if they already exist
1 parent fef551a commit 6adfe57

File tree

1 file changed

+29
-24
lines changed

1 file changed

+29
-24
lines changed

Assets/Integrations/Autodesk/max/scripts/UnityFbxForMaxPlugin.ms

Lines changed: 29 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -101,56 +101,55 @@ fn createUnityExportAction title parentMenu = (
101101

102102
-- Setup UI using menu manager if using 3ds Max 2018+
103103
if (maxVersion())[1] >= 20000 then(
104-
importMenuName = "File-Import"
105-
exportMenuName = "File-Export"
104+
global importMenuName = "File-Import"
105+
global exportMenuName = "File-Export"
106106

107107
-- get the import menu
108+
global getImportMenu
108109
fn getImportMenu = (
109110
menuMan.findMenu importMenuName
110111
)
111112

112113
-- get the export menu
114+
global getExportMenu
113115
fn getExportMenu = (
114116
menuMan.findMenu exportMenuName
115117
)
116118

117119
-- Setup UI
118120
fn setupUnityPluginUI = (
119-
importMenu = getImportMenu()
120-
exportMenu = getExportMenu()
121+
local importMenu = getImportMenu()
122+
local exportMenu = getExportMenu()
121123
if importMenu != undefined and exportMenu != undefined do
122124
(
123-
unityImportTitle = "Import from Unity"
124-
unityExportTitle = "Export to Unity"
125+
local unityImportTitle = "Import from Unity"
126+
local unityExportTitle = "Export to Unity"
125127

126-
-- check if menu items already exists
127-
foundUnityImport = false
128+
-- check if menu items already exist, delete if they do
129+
local foundUnityImport = false
128130
for i=1 to importMenu.numItems() while not foundUnityImport do(
129-
mi = importMenu.getItem i
131+
local mi = importMenu.getItem i
130132
if mi.getTitle() == unityImportTitle then(
133+
importMenu.removeItem mi
131134
foundUnityImport = true
132-
global unityImportAction = mi
133135
)
134136
)
135-
foundUnityExport = false
137+
local foundUnityExport = false
136138
for i=1 to exportMenu.numItems() while not foundUnityExport do(
137-
mi = exportMenu.getItem i
139+
local mi = exportMenu.getItem i
138140
if mi.getTitle() == unityExportTitle then(
141+
exportMenu.removeItem mi
139142
foundUnityExport = true
140-
global unityExportAction = mi
141143
)
142144
)
143145

144146
if foundUnityImport == false or foundUnityExport == false then(
145147
id = genClassID returnValue:true
146148
if menuMan.registerMenuContext id[1] then
147149
(
148-
if foundUnityImport == false do (
149-
global unityImportAction = createUnityImportAction unityImportTitle importMenu
150-
)
151-
if foundUnityExport == false do (
152-
global unityExportAction = createUnityExportAction unityExportTitle exportMenu
153-
)
150+
global unityImportAction = createUnityImportAction unityImportTitle importMenu
151+
global unityExportAction = createUnityExportAction unityExportTitle exportMenu
152+
154153
menuMan.updateMenuBar() --update the menu bar
155154
)
156155
)
@@ -173,17 +172,18 @@ if (maxVersion())[1] >= 20000 then(
173172
else(
174173
-- for 3ds Max 2017
175174

176-
unityMenuName = "Unity"
175+
global unityMenuName = "Unity"
177176

177+
global getUnityMenu
178178
fn getUnityMenu = (
179179
menuMan.findMenu unityMenuName
180180
);
181181

182182
-- Setup UI
183183
fn setupUnityPluginUI = (
184-
unityMenu = getUnityMenu()
185-
unityImportTitle = "Import"
186-
unityExportTitle = "Export"
184+
local unityMenu = getUnityMenu()
185+
local unityImportTitle = "Import"
186+
local unityExportTitle = "Export"
187187
if unityMenu != undefined do
188188
(
189189
-- remove the menu if it still exists
@@ -193,6 +193,11 @@ else(
193193
id = genClassID returnValue:true
194194
if menuMan.registerMenuContext id[1] then
195195
(
196+
local mainMenuBar = menuMan.getMainMenuBar()
197+
local unityMenu = menuMan.createMenu unityMenuName
198+
local unityMenuItem = menuMan.createSubMenuItem unityMenuName unityMenu
199+
mainMenuBar.addItem unityMenuItem -1
200+
196201
createUnityImportAction unityImportTitle unityMenu
197202
createUnityExportAction unityExportTitle unityMenu
198203

@@ -204,7 +209,7 @@ else(
204209
-- Make sure that Menu gets removed at shutdown, force menu to reload each time Max is opened
205210
callbacks.addScript #preSavingMenus (
206211
"unityMenu = getUnityMenu(); \
207-
if unityMenu != undefined then( \
212+
if unityMenu != undefined do ( \
208213
menuMan.unRegisterMenu unityMenu; \
209214
)"
210215
)

0 commit comments

Comments
 (0)