Inventor: Create custom property set

by Vladimir Ananyev

Issue

The custom properties are visible to end user through the properties dialog box. How to create some properties which are not shown in UI.

Solution

The Inventor API supports third party property sets which can be added and deleted. You can then add properties to those third party property sets. The sample VB .NET  code shown below adds a property set "autodesk" and adds a numeric property "empID". Complete C++ project is also attached.

 

VB .NET code:

Sub TestProps()

 

  ' Get access to Inventor session 

  Dim oApp As Inventor.Application = Nothing 

  Try 

    oApp = CType(Marshal.GetActiveObject( _

      "Inventor.Application"), Inventor.Application)

  Catch ex As Exception 

    MsgBox("Unable to access Inventor session")

    Exit Sub 

  End Try 

 

  Dim oDoc As Inventor.Document = oApp.ActiveDocument

 

  If (oDoc IsNot Nothing) Then

 

    ' Get Property Sets collection

    Dim oPropSets As PropertySets = oDoc.PropertySets

 

    ' Property set name

    Dim sPropSetName As String = "autodesk"

    Dim PropName As String = "empID"

    Dim PropID As Integer = 51 ' ID

    Dim PropValue As Object = 777 ' value

    ' Property to be added

    Dim oProp As Inventor.Property = Nothing

 

    ' Create your own property set

    ' Check whether your prop set already exist

    'get reference to the property set if it exists

    Dim oPropSet As PropertySet _

        = GetCustomPropSet(oDoc, sPropSetName)

    If (oPropSet Is Nothing) Then

      'create new property set

      oPropSet = oPropSets.Add(sPropSetName)

      ' Add new property

      oProp = oPropSet.Add(PropValue, PropName, PropID)

      MsgBox("Added value: " & oProp.Value.ToString)

    Else

      ' Get the value of prop and display it

      oProp = oPropSet.ItemByPropId(PropID)

      oProp.Value = PropValue

      MsgBox("Current value: " & oProp.Value.ToString)

    End If

  Else

    MsgBox("Open some Inventor document")

  End If

End Sub

 

Private Function GetCustomPropSet( _

            ByVal oDoc As Inventor.Document, _

            ByVal Name As String) As PropertySet

  For Each oPS As PropertySet In oDoc.PropertySets

    If oPS.Name = Name Then Return oPS

  Next

  Return Nothing

End Function


Download TestProps_Cpp

 


Comments

2 responses to “Inventor: Create custom property set”

  1. New APP for Sheet metal & Automate CUSTOM iProperties for Autodesk Inventor.
    Now compatible from 2013 to 2017
    you can view data sheet & video at:
    https://apps.autodesk.com/INVNTOR/it/Detail/Index?id=appstore.exchange.autodesk.com:mc-cadinventortemplete:en

  2. Jerry Berns Avatar
    Jerry Berns

    I realize this is an old post, but what is required to get this code to work with Inventor 2019?
    I loaded the code into Visual Studio 2017, but errors (red, underlined text) were indicated for:
    Inventor.Application
    Marshal.GetActiveObject
    PropertySets
    and a few others. I think I am missing the proper References required.
    I also tried adding this code to an iLogic rule. I corrected the errors I could, but I am confident there is an issue with the term, ‘Marshal’.
    I look forward to any assistance.
    Regards,
    Jerry

Leave a Reply to Jerry BernsCancel reply

Discover more from Autodesk Developer Blog

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

Continue reading