Inventor documents have a set of properties (iProperties) associated with them and are organized into Property Sets, with related properties found in a given set. Each PropertySet is identified by its Display Name and an Internal Name and each of the Properties that it contains is in turn identified by its PropertyID and an optional Name. It is possible to create new PropertySets, which contain user defined properties in addition to the four predefined PropertySets. None of the Inventor created PropertySets can be deleted,but those that are created by third parties can be.
The DisplayNames of all the PropertySets can be changed. In addition to changing the names of the Properties their values can also be changed. In order to access a particular Property within a particular PropertySet (in order to change its Value or Name) one can do so directly instead of having to iterate through all the PropertySets.
The following examples (VB6, VB.NET and c++) show how to access a particular Propertycalled "Cost" within the PropertySet "Design Tracking Properties irectly using the PropertyID.The example also shows how to create new PropertySets/Properties and how to set/change valuesof properties. Using Apprentice Server all additions/changes to the PropertySets collection can be saved using the PropertySets.FlushToFile method instead of having to save the entire document.
Public Sub PropFromApprentice()
' Start Apprentice
Dim newApp As ApprenticeServerComponent
On Error Resume Next
newApp = CreateObject("Inventor.ApprenticeServer")
If newApp Is Nothing Then
MsgBox("cannot start Apprentice")
End
End If
Dim newDoc As ApprenticeServerDocument
' open the document
newDoc = newApp.Open("C:\Temp\Part1_08.ipt")
Dim propsets As PropertySets
propsets = newDoc.PropertySets
'Another way to access propertysets and properties
Dim i As Integer
For i = 1 To propsets.Count
If propsets(i).DisplayName = _
"Design Tracking Properties" Then
Dim prop As Inventor.Property
Dim j As Integer
For j = 1 To propsets(i).Count
prop = propsets(i).Item(j)
If prop.Name = "Cost" Then
prop.Value = "250"
End If
Next
End If
Next
' Accessing a particular property
' of a particular propertyset directly
propsets.Item("Design Tracking Properties"). _
ItemByPropId( _
PropertiesForDesignTrackingPropertiesEnum. _
kCostDesignTrackingProperties).Value = "300"
' you could also pass the Internal Name
' or the index as a parameter to the Item method.
' adding the new propertyset
On Error Resume Next
Dim NewPropertySet As PropertySet
NewPropertySet = propsets.Item("DevTech Property Set")
If (NewPropertySet Is Nothing) Then
MsgBox("Adding new property set : DevTech Property Set")
NewPropertySet = propsets.Add("DevTech Property Set")
End If
' adding the new property to the property set
Dim NewProperty As Inventor.Property
NewProperty = NewPropertySet.Item("DevTech Property")
If (NewProperty Is Nothing) Then
Dim value As String
Dim id As Integer
value = "1"
id = 15
NewPropertySet.Add(value, "DevTech Property", id)
Else
NewProperty.value = "2"
End If
' change the name of the new propertyset
propsets.Item("DevTech Property Set"). _
DisplayName = "New Property Set"
' change the value of the new property
propsets.Item("DevTech Property Set"). _
Item("DevTech Property").Value = "3"
' FlushToFile (only for Apprentice)
propsets.FlushToFile()
End Sub