Update all Model States at Once

Update all Model States at Once

KaynePellegrino
Enthusiast Enthusiast
108 Views
2 Replies
Message 1 of 3

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
109 Views
2 Replies
Replies (2)
Message 3 of 3

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