Parameters as iProperties

The next few posts I’ll be making are intended to complete my coverage of topics related to iProperties.  I’ve made several recent posts that I believe cover the majority of the API functionality that will enable you to write most programs that use iProperties.  However, there are a few odds and ends that I haven’t covered.  Here’s the first of these last set of posts on iProperties.

In the Parameters dialog you can check the Export Parameter box for a parameter, as shown circled below.  This is useful because there are quite a few areas in Inventor that provide access to property values, (text in drawings, BOM, etc.), and by exporting a parameter as a property it extends the use of the existing functionality to also be able to use parameters.

ExportParameter

This causes a custom iProperty to be created that contains the value of that parameter.  This is a one-way association.  Changing the parameter will cause the iProperty to update, but changing the value of the iProperty will not cause the parameter to update.  The iProperty is just a reflection of the parameter and will be updated whenever the parameter value changes.

If the Export Parameter box is checked, then you can also access the Custom Property Format… command through the context menu, as shown below.

CustomPropertyFormatCtxMenu

This displays the dialog shown below where you can control the format of the iProperty that’s created for this parameter.

CustomPropertyFormat

This all results in the iProperty shown below.  The name of the iProperty is the same as the parameter.  If an iProperty of that name already exists, it’s value will be overwritten to the value of the parameter.  You can edit and even delete the iProperty, but Inventor will overwrite the edited value or re-create the iProperty whenever the parameter value changes.

ParamAsCustomiProp

From the API you can also set the “Export Parameter” box for a parameter.  You do this by using the ExposedAsProperty property of the Parameter object.  With Inventor 2010 and later you can also edit the formatting of the resulting iProperty using the CustomPropertyFormat property of the Parameter object.  This is demonstrated in the code below.

Dim param As Parameter
Set param = partDoc.ComponentDefinition.Parameters.Item("Length")
param.ExposedAsProperty = True

param.CustomPropertyFormat.Precision = kThreeDecimalPlacesPrecision
param.CustomPropertyFormat.ShowTrailingZeros = True
param.CustomPropertyFormat.ShowUnitsString = True
param.CustomPropertyFormat.Units = "in"

iProperties created as the result of an export appear like any other property through the API.  In fact, the iProperty doesn’t know it’s the result of an export.  If you need to find the iProperties that were created through an export you’ll would need to look through the parameters to see if any of them have been exported.


Comments

6 responses to “Parameters as iProperties”

  1. Sundeep Avatar
    Sundeep

    Thanks a lot Brian.
    It was very helpful

  2. We mark all parameters for export with this code:
    Public Sub MarkAllParametersForExport()
    Dim oPartDoc As PartDocument
    Set oPartDoc = ThisApplication.ActiveDocument
    Dim oParameter As Parameter
    For Each oParameter In oPartDoc.ComponentDefinition.Parameters
    oParameter.ExposedAsProperty = True
    Next oParameter
    MsgBox “Done!”, vbInformation
    End Sub

  3. Very nice. I will definitely use this. I just wonder how I’ve missed it all these years?!

  4. Hi
    Is it possible to ask some questions regarding macros in other subjects, How?
    thank you very much for helping us, I really appreciate that.

  5. Any change you can show how to add parameters through the API (preferably via VB.net if possible)

  6. Hi Brian,
    I’ve been able to create numeric parameters, but am really struggling to figure out how to create a text parameter. Does the API support this?
    Thanks

Leave a Reply to RamyCancel reply

Discover more from Autodesk Developer Blog

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

Continue reading