Hi there,
I was wondering if anyone knows how to change a Drive Part's Model state using iLogic?
I would like to use iLogic to go into each individual Drive Part in an assembly and change the Model State of each part. Currently, I only know how to do it manually, but I have over 50 parts and it can take lots of time.
Solved! Go to Solution.
Solved by MjDeck. Go to Solution.
I found the following code and I would expect that this would do the trick:
Dim doc As PartDocument = ThisDoc.Document Dim comp As DerivedPartComponent = doc.ComponentDefinition.ReferenceComponents.DerivedPartComponents.Item(1) comp.Definition.ActiveModelState = "Master" ' and check if the "ActiveModelState" is changed. MsgBox(comp.Definition.ActiveModelState)
But if I run this rule the ModelState will not change. Not sure what I do wrong or if this is a bug (@MjDeck ).
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.
Blog: hjalte.nl - github.com
You have to add an extra step. Here's sample code for a single part. This would have to be modified to make it run on multiple parts in an assembly.
Dim doc As PartDocument = ThisDoc.Document
Dim comp As DerivedPartComponent = doc.ComponentDefinition.ReferenceComponents.DerivedPartComponents.Item(1)
Dim derivedDef = comp.Definition
Logger.Info("current model state = {0}", derivedDef.ActiveModelState)
Dim stateWanted = "Model State1"
If (derivedDef.ActiveModelState <> stateWanted) Then
derivedDef.ActiveModelState = stateWanted
comp.Definition = derivedDef ' apply the modified definition back to the DerivedPartComponent
End If
Can't find what you're looking for? Ask the community or share your knowledge.