I have an assembly which consists of several parts with a selected model state (not master). When the assembly is saved, closed, and re-opened, the Model Tree indicates the correct model state but the parts do not display the correct model state in the assembly. There is no option to update the assembly, but a rebuild all forces the parts to display correctly. The problem then repeats itself when the assembly is saved and re-opened.
Hi! This does look like a bug to me. Somehow the Model State member doc is not properly created and the graphics is not properly updated. I had to open each part, activate each Model State, and save. After that, the Model States are in sync again. Please take a look at attached file.
Many thanks!
updating an individual part manually seems to retain the proper geometry after a save, close, re-open. updating all children via API will break the assembly again. (i didnt verify using API on only a single child.) the macro seems to revert each child differently to some other state. below is the VBA code used to execute the updates if that will help.
the macro was created as a proof of concept. we intend to package the functionality into an add-in. the basic premise is to add or update all model states of the child files based on the three input values. some of the CLR child files may have model states just to activate, others will need them created.
Sub CLR_ModelStates()
'Verify Assembly is active
If ThisApplication.ActiveDocument.DocumentType <> kAssemblyDocumentObject Then
MsgBox ("An assembly must be active")
Else
'Define Variables
Dim Front_Overhang As String
Dim Truck_Centers As String
Dim Rear_Overhang As String
Dim oOccA As ComponentOccurrence
Dim oMSFactoryA As PartDocument
Dim oAsmParam As Inventor.Parameter
Dim Front_Overhang_Param As UserParameter
Dim Truck_Centers_Param As UserParameter
Dim Rear_Overhang_Param As UserParameter
Dim oDocA As AssemblyDocument: Set oDocA = ThisApplication.ActiveDocument
Dim Front_Overhang_Exists As Boolean: Front_Overhang_Exists = False
Dim Truck_Centers_Exists As Boolean: Truck_Centers_Exists = False
Dim Rear_Overhang_Exists As Boolean: Rear_Overhang_Exists = False
'See if CLR parameters exist and if they do set their values in the form
For Each oAsmParam In oDocA.ComponentDefinition.Parameters.UserParameters
If oAsmParam.Name = "Front_Overhang" Then
Front_Overhang_Exists = True
Set Front_Overhang_Param = oAsmParam
FO_Array = Split(oAsmParam.Expression, " ")
CLR_ModelStates_Form.FOTextBox = FO_Array(0)
CLR_ModelStates_Form.UnitComboBox1.Value = FO_Array(1)
End If
If oAsmParam.Name = "Truck_Centers" Then
Truck_Centers_Exists = True
Set Truck_Centers_Param = oAsmParam
TC_Array = Split(oAsmParam.Expression, " ")
CLR_ModelStates_Form.TCTextBox = TC_Array(0)
CLR_ModelStates_Form.UnitComboBox2.Value = TC_Array(1)
End If
If oAsmParam.Name = "Rear_Overhang" Then
Rear_Overhang_Exists = True
Set Rear_Overhang_Param = oAsmParam
RO_Array = Split(oAsmParam.Expression, " ")
CLR_ModelStates_Form.ROTextBox = RO_Array(0)
CLR_ModelStates_Form.UnitComboBox3.Value = RO_Array(1)
End If
Next
'If parameters do not exist create them and set their values in the form
If Front_Overhang_Exists = False Then
Set Front_Overhang_Param = oDocA.ComponentDefinition.Parameters.UserParameters.AddByExpression("Front_Overhang", "0", "in")
CLR_ModelStates_Form.FOTextBox.Value = "0"
CLR_ModelStates_Form.UnitComboBox1.Value = "in"
End If
If Truck_Centers_Exists = False Then
Set Truck_Centers_Param = oDocA.ComponentDefinition.Parameters.UserParameters.AddByExpression("Truck_Centers", "0", "in")
CLR_ModelStates_Form.TCTextBox.Value = "0"
CLR_ModelStates_Form.UnitComboBox2.Value = "in"
End If
If Rear_Overhang_Exists = False Then
Set Rear_Overhang_Param = oDocA.ComponentDefinition.Parameters.UserParameters.AddByExpression("Rear_Overhang", "0", "in")
CLR_ModelStates_Form.ROTextBox.Value = "0"
CLR_ModelStates_Form.UnitComboBox3.Value = "in"
End If
'Show form
CLR_ModelStates_Form.Show
'Exit macro if canceled
If CLR_ModelStates_Form.FormCancelled = True Then
MsgBox ("You stopped the macro")
CLR_ModelStates_Form.FormCancelled = False
Exit Sub
End If
'Get form values and set assembly parameters
Front_Overhang = CLR_ModelStates_Form.FOTextBox + " " + CLR_ModelStates_Form.UnitComboBox1
Front_Overhang_Param.Expression = Front_Overhang
Truck_Centers = CLR_ModelStates_Form.TCTextBox + " " + CLR_ModelStates_Form.UnitComboBox2
Truck_Centers_Param.Expression = Truck_Centers
Rear_Overhang = CLR_ModelStates_Form.ROTextBox + " " + CLR_ModelStates_Form.UnitComboBox3
Rear_Overhang_Param.Expression = Rear_Overhang
'Define new name using values from form
Dim oName As String: oName = Front_Overhang + "-" + Truck_Centers + "-" + Rear_Overhang
'Loop through all occurances and if it is a CLR ipt then create or update modelstates
For Each oOccA In oDocA.ComponentDefinition.Occurrences
If oOccA.DefinitionDocumentType = kPartDocumentObject And Left(oOccA.Name, 3) = "CLR" Then
'Check need to Create new modelstates
If CreateModelstates(oOccA, oName) = False Then
Set oMSFactoryA = oOccA.Definition.FactoryDocument
'Update Parameters for new modelstates
Call ChangeParameters(oMSFactoryA, Front_Overhang, Truck_Centers, Rear_Overhang)
End If
End If
Next
'Rebuild all of the files, save and Great Success!!!
oDocA.Update
oDocA.Save
MsgBox ("Great Success!!!")
End If
End Sub
Function CreateModelstates(oOcc As ComponentOccurrence, oName1 As String) As Boolean
'This function checks to see if the requested modelstate exists and if it does not it creates it
Dim oPDef As PartComponentDefinition: Set oPDef = oOcc.Definition
'See how many model states there are
If oPDef.ModelStates.Count > 1 Then
'Create additional model state
Dim oMSFactory As PartDocument: Set oMSFactory = oOcc.Definition.FactoryDocument
Dim mstate As ModelState
Dim mstateexists As Boolean: mstateexists = False
'Check to see if requested modelstate exists
For Each mstate In oMSFactory.ComponentDefinition.ModelStates
'If the modelstate exists activate the modelstate, exit function, and return True
If mstate.Name = oName1 Then
CreateModelstates = True
oOcc.ActiveModelState = oName1
Exit Function
End If
Next
'If the modelstate does not exist create it and activate it
If mstateexists = False Then
oMSFactory.ComponentDefinition.ModelStates.Add (oName1)
End If
oOcc.Definition.Document.Save
oOcc.ActiveModelState = oName1
Else
'Create first model state
oPDef.ModelStates.Add (oName1)
oOcc.Definition.Document.Save
oOcc.ActiveModelState = oName1
End If
End Function
Sub ChangeParameters(oMSFactoryA1 As PartDocument, Front_Overhang1 As String, Truck_Centers1 As String, Rear_Overhang1 As String)
'This sub changes the parameters of Front_Overhang, Truck_Centers, and Rear_Overhang in the requested part factory
Dim oParam As Inventor.Parameter
For Each oParam In oMSFactoryA1.ComponentDefinition.Parameters.UserParameters
If oParam.Name = "Front_Overhang" Then
oParam.Expression = Front_Overhang1
End If
If oParam.Name = "Truck_Centers" Then
oParam.Expression = Truck_Centers1
End If
If oParam.Name = "Rear_Overhang" Then
oParam.Expression = Rear_Overhang1
End If
Next
End Sub
Hi! This has been reported as INVGEN-64026. Hopefully, it will be fixed soon.
Many thanks!
Hi! We are investigating this problem. The model state member document does not update correctly. Did you use API to edit the member document?
Hi Steven,
Thanks for the reply.
We resolved an issue that part file is not out of date if the member doc is edited by API, Ryan's data shows this problem, so I asked this question how he edited the data.
@EvanGu sorry if there was some confusion. I am the CAD coordinator at Loram working with Ryan to develop automation to update the model states of multiple children in an assembly. the above VBA code was written by Ryan and used to update the model states which produced the error.
Hi Steven,
Thanks for the information. We fixed the member out of date issue in 2023.1, which should work for this case. Looks you created the data in 2022.2, do you have a chance to try 2023.1? or could you tell me the workflow, I'll try it.
@steven_t_gunderson, @ryan.d.amundson do you have a chance to try it in 2023.1, it could be fixed.
@steven_t_gunderson before porting back the fix to 2022, I just want to verify if the fix works for you, if it does work, I'll let the project team to do the same fix in 2022.
Can't find what you're looking for? Ask the community or share your knowledge.