Adding constraints using ilogic

Adding constraints using ilogic

lee_gardnerXXNJE
Participant Participant
821 Views
7 Replies
Message 1 of 8

Adding constraints using ilogic

lee_gardnerXXNJE
Participant
Participant

Hi All,

 I have an issue that I'm hopeful you all can help with. I will start by saying that I'm fairly new to iLogic, (Inventor user for almost 20 years, iLogic about 3 months)

 

I am trying to resolve an ilogic issue I currently have. 

My models are set up as master models and get copy designed regularly and the first part of the part number always changes. This hasn't been a problem up to now. The way the iLogic is set up I use the code below:

 

 

oDoc = ThisDoc.FileName(False)
oVin = Left(oDoc, InStr(oDoc, "-") -1)


 

 

Then I apply oVin as my changeable part number so when I want to pass parameters down from an assembly to part parameters I use  

 

 

Parameter(oVin & "-123456:1", "HEIGHT") = MASTER_HEIGHT

This works really well.

 

The problem I have is when I want to add components and add constraints, For example, at the top assembly level I use ilogic to add a boss and I want to apply a constraint between its X Axis and a know axis in one of the other parts. Inventor doesn't like the oVin term

 

Constraints.AddMate("Mate1", "BOSS:1", "X Axis", oVin & "-Manifold_Block", "BOSS AXIS",

 

This is the error I get

 

Unable to cast object of type 'System.String' to type 'Autodesk.iLogic.Types.ComponentArgument'.

 

Any help would be appreciated 

0 Likes
Accepted solutions (1)
822 Views
7 Replies
Replies (7)
Message 2 of 8

Curtis_Waguespack
Consultant
Consultant

Hi @lee_gardnerXXNJE ,


Welcome to the forum. I think you will want to do something like this.

 

Hope that helps,

Curtis

 

Dim oComponent = Component.InventorComponent(oVin & "-Manifold_Block")

Constraints.AddMate("Mate1", "BOSS:1", "X Axis", oComponent.Name, "BOSS AXIS")

 

EESignature

0 Likes
Message 3 of 8

lee_gardnerXXNJE
Participant
Participant

Hi @Curtis_Waguespack ,

 Thanks, I tried that and the error i get is that it cant find the part with the oVin number. But the error has the correct part number and the part is in the model so thats both positive.

Sorry, i havent used Dim ocomponent previously, do i rename ocomponent and ocomponent.name in the code to a name? Im trying to understand what its doing, is it assigning the oVin part number to a single string?

0 Likes
Message 4 of 8

Curtis_Waguespack
Consultant
Consultant
Accepted solution

Hi @lee_gardnerXXNJE , no need to apologize. See if this clears anything up. I might be overexplaining some of it, but I wasn't sure where the error is coming from.

 

Post back if you have more questions.

 

hope that helps,

Curtis

 

 

Dim oComponent = Component.InventorComponent(oVin & "-Manifold_Block")

The line above is just getting the component occurrence from the assembly and assigning it to a variable called oComponent.

 

So if we had this as the assembly:

Curtis_Waguespack_0-1733347729965.png

 

 

... oComponent would be getting the component named 1234-Manifold_Block 

 

The next line then uses that variable with the .name property, so that we get the name string from the component to use in the constraint add line.

 

Constraints.AddMate("Mate1", "BOSS:1", "X Axis", oComponent.Name, "BOSS AXIS")

 

 

Here it is in use, in a simple example assembly where oVin is just being hardcoded for simplicity sake.

Curtis_Waguespack_2-1733347465716.png

 

 

EESignature

0 Likes
Message 5 of 8

lee_gardnerXXNJE
Participant
Participant

Thanks @Curtis_Waguespack,

 That worked perfectly, I will be using that in alot of places now

Message 6 of 8

lee_gardnerXXNJE
Participant
Participant

Hi @Curtis_Waguespack ,

 Sorry 1 more question, What if the part I am trying to constrain to is multiple levels deep? So to follow on our example above the manifold block is sitting in a sub assembly, 1 or 2 levels deep

0 Likes
Message 7 of 8

Curtis_Waguespack
Consultant
Consultant

Hi @lee_gardnerXXNJE ,

see the info below.

Hope that helps, Curtis

 

You could do it something like this, where the curly brackets are used to denote the array path to the component:

 

oVin = "1234"
oComponentName =  oVin & "-Manifold_Block"
Constraints.AddMate("Mate:7", "Block99", "BottomFace", {"Front Assembly", oComponentName}, "FrontFace")

 

Where this is the assembly:

Curtis_Waguespack_0-1733369169767.png

 

Note that to get the syntax, you can find the constraint in the iLogic editor as shown, and right click and choose Capture Current State ( Constraints.Add)

 

Then it's just a matter of modifying the resulting line to plug in the assembled component name using oVin, etc.

 

Curtis_Waguespack_2-1733369287367.png

 

 

 

EESignature

0 Likes
Message 8 of 8

lee_gardnerXXNJE
Participant
Participant

Hi @Curtis_Waguespack 

Thanks i will try that shortly, and...OMG that Capture thing has just blown my mind. Looking forward to trying that

0 Likes