State Sets MAXScript Access

The State Sets render pass management system was first introduced in the Subscription Advantage Pack extension to 3ds Max 2012 and is now integral part of 3ds Max 2013 and higher. In 3ds Max 2018 and higher, the compositing editor is a node-based system.

This feature is exposed to MAXScript via a DotNet object and its properties and methods.

The following example shows the basic steps involved in accessing and manipulating State Sets.

Getting Access To State Sets

``` stateSetsDotNetObject = dotNetObject "Autodesk.Max.StateSets.Plugin" --Get StateSets dotNet object. stateSets = stateSetsDotNetObject.Instance --Get the state sets instance from the dotNet object.

```

Opening and closing State Sets window

``` stateSets.ShowMainFrame() --Open the State Sets window. stateSets.HideMainFrame() --Close the State Sets window.

```

Getting access to the Master state

masterState = stateSets.EntityManager.RootEntity.MasterStateSet

Adding and renaming a new state set

``` stateSet = masterState.AddState() stateSet.Name = "MyStateSet" masterState.AssignUniqueName stateSet "MyMasterStateset" --Assigns a unique name to the state set

```

Changing current state set, starting, and ending recording

``` previousCurrentStateSet = masterState.CurrentState.Items[0] --Record current state set. masterState.CurrentState = #(stateSet) --Assign current state set. stateSet.BeginRecording() --Begin recording state set.
stateSet.EndRecording() --End recording state set. masterState.CurrentState = #(previousCurrentStateSet) --Assign previous state set.

```

Adding and rendering a child sub-state set, and doing other operations

``` subStateSet = stateSet.AddState() subStateSet = stateSet.Render #(stateSet) --Render state set, note that we specify a path because this state set could be located under multiple parents.

scriptedState = stateSet.AddScriptedState(false) --Add a scripted state. scriptedState.ApplyScript = "-- MaxScript executed when applying state set" --Assign the apply script. scriptedState.RevertScript = "-- MaxScript executed when reverting state set" --Assign the revert script. stateSet.CreateTemplate() --Create a template for this state set

```

Deleting state set and first child

``` masterState.RemoveChild stateSet --Removes the state set masterState.RemoveChild masterState.Children.Item[0] --Removes the first child

```

Adding a compositor view

``` masterState.CreateCompositingView true --Add compositor view with render elements masterState.CreateCompositingView false --Add compositor view without render elements

```

Getting the nodes in the active compositor view

``` cViewNodes = stateSets.CompositingViewNodes

for i in 0 to (cViewNodes.Count - 1 ) do ( node = cViewNodes.Item(i) node.Collapsed = true print node.Tag.Name )

```

Rendering all state sets in the scene

masterState.RenderAllStates()

Getting access to objects state set

objectStateSet = masterState.ObjectStateSet

All properties and methods of all DotNet objects and classes implemented by the State Sets system are accessible to MAXScript using the DotNet inspector functions.

Exploring State Set Plugin Instance

``` stateSetsDotNetObject = dotNetObject "Autodesk.Max.StateSets.Plugin" dotNetObject:Autodesk.Max.StateSets.Plugin

stateSets = stateSetsDotNetObject.Instance dotNetObject:Autodesk.Max.StateSets.Plugin

showProperties stateSets .AbsentLayerStatesWereRemovedOnLoad : .ActiveViewId : .BitmapInfos : , read-only .ClassDescManager : , read-only .CompositingView : , read-only .CompositingViewNodes : , read-only .CompositorLink : , read-only .CompositorLinkTargetViewId : .Configuration : .EntityManager : , read-only .Global : .GlobalStringFormat : , read-only .HasRenderPreviewNode : , read-only .Instance : , static .InvokeRequired : , read-only .IsInSequencerMode : .IsMainFrameInitialized : , read-only .IsMainFrameVisible : .LoadedVersion : .MainFrameBounds : .NodeEvents : , read-only .OpenViewCount : , read-only .PluginWasRegistered : .PreviewRenderNode : , read-only .SequencerTreeView : , read-only .Skin : , read-only .Sync : .ToolbarTreeView : , read-only .TreeView : , read-only .TreeViews : , read-only .accumCallbacks : true

showMethods stateSets .AccumCallbackCount type .AccumCallbackIncrement type .AccumCallbackIncrement type n .AccumCallbackReset type -- Added in 3ds Max 2018: .AddTreeView() .BeginInvoke method args .Cleanup() .CreateInstance() .CreateObjRef requestedType .EndInvoke result .Equals obj .[static]Equals objA objB .GetHashCode() .GetLifetimeService() .GetType() .GetUniqueBitmapInfoId() .HideMainFrame() .Initialize global sync .InitializeLifetimeService() .Invoke method args .LaunchBlank args .[static]Log logType message .[static]Log message newLine .LogLocal logType message .PreviewRenderNodeReset() .[static]ReferenceEquals objA objB .RegisterAnchorCallbacks() .ReloadConfiguration() .ResetAndDelete() .ResetConfiguration() .ResetNodeEventCallbackMessages() .ShowMainFrame() .ShowSetupRenderOutputsPanel() .ToggleMainFrame() .ToString() .TriggerNodeEventCallbackMessages() .UnRegisterAnchorCallbacks()true true

showEvents stateSets CameraSequencerModeChanged obj = ( ... ) CurrentLayerChanged obj = ( ... ) CurrentStateSetChanged obj = ( ... ) ScenePostSave = ( ... ) StateApplied arg1 arg2 = ( ... ) StateRecording arg1 arg2 = ( ... ) StateSetAdded obj = ( ... ) StateSetChanged obj = ( ... ) StateSetRemoved obj = ( ... ) StateSetRenamed obj = ( ... ) TimeChange obj = ( ... ) TimeRangeChanged = ( ... ) true

```

Exploring MasterStateSet

``` showProperties stateSets.EntityManager .RootEntity : true

showProperties stateSets.EntityManager.RootEntity .AutomaticName : .AutomaticTypeName : .Children : .CustomAttributes : , read-only .CustomChildren : .Description : .DynamicInsertTarget : .HierarchyIndex : , read-only .InternalName : , read-only .MasterStateSet : , read-only .Name : .Parents : , read-only .TypeName : .UseNameForTypeName : , read-only .CustomChildrenToken : , read-only, static true

showProperties stateSets.EntityManager.RootEntity.MasterStateSet .AutomaticName : , read-only .AutomaticTypeName : .Children : .CompositorLinkFilePath : .CurrentState : .CustomAttributes : , read-only .CustomChildren : .DefaultRenderOutputFilePattern : , read-only, static .DescendantStateCount : , read-only .Description : , read-only .DynamicInsertTarget : .HierarchyIndex : , read-only .InternalName : , read-only .Name : .ObjectStateSet : , read-only .Parents : , read-only .RenderOutputFilePattern : .StatesWithErrors : , read-only .TypeName : .UseNameForTypeName : , read-only .CustomChildrenToken : , read-only, static .StateNameToken : , read-only, static true

showMethods stateSets.EntityManager.RootEntity.MasterStateSet .AddChild entity wasAutoGenerated .AddChild entity wasAutoGenerated broadcastEvent .AddObjectState() .AddObjectState targetViewId .AddState() .AddState targetViewId addToCompositorView .AssignUniqueName state baseName .BeginRecordingStateSet stateSet path .CheckForStateErrors() .CollectDescendantStateSets destination .CollectDescendantsWithCustomAttribute customAttribute destination .CreateCompositingView includeRenderElements .CreateObjRef requestedType .CreateUserCreatableParameter name .DefaultSetup() .Dispose() .Equals obj .[static]Equals objA objB .GenerateChildrenForTarget target .GetChild name .GetCustomAttribute key defaultValue .GetCustomAttributeBoolean key .GetDescendant name .GetDescendant hierarchyIndex .GetDescendants() .GetDescendantStateSetIndex stateSetPath .GetDescendantStateSetPaths includeObjectStateSet .GetHashCode() .GetHierarchyIndex descendant .GetLifetimeService() .GetObjectData info context .GetStateById id .GetType() .GetUserCreatableParameterNames() .HasCustomAttribute key .HasDescendant descendant ignoreParents .HasDescendant descendant ignoreParents .InitializeLifetimeService() .InsertChild index entity .InsertChild index entity wasAutoGenerated broadcastEvent .InvalidateChildren() .IsDescendantOf ancestor .[static]maxnrAssignStateSetJob stateSetsHandles numHandles .OnCreateChildForIndex index target .[static]ReferenceEquals objA objB .Refresh() .RemoveChild entity .RemoveChild entity entityChange .RemoveChild entity entityChange broadcastEvent .RemoveCustomAttribute key .Rename newName .RenderAllStates forceNetworkRender .RenderStates stateSetPaths useNetworkRender .Reset() .ResetCompositingView includeRenderElements .SetCurrentStateSet path .SetCustomAttribute key value .SetCustomAttributeBoolean key value .SetupRenderOutputsPath value .ToString() .UpdateHierarchyParents() true

```