Inventor 2023 : Activate a model state, Incorrect parameter

Inventor 2023 : Activate a model state, Incorrect parameter

Sébastien_G
Advocate Advocate
299 Views
2 Replies
Message 1 of 3

Inventor 2023 : Activate a model state, Incorrect parameter

Sébastien_G
Advocate
Advocate

Hello everyone,

 

I want to activate the state of the "Main" model in an iam assembly in iLogic coding.

To do this, I'm using these few lines

I have not provided the lines of code from line 1 to 18 because they are comment lines requested by the client.

So, in the interests of confidentiality, I haven't included them in the attached screenshot.

 


















Dim ADoc As AssemblyDocument = DirectCast(ThisApplication.ActiveDocument, AssemblyDocument)
Dim ACDef As AssemblyComponentDefinition = ADoc.ComponentDefinition

ACDef.ModelStates.Item("Principale").Activate()

 

Unfortunately, these lines of code return the following error message:

Sbastien_G_0-1693903629441.png

 

Sbastien_G_1-1693903639698.png

 

This seems to be a fairly common error message on the forums, but I can't find a solution to my problem.

 

Would you have an idea for me, thank you.

@Sébastien_G 

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

Sébastien_G
Advocate
Advocate
Accepted solution

Information for anyone experiencing the same problem.

The solution is as follows:

ACDef.ModelStates.Item("[Principale]").Activate()

The cause of the error is a text string, it must be the same as the one indicated in your template browser.

In the past it was: "Principal(e)", with more recent versions it is: "[Principal]".

Likewise with the representations...etc

@Sébastien_G 

Message 3 of 3

WCrihfield
Mentor
Mentor

Hi @Sébastien_G.  Also, just so you know in the future, the Master/Primary/Principle ModelState (the original one that exists in all model files), is always the first one.  What I mean is its Index Integer is always one (1).  So ModelStates.Item(1) will always be that original ModelState.  This is because it was the first one to exist, and it can not be deleted, or renamed,  or repositioned within the ModelStates collection.  Therefore you do not necessarily need to specify it by its name, if you did not want to, to help ensure stability that lasts.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes