D.S

adndevblog.typepad.com

Inventor: Create custom property set - Manufacturing DevBlog

Inventor: Create custom property set - Manufacturing DevBlog Manufacturing DevBlog The resource for software developers working with Design, Lifecycle and Simulation technologies from Autodesk. Home Subscribe Follow Useful Links Autodesk About this Blog « Inventor: Access to AssemblyConstraint objects | Main | Inventor: Scale of a Drawing » 01/06/2013 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   Posted at 01:03 AM in Inventor , Vladimir Ananyev , Wayne Brill | Permalink | | | Comments 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   View the entire comment