There are three different mechanisms that allow you to store information in a file that is not directly accessible by the end user.
1. iProperties
2. Attribute
3. IStorage & IStream
The first of these and probably the simplest to use are document properties. iProperties is at document level for all kinds of document. There are the standard properties that are visible to the user through the iProperties command (dialog), but you can also create your own property sets and properties. These are not visible through Inventor's user interface.
Many materials are available for iProperties. I’d recommend one blog and one video course.
Access IProperty
Introductory Inventor API_Module 2 - Document
iProperties is accessible (read/write) by Inventor API or Apprentice.Following is a small sample which adds a custom property set with some properties. It also shows how to read the information.
VBA
Sub AddCustomProperty()
' open a document invisble
Dim oDoc As Document
Set oDoc = ThisApplication.Documents.Open("c:\testpart.ipt", False)
' name of new property set
Dim oNameOfNewPS As String
oNameOfNewPS = "myNewSet"
' new property set
Dim oNewPS As PropertySet
If oDoc.PropertySets.PropertySetExists("myNewSet") Then
' if the set exists aleady
Set oNewPS = oDoc.PropertySets("myNewSet")
' you can clean up the existing properties
Else
' add a new one with a GUID
Set oNewPS = oDoc.PropertySets.Add("myNewSet",
"{3FDB7763-80DB-4269-83E4-7F43BC8E9EA7}")
End If
'the values of the properties
Dim oIntProV As Integer
oIntProV = 100
Dim oBoolProV As Boolean
oBoolProV = False
Dim oDoubleProV As Double
oDoubleProV = 3.1415926
Dim oDateProV As Date
oDateProV = "2013-3-1 15:25"
' add these properties with the meaningful name
' assume they do not exist in the property set
Call oNewPS.Add(oIntProV, "ModelCount")
Call oNewPS.Add(oBoolProV, "ModelUpdateToDate")
Call oNewPS.Add(oDoubleProV, "ModelBasicLength")
Call oNewPS.Add(oDateProV, "ModelUpdateDate")
oDoc.Save
oDoc.Close
End Sub
Sub ReadCustomProperty()
' open a document invisble
Dim oDoc As Document
Set oDoc = ThisApplication.Documents.Open("c:\testpart.ipt", False)
' name of new property set
Dim oNameOfNewPS As String
oNameOfNewPS = "myNewSet"
' new property set
Dim oNewPS As PropertySet
If oDoc.PropertySets.PropertySetExists("myNewSet") Then
' if the set exists aleady
Set oNewPS = oDoc.PropertySets("myNewSet")
' you can clean up the existing properties
Else
MsgBox "no property named myNewSet"
Exit Sub
End If
Dim oShowStr As String
oShowStr = ""
'iterate the properties
Dim oEachP As Property
For Each oEachP In oNewPS
oShowStr = oShowStr & " [Property Name] " & oEachP.Name
oShowStr = oShowStr & " [Property Value] " & oEachP.Value & vbCr
Next
MsgBox oShowStr
oDoc.Close
End Sub
VB.NET
Sub AddCustomProperty()
Dim m_inventorApp As Inventor.Application = Nothing
m_inventorApp = System.Runtime.InteropServices.Marshal.GetActiveObject("Inventor.Application")
' open a document invisble
Dim oDoc As Document
oDoc = m_inventorApp.Documents.Open("c:\testpart.ipt", False)
' name of new property set
Dim oNameOfNewPS As String
oNameOfNewPS = "myNewSet"
' new property set
Dim oNewPS As PropertySet
If oDoc.PropertySets.PropertySetExists("myNewSet") Then
' if the set exists aleady
oNewPS = oDoc.PropertySets("myNewSet")
' you can clean up the existing properties
Else
' add a new one with a GUID
oNewPS = oDoc.PropertySets.Add("myNewSet",
"{3FDB7763-80DB-4269-83E4-7F43BC8E9EA7}")
End If
'the values of the properties
Dim oIntProV As Integer
oIntProV = 100
Dim oBoolProV As Boolean
oBoolProV = False
Dim oDoubleProV As Double
oDoubleProV = 3.1415926000000001
Dim oDateProV As Date
oDateProV = "2013-3-1 15:25"
' add these properties with the meaningful name
' assume they do not exist in the property set
oNewPS.Add(oIntProV, "ModelCount")
oNewPS.Add(oBoolProV, "ModelUpdateToDate")
oNewPS.Add(oDoubleProV, "ModelBasicLength")
oNewPS.Add(oDateProV, "ModelUpdateDate")
oDoc.Save()
oDoc.Close()
End Sub
Sub ReadCustomProperty()
Dim m_inventorApp As
Inventor.Application = Nothing
m_inventorApp = System.Runtime.InteropServices.Marshal.
GetActiveObject("Inventor.Application")
' open a document invisble
Dim oDoc As Document
oDoc = m_inventorApp.Documents.Open("c:\testpart.ipt", False)
' name of new property set
Dim oNameOfNewPS As String
oNameOfNewPS = "myNewSet"
' new property set
Dim oNewPS As PropertySet = Nothing
If oDoc.PropertySets.PropertySetExists("myNewSet") Then
' if the set exists aleady
oNewPS = oDoc.PropertySets("myNewSet")
' you can clean up the existing properties
Else
MsgBox("no property named myNewSet")
Exit Sub
End If
Dim oShowStr As String
oShowStr = ""
'iterate the properties
Dim oEachP As [Property]
For Each oEachP In oNewPS
oShowStr &= " [Property Name] " &
oEachP.Name
oShowStr &= " [Property Value] " &
oEachP.Value & vbCr
Next
MessageBox.Show(oShowStr)
oDoc.Close()
End Sub
Apprentice
Sub AddCustomProperty_Apprentice()
Dim m_ApprenticeApp As Inventor.ApprenticeServerComponent =
New Inventor.ApprenticeServerComponent()
' open a document
Dim oDoc As ApprenticeServerDocument
oDoc = m_ApprenticeApp.Open("c:\testpart.ipt")
' name of new property set
Dim oNameOfNewPS As String
oNameOfNewPS = "myNewSet"
' new property set
Dim oNewPS As PropertySet
If oDoc.PropertySets.PropertySetExists("myNewSet") Then
' if the set exists aleady
oNewPS = oDoc.PropertySets("myNewSet")
' you can clean up the existing properties
Else
' add a new one with a GUID
oNewPS = oDoc.PropertySets.Add("myNewSet",
"{3FDB7763-80DB-4269-83E4-7F43BC8E9EA7}")
End If
'the values of the properties
Dim oIntProV As Integer
oIntProV = 100
Dim oBoolProV As Boolean
oBoolProV = False
Dim oDoubleProV As Double
oDoubleProV = 3.1415926000000001
Dim oDateProV As Date
oDateProV = "2013-3-1 15:25"
' add these properties with the meaningful name
' assume they do not exist in the property set
oNewPS.Add(oIntProV, "ModelCount")
oNewPS.Add(oBoolProV, "ModelUpdateToDate")
oNewPS.Add(oDoubleProV, "ModelBasicLength")
oNewPS.Add(oDateProV, "ModelUpdateDate")
' flush the modification. Apprentice requires
oDoc.PropertySets.FlushToFile()
m_ApprenticeApp.FileSaveAs.AddFileToSave(oDoc, oDoc.FullDocumentName)
m_ApprenticeApp.FileSaveAs.ExecuteSave()
End Sub
Sub ReadCustomProperty_Apprentice()
Dim m_ApprenticeApp As Inventor.ApprenticeServerComponent =
New Inventor.ApprenticeServerComponent()
' open a document invisble
' open a document
Dim oDoc As ApprenticeServerDocument
oDoc = m_ApprenticeApp.Open("c:\testpart.ipt")
' name of new property set
Dim oNameOfNewPS As String
oNameOfNewPS = "myNewSet"
' new property set
Dim oNewPS As PropertySet = Nothing
If oDoc.PropertySets.PropertySetExists("myNewSet") Then
' if the set exists aleady
oNewPS = oDoc.PropertySets("myNewSet")
' you can clean up the existing properties
Else
MsgBox("no property named myNewSet")
Exit Sub
End If
Dim oShowStr As String
oShowStr = ""
'iterate the properties
Dim oEachP As [Property]
For Each oEachP In oNewPS
oShowStr &= " [Property Name] " &
oEachP.Name
oShowStr &= " [Property Value] " &
oEachP.Value & vbCr
Next
MessageBox.Show(oShowStr)
oDoc.Close()
End Sub
In the next post, we will introduce the second way: Attribute.