iLogic relationships retrieve parameter value

iLogic relationships retrieve parameter value

DFitting
Contributor Contributor
842 Views
8 Replies
Message 1 of 9

iLogic relationships retrieve parameter value

DFitting
Contributor
Contributor

Browser Bar.JPGI have an assembly that I placed subassemblies with an ilogic rule I wrote. When it places the parts and adds constraints, they are named. I've attached a picture for easy reference of what I mean. You will see sub-assembly "C-4" has 4 constraints N4 Mate:1, N4 Mate:2, N4 Mate:3 and N4 Angle:1. How can I access those values through iLogic? The parameters that control the are just the default sequential d0, d1, d2 ...etc. So how can iLogic know which parameters are attached to which constraint so that I can access the values of the parameters?

843 Views
8 Replies
Replies (8)
Message 2 of 9

WCrihfield
Mentor
Mentor

When get the constraint object, if it is defined as a specific type of constraint (exe. MateConstraint), there are usually properties exposed which will give you access to the Parameter(s) associated with them.

Here is a very basic example using the MateConstraint object:

Dim oMateConst As MateConstraint
Dim oParam1 As Parameter = oMateConst.Offset

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 3 of 9

WCrihfield
Mentor
Mentor

@DFitting 

You may have to use the .Type property of the AssemblyConstraint object to get its real ObjectTypeEnum (which annoyingly returns a number, which you then have to look up on a chart, before you can get a readable type name), before then defining the variable type to match, then setting this constaint as its value.  Then you should be able to access the specific properties of that type of constraint.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 4 of 9

myronHBBUW
Contributor
Contributor

@WCrihfield  can you give some example code?

 

I add components through Ilogic and i give that mate a name, but this name is only the relationship name and not the parameter name.  The mate has a offset dis0ancet that sometimes need to change.

 

If i can change the parameter with the relationship name that would be great. 

Otherwise if i can give the parameter a name when adding the constraints, that would also be helpful

 

Thanks

0 Likes
Message 5 of 9

WCrihfield
Mentor
Mentor

Hi @myronHBBUW.  Sure.  Changing the parameter's value directly would certainly be an easier & more efficient process than having to dig down into components &/or assembly constraints to find the right constraint, then looping through its properties, to find the associated parameter.  You may or not be familiar with this practice, but any time you are prompted to enter a numerical value that will be used for a parameter, such as when placing driving part sketch dimensions, or when creating features, and specifying values in a dialog box, you can almost always enter something like "WIDTH = 2.5 in", instead of just "2.5", and that will name the 'model parameter' that gets generated "WIDTH", as well as set the units.  This same practice can be used when coding, in certain situations.  The key thing to look, which will often indicate that this is possible, is when the Value that the property that you are about to set in your code is asking for a generic Variant or Object, instead of strictly just a Double.  When that is the case, you can usually supply a String there, which will be understood similarly to if you typed that String into the equation cell of a parameter in the parameters dialog box.  And when adding assembly constraints, either using the API methods, or iLogic shortcut snippets methods, it allows you to enter the parameter's value that same way (numerical or String).  When providing a String is possible, you can use something like the example above to name the 'model' parameter, as well as its value, as it gets initially created.

Dim oConsts As AssemblyConstraints
Dim oMate1 As MateConstraint
oMate1 = oConsts.AddMateConstraint(oEnt1, oEnt2, "ConstNameOffset = 2.5 in")
oMate1.Name = "ConstName"
Constraints.AddMate("ConstraintName", "Comp1:1", "EntName1", "Comp2:2", "EntName2", "ConstraintNameOffset = 2.5 in")

 

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 6 of 9

myronHBBUW
Contributor
Contributor

@WCrihfield , Thank you for your quick reply and explanation.

 

Adding a constrain name between quotation marks works perfect.

Is there also a way to make the "2.5 in" a variable?

 

otherwise i will edit the value later in the rule.

 

Constraints.AddMate("ConstraintName", "Comp1:1", "EntName1", "Comp2:2", "EntName2", "ConstraintNameOffset = Variable1")

 

Thanks in advance

0 Likes
Message 7 of 9

WCrihfield
Mentor
Mentor

Sure:

Dim sConstName AS String = "ConstraintName"
Dim Offset As String = "2.5 in"
Constraints.AddMate(sConstName , "Comp1:1", "EntName1", "Comp2:2", "EntName2", sConstName & "Offset = " & Offset)

Just one, of multiple possible ways to do that, depending on your needs, and how you want to name things.  I like to keep the numerical value as a String whenever possible, to preserve the 'units'.  Most of the time in iLogic, if you just type in a raw number that is supposed to represent a measurement, its gets automatically understood as 'database' units, instead of your 'document' units, or 'parameter' units.  Since I don't use the 'Constraints' shortcut snippet that much, I can't remember if it will understand a numeric (instead of String) value as database units, or document units.  If it understands it as document units, and you want the parameter to also be in document units, then there is no need for all the 'String' stuff there.  I'm just paranoid that way, after seeing tons of problems in that area.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 8 of 9

myronHBBUW
Contributor
Contributor

Thanks, a couple of characters can make a big difference! 

 

It appears that I don’t need to define as string, but do get some errors if I don’t  keep my offset value between quotation marks

 

Constraints.AddMate(sConstName , "Comp1:1", "EntName1", "Comp2:2", "EntName2", sConstName & "Offset = " & Offset)

0 Likes
Message 9 of 9

Curtis_Waguespack
Consultant
Consultant

Just a quick addition

 

Note that you can set the constraint to be linked to an existing parameter also:

 

Curtis_Waguespack_2-1675436213265.png

 

 

Curtis_Waguespack_3-1675436230010.png

 

 

 

EESignature