Update all Model States at Once

Update all Model States at Once

KaynePellegrino
Enthusiast Enthusiast
161 Views
5 Replies
Message 1 of 6

Update all Model States at Once

KaynePellegrino
Enthusiast
Enthusiast

I'm making a part that has hundreds of model states. I edit it via spreadsheet to make tens and hundreds of model states at once, save the spreadsheet and close it out, let the inventor part load the new model states, but then it shows I need to manually activate and local update every single model state. That's going to take forever. 

 

I've presented this issue before and was given these codes. They are no longer working (not sure if it's cause of a basic update or if it's cause I'm on 2026 instead of 2025

 

Code 1:

Dim oDoc As Inventor.Document = ThisDoc.FactoryDocument
If oDoc Is Nothing Then Return
Dim oMSs As ModelStates = oDoc.ComponentDefinition.ModelStates
If oMSs Is Nothing OrElse oMSs.Count = 0 Then Return
Dim oAMS As ModelState = oMSs.ActiveModelState
For Each oMS As ModelState In oMSs
	oMS.Activate
	Dim oMSDoc As Inventor.Document = TryCast(oMS.Document, Inventor.Document)
	If oMSDoc Is Nothing Then Continue For
	oMSDoc.Update2(True)
Next oMS
If oMSs.ActiveModelState IsNot oAMS Then oAMS.Activate

 

 Code 2:

Dim oDoc As Inventor.Document = ThisApplication.ActiveDocument
If oDoc Is Nothing Then Return
If (Not TypeOf oDoc Is AssemblyDocument) AndAlso (Not TypeOf oDoc Is PartDocument) Then Return
If oDoc.ComponentDefinition.IsModelStateMember Then
	oDoc = oDoc.ComponentDefinition.FactoryDocument
End If
Dim oMSs As ModelStates = oDoc.ComponentDefinition.ModelStates
If (oMSs Is Nothing) OrElse (oMSs.Count < 2) Then Return
Dim oAMS As ModelState = oMSs.ActiveModelState
For Each oMS As ModelState In oMSs
	oMS.Activate()
	Dim oFDoc As Inventor.Document = ThisApplication.ActiveDocument
	oFDoc.Update2(True)
Next oMS
If oMSs.ActiveModelState IsNot oAMS Then oAMS.Activate()

 

I've tried running those rules, rebuilding all, and updating  mass. All with scope as single member, scope as all members. I don't know if 'Global Update' would work, but it's greyed out so I can't even try it.

 

I need help finding either a command that will update all model states or if there's some sort of rule I can write and run to go through and update each model state.

0 Likes
162 Views
5 Replies
Replies (5)
Message 3 of 6

hollypapp65
Advocate
Advocate

What didn't work?  Error message?

 

Try this:

Dim oDoc As Inventor.Document = ThisDoc.FactoryDocument
If oDoc Is Nothing Then Return
Dim oMSs As ModelStates = oDoc.ComponentDefinition.ModelStates
If oMSs Is Nothing OrElse oMSs.Count = 0 Then Return
Dim oAMS As ModelState = oMSs.ActiveModelState
For Each oMS As ModelState In oMSs
	oMS.Activate
	Logger.Info(oMS.Name)
	'Dim oMSDoc As Inventor.Document = TryCast(oMS.Document, Inventor.Document)
	'If oMSDoc Is Nothing Then Continue For
	Logger.Info("Update")
	oDoc.Update2(True)
Next oMS
If oMSs.ActiveModelState IsNot oAMS Then oAMS.Activate

 

0 Likes
Message 4 of 6

KaynePellegrino
Enthusiast
Enthusiast

Screen.jpg

When I run the code (from my original post) it cycles through the model states, but when I activate different model states after, it still shows that I need to do a 'Local Update' on each one manually

 

I ran the code you sent too and it shows the same. With scope as single member and all members

0 Likes
Message 5 of 6

WCrihfield
Mentor
Mentor

Do you have some code set-up to run automatically when specific events happen...such as iLogic rules or add-ins.  The iLogic rules could be triggered by settings in the iLogic Event Triggers dialog, or because of any 'internal' iLogic rules containing the blue, unquoted parameter names, which causes them to run when those parameter values change (by default).  If so, could the event of you activating a different ModelState be triggering any of those codes to run.  Or maybe when you activate a different ModelState, it is like changing Parameter values, so some code may be triggered by the changed parameter values, or something similar.  If so, then something the code may be doing may be causing the document to think that an update may be necessary.  Just trying to think about environmental effects, because it looks like you have a lot of stuff going on in that screen captured image.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 6 of 6

KaynePellegrino
Enthusiast
Enthusiast

I actually just added one earlier. To have an event trigger where it updates the document when I activate a model state.

 

But the idea is the part can be different lengths, widths, have holes, no holes, be beige pvc or wood, etc. So I need it to activate each model state, run the rules and update, then move to the next model state. Because yes, the parameters have different values/options.

I will 'Edit via Spreadsheet' for the model states. Copy inventor sheet and paste it into a google doc. Copy and paste new rows. Change the model state names and change parameters to match each model state. Then copy the google sheet and paste it back into the inventor sheet. Save, close, and let inventor load in the new model states.

The issue comes when I activate any newly added model states. They need updated. The other issue, there's hundreds of model states and it takes like 5-10 seconds to load each model state when I manually activate it.

 

Having the 'Activate a Model State' Event Trigger run a 'update document' rule when I activate a model state saves me like 1/2 a second since I don't have manually click 'local update' anymore. But I still need to manually activate each model state so they can update. 

 

So I need a rule that will activate a model state, run the rules and update the document, then save the document and activate the next model state.

 

And yes, there is a lot going on and I'm probably making rules and parameters that are making thigs way over complicated 😂

0 Likes