Notifications
Clear all

[Closed] Exit Application and New Scene Via Python

Hello, I am trying to find a way in python to create a new scene in 3ds max, the command exists in both motion builder and maya so I am sure there is a way in max as well.

The MaxPlus.FileManager seems to have almost all the options I would expect except it is missing a new scene for some reason.

Any ideas? Thanks.

[Edit] Found how to quit, still need new scene however.

        if save:
            MaxPlus.Core.EvalMAXScript("quitmax")
        else:
            MaxPlus.Core.EvalMAXScript("quitmax #noprompt")
8 Replies

From the python help here:

When sys.exit() is used to exit Python, it raises a SystemExit exception. If an uncaught exception is raised in Python, it is reported to the MAXScript Listener window as an error, even though no error actually occurred. To avoid having an error being reported in the MAXScript Listener window by sys.exit(), you can use the try and except statements as follows:

try: import sys print 'goodbye world' sys.exit()
# Safe way to leave program at any point and allow objects and resources to be cleaned up.
# Prevent 3ds Max from reporting a system exit as an error in the listener.
except SystemExit: pass

What about using reset() for new scene?
Or use the Action Item. From the ApplicationMenu.xaml

  <ApplicationMenuItem Text="New" IsSplit="true" Id="New"
  	KeyTip="N" SplitKeyTip="W"
  	LargeImage="../../UI_ln/Icons/ApplicationMenu/new_32.ico"
  	Description="Clears the content of the current scene and keeps the current session settings and UI"
  	CommandHandler="{wpfmax:ActionItem TableId=0, ActionId=16}"
  	IsToolTipEnabled="false">

  	<ApplicationMenuItem Text="New All" Id="NewAll"
  		KeyTip="N"
  		LargeImage="../../UI_ln/Icons/ApplicationMenu/new_32.ico"
  		Description="Refresh 3ds Max with a new scene and keeps the session settings."
  		CommandHandler="{wpfmax:ActionItem TableId=0, ActionId=16}"
  		IsToolTipEnabled="false"/>

  	<ApplicationMenuItem Text="Keep Objects" Id="NewKeepObjects"
  		KeyTip="O"
  		LargeImage="../../UI_ln/Icons/ApplicationMenu/keepObjects_32.ico"
  		Description="Refresh 3ds Max with a new scene and keeps the session settings and objects."
  		CommandHandler="{wpfmax:ActionItem TableId=0, ActionId=17}"
  		IsToolTipEnabled="false"/>

  	<ApplicationMenuItem Text="Keep Objects and Hierarchy" Id="NewKeepObjectHierarchy"
  		KeyTip="H"
  		LargeImage="../../UI_ln/Icons/ApplicationMenu/keepObjectsAndHierarchy_32.ico"
  		Description="Refresh 3ds Max with a new scene and keeps the session settings, objects and hierarchies."
  		CommandHandler="{wpfmax:ActionItem TableId=0, ActionId=18}"
  		IsToolTipEnabled="false"/>
  
  <ApplicationMenuItem Text="New from Template" Id="NewFromTemplate"
  		KeyTip="T"
  		LargeImage="../../UI_ln/Icons/ApplicationMenu/newFromTemplate_32.ico"
  		Description="Refresh 3ds Max with a new scene using the configuration from a template."
  		CommandHandler="{wpfmax:ActionItem TableId=0, ActionId=19}"
  		IsToolTipEnabled="false"/>

-Eric

I thought about reset, but that also resets all the current settings that were loaded with the scene etc. I would like to keep it as clean as possible.

I tried your application menu example but I cant seem to figure out how to call it?

        NEW_ACTION_ID = 16 # From ApplicationMenu.xaml
        menu = MaxPlus.MenuManager.GetMainMenu()
        for i in range(menu.GetNumItems()):
            print menu.GetItem(i).GetTitle()
            actionItem = menu.GetItem(i).GetActionItem()
            if actionItem.GetId() == "New":
                actionItem.Execute()
                break

Is my attempt, however the GetMainMenu seems to start on the edit menu and go down the list. It cant seem to get into the main maxscript menu. Do you know how abouts I would get that action item?

Thanks

Try ActionManager.FindTable and ActionTable.GetAction. Sorry don’t know enough about python to help beyond that, but that may get you where you need to go.

From the XAML:
CommandHandler=”{wpfmax:ActionItem TableId=0, ActionId=16}”

-Eric

Thanks

This works:

        # From C:\Program Files\Autodesk\3ds Max 2015\en-US\UI\ApplicationMenu.xaml
        ACTION_TABLE_ID = 0
        NEW_ACTION_ID = "16"

        MaxPlus.Core.EvalMAXScript('actionMan.executeAction ' + str(ACTION_TABLE_ID) + ' "' + str(NEW_ACTION_ID) + '"')

though it asks if you want to save or not which is a shame. Reset does as well. Ah well looks like this is my only option. Thanks for all the help.

2 Replies
(@pixel_monkey)
Joined: 1 year ago

Posts: 0

Use FileManager.IsSaveRequired and FileManager.SetSaveRequiredFlag to change that flag to false before reset or new scene call and it should work like you want.

-Eric

(@marsh0)
Joined: 1 year ago

Posts: 0

Perfect! Thank you so much.

NewScene is the same as “delete all scene nodes”

1 Reply
(@marsh0)
Joined: 1 year ago

Posts: 0

That could work for some people yes.

It is not the same with some notable differences however. Mainly that you can register a callback to be received when a new scene is created. I need this callback to be triggered.