Community
Inventor Programming - iLogic, Macros, AddIns & Apprentice
Inventor iLogic, Macros, AddIns & Apprentice Forum. Share your knowledge, ask questions, and explore popular Inventor topics related to programming, creating add-ins, macros, working with the API or creating iLogic tools.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

iLogic control parameters in Model States.

13 REPLIES 13
SOLVED
Reply
Message 1 of 14
theodkary
4791 Views, 13 Replies

iLogic control parameters in Model States.

Hello, 

 

My question has to do with the addition of Model States in Inventor. I want to control parameters from iLogic according to Model State from an assembly. Sure I can set manually or from excel, different values for parameters in the part, but in the assembly some of those, in my case, are often changing according to the use of the part and the customer's order.

 

Until 2021 I was connecting the parameters of an assembly via ilogic, with parameters inside the parts that belong to this assembly. So by changing the parameter in the assembly, all the parts with an ilogic connection to it, were changing accordingly. 

 

With model states, how can I specify which exact parameter i want to change to the exact model state? 

 

To clarify I will give an example: 

- I have Part1 that has a parameter called "Length". This parameter changes according to 3 model states. 

Model State1 =>   Length = 1000 mm

Model State2 =>   Length = 2000 mm

Model State3 =>   Length = 3000 mm

 

- In an assembly I have 3 parameters called "Length_1",  "Length_2", and "Length_3".

Now in the assemply I will add Part1 with 3 model states, and I would like to connect it with the bellow logic:

Parameter("Part1:1" , "Length")  = Length_1                '(Model State1)

Parameter("Part1:2" , "Length")  = Length_2                '(Model State2)

Parameter("Part1:3" , "Length")  = Length_3                '(Model State3)

 

With a colleague we managed to find a solution that seems to be working: 

Dim AssDoc As AssemblyDocument = ThisApplication.ActiveDocument
Dim Occ As Inventor.ComponentOccurrence
Dim partcomp As PartComponentDefinition
Dim partdoc As Inventor.PartDocument

Occ = AssDoc.ComponentDefinition.Occurrences.ItemByName("Part1:1")
partdoc = Occ.Definition.Document
Occ.ActiveModelState = "Model State1"
partdoc.ComponentDefinition.Parameters.UserParameters.Item("Length").Value = Length_1

AssDoc.Update2
AssDoc.Save2


Occ = AssDoc.ComponentDefinition.Occurrences.ItemByName("Part1:2")
partdoc = Occ.Definition.Document
Occ.ActiveModelState = "Model State2"
partdoc.ComponentDefinition.Parameters.UserParameters.Item("Length").Value = Length_2

AssDoc.Update2
AssDoc.Save2

 

Is there a simpler way or better way to do that?

13 REPLIES 13
Message 2 of 14
CattabianiI
in reply to: theodkary

First of all you should be clear if you need to take advantage the new model state concept, for example if you want iProperties changing with model state. If you think this way fits your needs better by improving previous Inventor workflow, that's how I would implement it in Inv2022.
In this case DO NOT WORK with parameters AND model states, the parameter change is already define in the model state.

Place the occurrences in assembly, without worrying about the active model state, I would place them in the master one. Then add the rule and change the asm parameters as you want.


 

 

Dim length2ModelState As New Dictionary(Of Integer, String) From {
{1000, "Model State1" },
{2000, "Model State2" },
{3000, "Model State3" }
' Or changing the model states name with explanatory name
'{1000, "short" },
'{2000, "medium" },
'{3000, "long" }
}

Dim AssDoc As AssemblyDocument = ThisApplication.ActiveDocument
Dim Occ As Inventor.ComponentOccurrence
Dim partcomp As PartComponentDefinition
Dim partdoc As Inventor.PartDocument


Occ = AssDoc.ComponentDefinition.Occurrences.ItemByName("Part1:1")
Occ.ActiveModelState = length2ModelState(Length_1)

Occ = AssDoc.ComponentDefinition.Occurrences.ItemByName("Part1:2")
Occ.ActiveModelState = length2ModelState(Length_2)

AssDoc.Update2
AssDoc.Save2

 

 




Message 3 of 14
theodkary
in reply to: CattabianiI

Good morning, and thank you for the reply!

 

For sure, I want to take advantage of the model state concept. So, in the code you gave me you assume that the part has the same Parameter called Length_1 like in the Assembly.

 

That is not true though. In my case The assembly has 3 parameters Length_1, Length_2 and Length_3 that will change one parameter in the part called Length. Depending on each model state of course. 

 

Also, the parameters Length_1, Length_2 and Length_3 that drive the part are changing according to the customers order. 

Message 4 of 14
CattabianiI
in reply to: theodkary

Let's just discuss about that three measures at the moment.

> in the code you gave me you assume that the part has the same Parameter called Length_1 like in the Assembly.
No! I don't work with part parameter, I just use the assembly parameter to activate the linked model state.
It's the model state which drives the part length.
And this is how your model state table should look like:

CattabianiI_0-1617982052775.png

Hence from the assembly you don't have to set the part length anymore but just activate the proper model state.
Am I missing something? Did you get the workflow I'm pointing out here?




Message 5 of 14
theodkary
in reply to: CattabianiI

Yes of course I get what you are saying. I am well aware of the "proper" use of model states. In many cases I will use it just the way you are saying. In the case I am describing though, things are a bit different. I will give you a simplified yet real example that may be more clear.

 

We have an elevator platform that on each side except the front side (entrance), it has a sheet metal apron. This apron is the same as a design concept, no matter the side, in all except its length. 

 

Now the elevator, varies in sizes in depth and width according to the customer order. So the aprons too can take hundreds of different lengths.

 

Until now I was instructing the designers to have separate apron files for the sides (left, right) and rear to be able to coexist in an assembly. With the addition of the model states, we have the ability to create with one part file, different configurations with different properties. This will simplify our work a lot in some cases, in design as well as in the software developing for modeling. 

 

So, in trying to find ways to do the above, I created as a test an apron that has 2 model states one for the side apron (left & right) and one for the rear apron. 

 

Apron.ipt

- Side (model state)

- Rear (model state)

 

In the assembly, I have the same apron part added with the 2 different model states. There are 2 dimensions for the platform that control depth and width of the elevator cabin and therefore the platform and the aprons. 

 

Platform.iam

-- Apron.ipt with Side (model state)

-- Apron.ipt with Rear (model state)

 

That means that with each customer order, the generated assembly is giving to each connected part via ilogic a new value. 

 

Platform width = Rear Apron Length

Platform depth = side Apron Length

 

When the Platform width is 1100 then the apron with rear model state has also length 1100 and so on. 

When the Platform depth is 1400 then the apron with side model state has also length 1400 and so on. 

Message 6 of 14
CattabianiI
in reply to: theodkary

Hi @theodkary,
yes it's more clear now, thanks.

I attached an example of your use case. The main difference with the rule you posted above is that I set the parameter in the factory document. It's not 100% clear to me but what I understand from my testing is that when I had to _write_ data into a model state is better to do this through the factory document.
So this is the rule I came up with:

Dim asmDoc As AssemblyDocument = ThisApplication.ActiveDocument

Dim occSide As ComponentOccurrence = asmDoc.ComponentDefinition.Occurrences.ItemByName("Side")
Dim facDoc As Document = occSide.Definition.FactoryDocument

' Make sure the factory has activated the model state I want to work with
' I do not change the active model state for the occurrence facDoc.ComponentDefinition.ModelStates.Item("Side").Activate() facDoc.ComponentDefinition.Parameters.ModelParameters.Item("length").Value = Width asmDoc.Update() facDoc.ComponentDefinition.ModelStates.Item("Rear").Activate() facDoc.ComponentDefinition.Parameters.ModelParameters.Item("length").Value = Length asmDoc.Update() asmDoc.Save()

I create a form to configure the platform.
The model state table of Apron.ipt must have the length param column.
The occurrences are already placed in the platform in the proper model state, if that fits your needs otherwise you can active the occurrence model state with the ComponentOccurrence.ActiveModelState property but you still have to set the parameter through the factory document as in the code above.

Message 7 of 14
theodkary
in reply to: CattabianiI

This works perfectly! It's a different approach to my solution, and it will help me a lot in the more complicated automation!

 

Thank you so much!

 

 

Message 8 of 14

Whenever I use this code to update my parameters it converts my inch parameters to metric. Is there a way to utilize this code within the imperial system?

Message 9 of 14
CattabianiI
in reply to: theodkary

Message 10 of 14

Understand this is an old post... 

Trying to get some parameters to past to model states using this syntax:

facDoc.ComponentDefinition.Parameters.ModelParameters.Item("Param1").Value = Param2

It does pass BUT the Param1 becomes 10 x Param2.

Believe this is a unit thing but both documents are in millimeters. Both parameters are in millimeters.  

 

Tested printing:

MessageBox.Show(facDoc.ComponentDefinition.Parameters.ModelParameters.Item("Param1").Units) 

This returns mm

 

Any help on this would be amazing. 

Message 11 of 14

It is the link in the message just above yours, where you can find out how to convert the database units (the ones Inventor uses internally) into the units you need and vice versa

Message 12 of 14
theodkary
in reply to: theodkary

As an update to the subject, you can take a look at my post on the link:

https://forums.autodesk.com/t5/inventor-ilogic-api-vba-forum/managing-changes-in-model-states-ilogic... 

 

Message 13 of 14

Hi, I would like use Model States feature use for simplify assemblies only with suppressed OC parts:
Master - all parts active
Simple - all subassy in MS Simply + OC in top level suppress
Simple DRW - all subassy in MS Simply + OC in top level active
But if not apply change use for all family, in exist model states not update mates parameters and after activate other state is components in other positions.
Can you help me with rule for delete all columns in modelstates.table for clear table (except first culomn with model states name).
I wrote rule for suppress OC part in all standard model state, so after clear table is fill only suppressed parts and no parameters changes.

Message 14 of 14
J_Dumont
in reply to: CattabianiI

Hi @CattabianiI 

 

I trying to use your code in inventor 2024 and it fails when trying to update the parameter.

 

I'd appreciate any input you could provide.

 

Here's my code..

 

'Set Grille style using Model States
Dim LinearBarLength = GrillLength - GrillToFeameClearance
Component.ActiveModelState("Linear Bar")=BarGrilleStyle

Dim asmDoc As AssemblyDocument = ThisApplication.ActiveDocument
Dim occSide As ComponentOccurrence = asmDoc.ComponentDefinition.Occurrences.ItemByName("Linear Bar")
Dim facDoc As Document = occSide.Definition.FactoryDocument

' Make sure the factory has activated the model state I want to work with
' I do not change the active model state for the occurrence
facDoc.ComponentDefinition.ModelStates.Item(BarGrilleStyle).Activate()
facDoc.ComponentDefinition.Parameters.ModelParameters.Item("length").Value = LinearBarLength
asmDoc.Update()

 Here is the error

 

J_Dumont_0-1715356693401.png

 

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Technology Administrators


Autodesk Design & Make Report