State Sets C#

 
 
 
Posted by:henriquemelo
Data created:29 October 2012

 

Hello,
Can anyone help me with a little issue?
I'm trying to access the .CurrentState property from Autodesk.Max.StateSets.dll using C# but I can't find a solution for this problem.
In MaxScript I can use:
masterState.CurrentState = #(masterState.Children.Item[x])
In C# how can I use the .CurrentState to Ative my State Set? My code is:
var StateSetsObjs = Autodesk.Max.StateSets.Plugin.Instance;
var masterState = StateSetsObjs.EntityManager.RootEntity.MasterStateSet;
for (int i...)
{
 masterState.CurrentState = masterState.Children... ???
}
What I need to use to make my State Set ative by ID?
Thanks

Hello,

You need to pass an array of State Sets to current state, you can just pass in one item in the array but it does need to be an array. Please look at this example:

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

Marsel Khadiyev (Software Developer, EPHERE Inc.)

Hi Marsel,

Yes, it's works using maxscript. But I'm using c# inside visual Studio.

My code in c# to list all state sets is this:

 

 

var StateSetObjs = Autodesk.Max.StateSets.Plugin.Instance;
            var masterState = StateSetObjs.EntityManager.RootEntity.MasterStateSet;
            
            lv_StateSets.BeginUpdate();
            lv_StateSets.Items.Clear();
            for (int i = 1; i <= masterState.Children.Count; i++)
            {
                if (masterState.Children[(i - 1)].Name != "Objects")
                    lv_StateSets.Items.Add((masterState.Children[(i-1)].Name).ToString());
            }
            lv_StateSets.EndUpdate();
            lv_StateSets.Refresh();

and my code to activate each state sets is:

 

 

var StateSetsObjs = Autodesk.Max.StateSets.Plugin.Instance;

var masterState = StateSetsObjs.EntityManager.RootEntity.MasterStateSet;

 

StateSetsObjs.ShowMainFrame(); // Show State Sets Window

for (int i = 0; i < lv_StateSets.Items.Count; i++)

{

if (lv_StateSets.Items[i].Checked)

   {

MessageBox.Show("Rendering State Set... \n\nID: " + i + "\nName: " + (lv_StateSets.Items[i].Text).ToString(), "Local Render");

   }

}

masterState.Refresh(); // Refresh List

StateSetsObjs.HideMainFrame(); // Hide StateSets Window

 

 

What I would like is change the "MessageBox.Show" to a line code for activate each state set that is checked on my listview

 

Thanks

 

when I use this code:

masterState.CurrentState = masterState.Children[1];

visual studio return this error:

Error 1 Cannot implicitly convert type 'Autodesk.Max.StateSets.Entities.Entity' to 'Autodesk.Max.StateSets.Entities.StateSets.StateSet[]'

what I need to do?

 

 

try:

masterState.CurrentState = new StateSet[] { masterState.Children[1] as StateSet };

Marsel Khadiyev (Software Developer, EPHERE Inc.)

Marcel,

You - are - my - hero.

Thanks a lot!

one more question, the last one.

There's a way to make a callback function? I mean, when the user add/delete/rename a state set, my listview update automatically?