Component.ActiveModelState: Failed to set model state ... in component ... - Cannot get this to work

Component.ActiveModelState: Failed to set model state ... in component ... - Cannot get this to work

ryan.grantE6CPF
Explorer Explorer
727 Views
3 Replies
Message 1 of 4

Component.ActiveModelState: Failed to set model state ... in component ... - Cannot get this to work

ryan.grantE6CPF
Explorer
Explorer

I am receiving this error message when trying to set the model state of an individual part within my  'Block' sub-assembly. There is no issue getting the model state to change with our iLogic rules when the 'Block' assembly is open on it's own, however as soon as I place the 'Block' sub-assembly as an iLogic component within another assembly I receive the following error message when trying to change the model states of the part.

 

ryangrantE6CPF_1-1678805472174.png

ryangrantE6CPF_2-1678805508561.png

 

As the parameter 'SelectSize' changes within the 'Main Assembly', the intent is to have the pin size change along with the block size. However as that parameter is cycled through, the above error occurs. Am I missing something?

 

I have linked all the required files along with this post. 

 

If any additional information is needed please let me know.

0 Likes
Accepted solutions (1)
728 Views
3 Replies
Replies (3)
Message 2 of 4

JelteDeJong
Mentor
Mentor
Accepted solution

Im not sure how to do this with the iLogic functions. But using the Inventor API (in your iLogic rule) it can be done. Add this rule to your main assembly and remove all other rules (also in the sub-assembly).

Dim size As String = SelectSize '  Parameter("SelectSize")
Dim Height, Width, Length As Double
Dim modelStateName As String = String.Empty

Select Case size
    Case "150x150"
        Height = 500
        Width = 150
        Length = 150
        modelStateName = "4 Ton x 5.5"

    Case "350x350"
        Height = 500
        Width = 350
        Length = 350
        modelStateName = "8 Ton x 7.125"

    Case "500x500"
        Height = 500
        Width = 500
        Length = 500
        modelStateName = "20 Ton x 8"

End Select

' Get the main assembly
Dim doc As AssemblyDocument = ThisDoc.Document

' get the sub assembly ComponentDefinition
Dim blockAssemblyOcc As ComponentOccurrence = doc.ComponentDefinition.Occurrences.ItemByName("Block")
Dim blockAssemblyDef As AssemblyComponentDefinition = blockAssemblyOcc.Definition

If (blockAssemblyDef.IsModelStateMember) Then
    blockAssemblyDef = blockAssemblyDef.FactoryDocument.ComponentDefinition
End If


'Change the model state of the pin occurence
Dim pinOcc = blockAssemblyDef.Occurrences.ItemByName("Pin1")
pinOcc.ActiveModelState = modelStateName

'Change the block parameters
Dim blockOcc As ComponentOccurrence = blockAssemblyDef.Occurrences.ItemByName("Block")
Dim blockDef As PartComponentDefinition = blockOcc.Definition

If (blockDef.IsModelStateMember) Then
    blockDef = blockAssemblyDef.FactoryDocument.ComponentDefinition
End If

Dim blockParameters = blockDef.Parameters.ModelParameters
blockParameters.Item("Height").Expression = Height
blockParameters.Item("Width").Expression = Width
blockParameters.Item("Length").Expression = Length

doc.Update2()

 

Jelte de Jong
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

EESignature


Blog: hjalte.nl - github.com

0 Likes
Message 3 of 4

ryan.grantE6CPF
Explorer
Explorer

Thanks for your time, this resolved my issue!

0 Likes
Message 4 of 4

matteo_pallaroni
Advocate
Advocate

Hi, I'm having issues using the statement everyone is using everywhere as "good": oCompDef.ActiveModelState = "Name"

1. ActiveModelState is not member of Component definition; how it is possible it works for you?

2. ActiveModelState is a Read-only method...

I'm on Inventor 2024

0 Likes