iProperty Expressions

In the iProperties dialog, Inventor allows you to create expressions for the values of iProperties.  Using an expression you can combine the values of other iProperties into a single iProperty value.  (By using the functionality described in a previous post to create an iProperty for a parameter, you can also use parameter values in an expression.)  To create an expression just enter an “=” sign as the first character of the iProperty value.  Inventor will now treat this as an expression.  An expression can consist of any text and can reference any existing iProperties by specifying their names in brackets, as shown below.  The expression in this example uses the iProperty named “Part Number” and two custom iProperties named “Length” and “Height” that were created by exporting parameters.

iPropertyExpression

Once you’ve finished entering the expression and press return, the expression is evaluated and the resulting value is displayed, as shown below. 

iPropertyExpressionResult

The fx symbol to the right of the field indicates that the property is defined using an expression.  To edit the expression, rather than the value, right-click in the iProperty field and select the Edit Expression command from the context menu, as shown below.

EditExpression

To use expressions through the API you use the Expression property of the Property object.  This is demonstrated below.  The Expression property is the equivalent of editing the expression in the iProperties dialog.  When setting the value of the Expression property you need to follow the same rules as when creating an expression in the iProperties dialog.  The Value property of the Property object will always return the evaluated result.  Setting the value through the Value property will remove the expression associated with the property or you can set the value of the expression to an empty string (“”).

Public Sub TestExpression()          Dim partDoc As PartDocument           Set partDoc = ThisApplication.ActiveDocument                 ' Get the Design Tracking property set.              Dim designTrackPropSet As PropertySet           Set designTrackPropSet = partDoc.PropertySets.Item( _                                            "Design Tracking Properties")                 ' Get the Description property.              Dim descProp As Property           Set descProp = designTrackPropSet.Item("Description")                 ' Add an expression to the property.              descProp.Expression = _                            "= size is  x "       End Sub

The program below removes the expression from the property but maintains the property’s current value.  It does this by setting the value of the property to its current value.  This would at first seem like it wouldn’t do anything, but in the case where the property is defined using an expression, setting the value of the property removes the expression.  It’s just that in this case the value we’re setting it to happens to be the current displayed value.

Public Sub TestExpression()        Dim partDoc As PartDocument         Set partDoc = ThisApplication.ActiveDocument             ' Get the Design Tracking property set.            Dim designTrackPropSet As PropertySet         Set designTrackPropSet = partDoc.PropertySets.Item( _                                          "Design Tracking Properties")             ' Get the Description property.            Dim descProp As Property         Set descProp = designTrackPropSet.Item("Description")             ' Set the value of the property to it’s current value.           ' This has the side-effect of removing an associated expression.
descProp.Value = descProp.Value   End Sub

Comments

One response to “iProperty Expressions”

  1. Great! Thanks Brian.

Leave a Reply

Discover more from Autodesk Developer Blog

Subscribe now to keep reading and get access to the full archive.

Continue reading