Change Drive Part Model Stage using iLogic

Change Drive Part Model Stage using iLogic

frahaman7SKBG
Advocate Advocate
935 Views
4 Replies
Message 1 of 5

Change Drive Part Model Stage using iLogic

frahaman7SKBG
Advocate
Advocate

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. 

 

frahaman7SKBG_0-1632424300712.png

 

0 Likes
Accepted solutions (1)
936 Views
4 Replies
Replies (4)
Message 2 of 5

JelteDeJong
Mentor
Mentor

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.

EESignature


Blog: hjalte.nl - github.com

0 Likes
Message 3 of 5

frahaman7SKBG
Advocate
Advocate
Thank you @JelteDeJong for your reply. Your snippet is definitely a start. It is able to grab the ActiveModelState.

Does anyone here know how to ChangeModelState?
0 Likes
Message 4 of 5

MjDeck
Autodesk
Autodesk
Accepted solution

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

 


Mike Deck
Software Developer
Autodesk, Inc.

Message 5 of 5

frahaman7SKBG
Advocate
Advocate
Thank you @MjDeck. I was able to take your snippet and modify it to make it work.
0 Likes