Skip to content

Commit e418961

Browse files
committed
created max script to add Unity menu in Max
- also started adding code to install the max integration from Unity
1 parent 71bfa4f commit e418961

File tree

3 files changed

+152
-0
lines changed

3 files changed

+152
-0
lines changed

Assets/FbxExporters/Editor/FbxExportSettings.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,10 @@ public override void OnInspectorGUI() {
161161
FbxExporters.Editor.IntegrationsUI.InstallMayaIntegration ();
162162
}
163163

164+
if (GUILayout.Button ("Install Max Integration")) {
165+
FbxExporters.Editor.MaxIntegration.InstallMaxPlugin ();
166+
}
167+
164168
GUILayout.FlexibleSpace ();
165169
GUILayout.EndScrollView ();
166170

Assets/FbxExporters/Editor/InstallIntegration.cs

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -389,4 +389,99 @@ public static void InstallMayaIntegration ()
389389
UnityEditor.EditorUtility.DisplayDialog (title, message, "Ok");
390390
}
391391
}
392+
393+
class MaxIntegration
394+
{
395+
// get version of Max
396+
// find 3dsmax.ini file (in the AppData)
397+
// get startup path from .ini file
398+
// copy .ms file to startup path
399+
400+
//private const string MaxIni = "3dsmax.ini";
401+
private const string PluginName = "unityOneClickPlugin.ms";
402+
private const string PluginPath = "Integrations/Autodesk/max/scripts/" + PluginName;
403+
//private const string InstallMaxScript = "Integrations/Autodesk/max/scripts/unityPluginInstall.ms";
404+
405+
private const string InstallMaxScriptTemplate =
406+
@"startupScriptPath = pathConfig.GetDir(#userStartupScripts);" +
407+
@"copyFile \""{UnityPluginScript_Source}\"" (startupScriptPath + \""/{UnityPluginScript_Name}\"")";
408+
409+
private const string PluginSourceTag = "{UnityPluginScript_Source}";
410+
private const string PluginNameTag = "{UnityPluginScript_Name}";
411+
412+
// TODO: get this from the export settings
413+
private static string GetMaxExe(){
414+
return "C:/Program Files/Autodesk/3ds Max 2017/3dsmax.exe";
415+
}
416+
417+
private static string GetInstallScript(){
418+
Dictionary<string,string> Tokens = new Dictionary<string,string>()
419+
{
420+
{PluginSourceTag, Application.dataPath + "/" + PluginPath },
421+
{PluginNameTag, PluginName }
422+
};
423+
424+
var installScript = InstallMaxScriptTemplate;
425+
foreach (var t in Tokens) {
426+
installScript = installScript.Replace (t.Key, t.Value);
427+
}
428+
return installScript;
429+
}
430+
431+
public static int InstallMaxPlugin(){
432+
var maxExe = GetMaxExe ();
433+
var installScript = GetInstallScript ();
434+
435+
int ExitCode = 0;
436+
437+
try {
438+
if (!System.IO.File.Exists(maxExe))
439+
{
440+
Debug.LogError (string.Format ("No 3DsMax installation found at {0}", maxExe));
441+
return -1;
442+
}
443+
444+
System.Diagnostics.Process myProcess = new System.Diagnostics.Process();
445+
myProcess.StartInfo.FileName = maxExe;
446+
myProcess.StartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
447+
myProcess.StartInfo.CreateNoWindow = true;
448+
myProcess.StartInfo.UseShellExecute = false;
449+
450+
#if UNITY_EDITOR_OSX
451+
throw new NotImplementedException();
452+
#elif UNITY_EDITOR_LINUX
453+
throw new NotImplementedException();
454+
#else // UNITY_EDITOR_WINDOWS
455+
myProcess.StartInfo.Arguments = string.Format("-q -silent -mxs \"{0}\"", installScript);
456+
#endif
457+
myProcess.EnableRaisingEvents = true;
458+
459+
Debug.Log("args: " + myProcess.StartInfo.Arguments);
460+
461+
myProcess.Start();
462+
myProcess.WaitForExit();
463+
ExitCode = myProcess.ExitCode;
464+
Debug.Log(string.Format("Ran max: [{0}]\nWith args [{1}]\nResult {2}",
465+
maxExe, myProcess.StartInfo.Arguments, ExitCode));
466+
}
467+
catch (Exception e)
468+
{
469+
UnityEngine.Debug.LogError(string.Format ("Exception failed to start Max ({0})", e.Message));
470+
ExitCode = -1;
471+
}
472+
return ExitCode;
473+
}
474+
475+
/*private string AppDataPath{
476+
get{
477+
return Environment.GetFolderPath (Environment.SpecialFolder.LocalApplicationData);
478+
}
479+
}
480+
481+
//C:/Users/Viktoria/AppData/Local/Autodesk/3dsMax/2017 - 64bit/ENU
482+
private string GetMaxIniPath(){
483+
var appData = AppDataPath;
484+
return null;
485+
}*/
486+
}
392487
}
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
-- MacroScripts that will perform actions
2+
macroScript Import category:"Unity"
3+
(
4+
print "I do nothing, but I should Import!"
5+
)
6+
macroScript Preview category:"Unity"
7+
(
8+
print "I do nothing, but I should Preview!"
9+
)
10+
macroScript Export category:"Unity"
11+
(
12+
print "I do nothing, but I should Export!"
13+
)
14+
15+
-- Setup UI
16+
unityMenuName = "Unity"
17+
unityMenu = menuMan.findMenu unityMenuName
18+
if unityMenu == undefined do
19+
(
20+
id = genClassID returnValue:true
21+
if menuMan.registerMenuContext id[1] then
22+
(
23+
mainMenu = menuMan.getMainMenuBar() --get the main menu bar
24+
newUnityMenu = menuMan.createMenu unityMenuName
25+
newUnitySubMenu = menuMan.createSubMenuItem unityMenuName newUnityMenu --create a SubMenuItem
26+
mainMenu.addItem newUnitySubMenu -1 --add the SubMenu to the end of the Main Menu
27+
28+
importAction = menuMan.createActionItem "Import" unityMenuName --create an ActionItem from the MacroScript
29+
importAction.setTitle "Import"
30+
importAction.setUseCustomTitle true
31+
32+
previewAction = menuMan.createActionItem "Preview" unityMenuName
33+
previewAction.setTitle "Preview"
34+
previewAction.setUseCustomTitle true
35+
36+
exportAction = menuMan.createActionItem "Export" unityMenuName
37+
exportAction.setTitle "Export"
38+
exportAction.setUseCustomTitle true
39+
40+
newUnityMenu.addItem importAction -1 --add the ActionItem to the menu
41+
newUnityMenu.addItem previewAction -1
42+
newUnityMenu.addItem exportAction -1
43+
menuMan.updateMenuBar() --update the menu bar
44+
45+
print "heeyyyy"
46+
)
47+
)
48+
--#preSystemShutdown
49+
-- Make sure that Menu gets removed at shutdown, force menu to reload each time Max is opened
50+
callbacks.addScript #preSavingMenus ("menu = menuMan.findMenu \"Unity\" if menu != undefined then menuMan.unregisterMenu menu")
51+
52+
--python.ExecuteFile "C:/Program Files/Autodesk/3ds Max 2017/scripts/Python/demoMenu.py"
53+
--pathConfig.GetDir(#userStartupScripts) --where the startup scripts go

0 commit comments

Comments
 (0)