A question on scripting state set render output

Hi guys, I recently made a script that takes a selected State Set and creates render output (dir, filename etc)for that active State. I was hoping to extend this a bit further by writing a for loop to do this for all existing State Sets and ran aground when trying to activate and record the current state (in Max 2015 Ext2).

The script I've posted marches through and calls out the state names, makes dirs for them but then usually only records the path for the last state onto all outputs. I'm struggling to understand the structure for activate and record State Sets with MXS.

I spent many hours tinkering with what I read in the docs and googling:

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.

I'm assuming the above lines are what I should be using but I can't figure out how to make them work in the context of my script... I usually try something simple with syntax like this but in this case I'm coming up short.

Can anyone give me a nudge in the right direction? Thanks so much in advance!


stateSetsDotNetObject = dotNetObject "Autodesk.Max.StateSets.Plugin"
stateSets = stateSetsDotNetObject.Instance 
masterState.Refresh()--to deselect any currently selected states
masterState = stateSets.EntityManager.RootEntity.MasterStateSet
childCount = masterState.Children.count --to get the # of sets
childCount -= 2 --to nix "objects" state
for i in 0 to childCount do(
masterState.CurrentState = #(masterState.Children.Item[i])
	CurSSName = masterState.Children.Item[i].Name
	print CurSSName
	rendTimeType = 2 
	SSDir = maxfilepath + CurSSName
	MakeDir SSDir
	outputRender = SSDir + ".jpg"
	rendSaveFile = true
	rendOutputFilename  = outputRender


Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
ehance's picture

Ah, with the help of a sharp

Ah, with the help of a sharp guy at work it's solved:


Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.