Oops, sorry about that. I gave that a quick test and thought it worked, but I was wrong.
I don't think there's a concise, built-in function for getting an iProperty for a given document, like we can for an occurrence. However, you could certainly write one.
The following class should behave pretty much exactly like the iProperties.Value function, except it accepts a Document object rather than an occurrence name:
Class iProperties2
Public Shared Property Value(Doc As Inventor.Document,setName As String,propertyName As String) As Object
Get
Return Prop(Doc,setName,propertyName,Nothing).Value
End Get
Set(Value As Object)
Dim oProp As Inventor.Property = Prop(Doc,setName,propertyName,Value)
If oProp IsNot Nothing Then oProp.Value = Value
End Set
End Property
Private Shared Function Prop(Doc As Inventor.Document,setName As String,propertyName As String,MissingSetVal As Object) As Inventor.Property
If setName = "Custom" Then
Try
Return Doc.PropertySets("Inventor User Defined Properties")(propertyName)
Catch
If MissingSetVal Is Nothing Then
Return Doc.PropertySets("Inventor User Defined Properties").Add("",propertyName)
Else
Doc.PropertySets("Inventor User Defined Properties").Add(MissingSetVal,propertyName)
Return Nothing
End If
End Try
Else
Try
Return Doc.PropertySets("Design Tracking Properties")(propertyName)
Catch
Try
Return Doc.PropertySets("Inventor Summary Information")(propertyName)
Catch
Return Doc.PropertySets("Inventor Document Summary Information")(propertyName)
End Try
End Try
End If
End Function
End Class
You can use it exactly like the original iProperties.Value method, but with a Document input:
iProperties2.Value(oDoc,"Project","Part Number") = "xxx"
MsgBox(iProperties2.Value(oDoc,"Custom","MyProp"))
I know it's annoying to have to add such a long function to the end of your code, but I don't know of a better solution. It takes several lines of code to get an iProperty, make sure it exists, handle if it doesn't exist, etc. You can have all that junk in the body of your code, every time you get or set an iProperty, or you can use a bulky function like this one. For most situations, the function is better.