cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Add Property/Method To API For Parameter Type Objects – Get/Set Value In Parameter/Document Units

Add Property/Method To API For Parameter Type Objects – Get/Set Value In Parameter/Document Units

This one has been needed and begged for since the very beginning.

There needs to be a new Property or Method added to the API for Parameter type (Class) objects (Parameter, UserParameter, ModelParameter, ReferenceParameter, DerivedParameter, TableParameter), that will Get the Value of the Parameter in the Parameter's own Units, instead of in ‘database units.  If I typed the numerical value of 13.77 into the Equation column cell of a UserParameter in the Parameters dialog box, and the units of that UserParameter in the dialog box is set to “in” (Inches), I want to get that exact numerical value (not String) back from that UserParameter, in those exact units, without it being automatically converted to something else, when I retrieve it from that UserParameter in my code using the API route.  This is so outrageously irritating, inefficient, and illogical.  This shouldn’t be that difficult to accomplish for a company as massive as Autodesk.

 

Something like this:

 

Dim oPartDoc As PartDocument = ThisApplication.ActiveDocument
oVal = oPartDoc.ComponentDefinition.Parameters.Item("MyParam1").ValueInParameterUnits

 

Because Parameter.Value and Parameter.ModelValue both return the value in database units.

 

I am aware of the iLogic Snippets:

 

Parameter("d0") = 1.2
Parameter("Part1:1", "d0") = 1.2
Parameter(MakePath("SubAssem1:1", "Part1:1"), "d0") = 1.2

 

 

I know that this snippet accesses the Parameter’s Value, and gets/sets its value in the parameter’s units.  But these are Properties of the iLogic Add-in’s IParamDynamic Interface, and not true API object Properties, and they have never been fully explained anywhere, in all the years they have been available.  When you want to access a parameter in another document, the first ‘input variable’ requested is named “componentOrDocName”, and is defined as an Object, not a String.  This variable has never been fully and specifically documented anywhere that I have ever seen.  It is very unclear at best.  And the fact that it is defined as an Object, leads us to believe that might accept something other than a String type value, but I have never seen any other object/data type used in that position, other than a String.  In the case where you want to access a parameter in an assembly component, I have come to understand (through experience, not documentation) that it wants the same value as is returned from the ComoponentOccurrence.Name (also the same as is shown in the assembly’s model browser).  But in the case where you want to access a parameter in another document (not an assembly component), I have learned that it wants the file name (without path & with file extension), but this is also not documented anywhere, and often times that doesn’t even work.  Also, it seems like the Document.DisplayName will work there, but that is a Read/Write property, and doesn't always work either.

 

'local' = in the same document that the rule is saved within

 

And I’m also aware of using the unquoted name of a ‘local’ parameter in a ‘local’ rule, and that it will represent the direct value of the parameter in the parameter’s units, but this only works in ‘local’ rules, not in external rules or other external code.

3 Comments
MjDeck
Autodesk

@WCrihfield , the iLogic properties are in document units, not parameter units. Those two are usually the name. But if you happen to have an inch parameter in a millimeter part, the iLogic properties will return (or assign) the value of that parameter in millimeters. The reason for that : it makes it easier to do math with the values of different parameters within a rule.

There is an iLogic property that gives you access to a parameter in any document. If you have a Document object:

 

 

 

Dim doc as Document
' assign the doc object here...
Dim lengthValue = iLogicVb.Automation.ParamValue(doc, "Length") ' get the current value
iLogicVb.Automation.ParamValue(doc, "Length") = 5.0 ' assign another value

 

 

 

This property is described (without much detail) here.

It's similar to the Parameter snippet. For numeric parameters, the units will be the ones associated with the document that you provide when calling ParamValue (e.g. the object named "doc" in the code sample above).

WCrihfield
Mentor

Thank you @MjDeck.  I really appreciate the time, attention, and help you provided here.  I did mix my words a bit in that original post (document units vs parameter units), which could lead to some confusion.  After a little testing I found what you said to be very true.  Document units are set within the Document Settings of the document, while parameter units are set individually for each parameter, usually within the Parameters dialog box.  And I know that when you create new numerical type user parameters within the parameters dialog box, the units default to the document units.  But you have the option to change those units to something else, per parameter.  I may have parameters in Inches, Feet, Yards, and other similar units all in one document though, and I created those parameters in those units on purpose, because that's now I use them, need to see them, and how I need to document them.  It just surprised and disappointed that there is not a direct way to pull those values, in those units (as seen in the Parameters dialog box) from those Parameter objects, without having to go through some sort of extra units conversion steps.  Those units conversions should be handled automatically in the background, by either iLogic or the Inventor API, so users don't have to deal with it.  It shouldn't be the burden of the user, it should be the burden of the software or API system.  If we didn't use units conversions when we entered the values, we shouldn't need to use units conversions to extract those same values.

 

The Parameter() iLogic snippet and the iLogicVb.Automation.ParamValue() iLogic snippet are really nice, but they both return the parameter's value in document units, even when the parameter itself may be set to other units (the parameter's units).  I would like a direct way to get the parameter's value in the parameter's own units.  That's the main point of this Idea.

 

By the way...just an additional note to others about what the 'componentOrDocName as Object' is asking for when using the Parameter(Object, String) snippet to access parameters in another document.  Here is a link to a similar post about the iProperties.Value(Object, String, String) snippet that uses that same terminology and behavior, that may be enlightening.

 https://forums.autodesk.com/t5/inventor-ilogic-api-vba-forum/retreaving-custom-iproperty/m-p/1095703... 

MjDeck
Autodesk

@WCrihfield , the choice of document units for iLogic was a compromise. We knew that for ease of use, we couldn't go with database units (cm) or any other fixed unit. Mixes of length units in a single document are not that common. So to make it easy to do things like add two values in different units together, we went with document units.

I agree : it would make sense to provide API functions to get and set the value in parameter units. You're probably familiar with code like the following. For other readers of this post, here's a sample of the extra code required to convert values. This is iLogic, but it could be easily converted to VBA.

 

 

Dim doc As PartDocument = ThisApplication.ActiveDocument

Dim length_param = doc.ComponentDefinition.Parameters("Length")
Dim value_in_cm = length_param.Value
Dim value_in_units = doc.UnitsOfMeasure.ConvertUnits(value_in_cm, UnitsTypeEnum.kDatabaseLengthUnits, length_param.Units)

Logger.Info("length value in parameter units = {0}", value_in_units)

Dim new_value = 40 ' mm
Dim new_value_in_cm = doc.UnitsOfMeasure.ConvertUnits(new_value, length_param.Units, UnitsTypeEnum.kDatabaseLengthUnits)
length_param.Value = new_value_in_cm

 

 


Note : it makes sense to return the Value of a parameter in cm, because all length values in the API are cm. But since parameters can have other units, it also makes sense to provide a way to access the value in those units.

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

Submit Idea