In all previous iProperty related posts I’ve only talked about working with the four public property sets; Design Tracking, Summary Info, Document Summary Info, and User Defined. The first three of these contain a fixed number of properties while the user defined allows you to add and delete your own properties. This mirrors the iProperty functionality that’s available through Inventor’s user-interface.
Using the API it’s possible to create new property sets in addition to these standard four. A property set created using the API is not visible through the user-interface. For example, it does not automatically create a new tab in the iProperty dialog. It is only accessible through the API. The code below creates a new property set named “MyStuff” and a property named “Favorite Fruit”.
Public Sub CreatePropertySet()
' Get the active document.
Dim doc As Document
Set doc = ThisApplication.ActiveDocument
' Create a new property set.
Dim customSet As PropertySet
Set customSet = doc.PropertySets.Add("My Stuff")
' Add a property.
Call customSet.Add("Banana", "Favorite Fruit")
End Sub
Here’s some sample code that accesses and reads the value of the property created above.
Public Sub ReadProperty()
' Get the active document.
Dim doc As Document
Set doc = ThisApplication.ActiveDocument
' Get the custom property set.
Dim customSet As PropertySet
Set customSet = doc.PropertySets.Item("My Stuff")
' Get the value of the "Favorite Fruit" property.
Dim fruit As String
fruit = customSet.Item("Favorite Fruit").value
MsgBox "The favorite fruit is: " & fruit
End Sub
Hopefully you can see that working with these custom property sets is not any different than working with the standard property sets. It’s likely that you won’t ever need for this capability but sometimes it can come in handy. The primary use is when you need to store additional data with a file. iProperties especially make sense when you want to be able to access this information from Apprentice. An example of where Inventor uses this functionality is Content Center. Content Center adds an new property set to the parts it creates and uses the property set to store information about the part.
A useful tool when working with iProperties is a sample program that’s delivered with the Inventor SDK. Assuming you’ve installed the developer tools using the DeveloperTools.msi in the SDK directory, you’ll find the following directory:
SDK\DeveloperTools\Samples\VB\Standalone Applications\ApprenticeServer\Properties
It’s an old VB6 sample, but you can use the EXE without having VB6. When you run the EXE, the dialog below is displayed. You use the button at the top to browse to any Inventor file. The property sets and properties are then displayed in the dialog and you can double-click on most properties to edit them. I use tool anytime I want to know about all of the iProperties in a document.