Here is another example iLogic code starter, where I have implemented both of those options mentioned above. It first captures the current document do a generic Document type variable using the ThisDoc.Document phrase. Then if it is already a drawing, it will set that document reference as the value of a DrawingDocument type variable, so we have access to all the methods & properties of the drawing. If the active document is not a drawing, it then tries to get the full file name of the drawing. I am using two lines of code there that assume that the drawing is saved in the same path as the current document, and has the same file name as the current document, but has the different file extension. If that is not the case, that part can be changed as needed. I did notice that you seem to be using Vault, so you may simply need to substitute in the vault path, as in your first couple posts. Once it has a full file name for the drawing, it first checks to see if it is already open in the background, and if so, gets that document reference to the DrawingDocument type variable. If not found there, it then tries to open the drawing in a not visible way. If either of those worked to set the value of the DrawingDocument type variable, it then moves on to access the custom iProperties of that drawing. I am showing the Inventor API route of doing that part. I first get the PropertySet for the 'custom' iProperties. This can be done in a few different ways (by name, internal name, or Index number). Then I create a variable for an Inventor Property type object, with no value set to it yet. Then I use a Try...Catch block of code to avoid getting an error when I try to access a custom iProperty that may not already exist (if checking or changing a value). If getting the existing property fails, the Catch part runs, and will either notify the user that the property could not be found, or creates the custom iProperty.
Dim oDoc As Document = ThisDoc.Document
Dim oDrawDoc As Document = Nothing
If oDoc.DocumentType = DocumentTypeEnum.kDrawingDocumentObject Then
oDrawDoc = oDoc
Else
'these next two lines assume the drawing has same path & file name as model, except extension
Dim sDrawingFile As String = ThisDoc.PathAndFileName(False) & ".idw"
'Dim sDrawingFile As String = System.IO.Path.ChangeExtension(oDoc.FullFileName, ".idw")
If System.IO.File.Exists(sDrawingFile) = False Then Exit Sub 'exit rule, the file does not exist
For Each oOpenDoc As Document In ThisApplication.Documents
If oOpenDoc.FullFileName = sDrawingFile Then
oDrawDoc = oOpenDoc
End If
Next
If oDrawDoc Is Nothing Then
oDrawDoc = ThisApplication.Documents.Open(sDrawingFile, False) 'False = not visible
End If
End If
If oDrawDoc Is Nothing Then Exit Sub 'exit rule because no drawing could be found
Dim oCustomPropSet As Inventor.PropertySet = oDrawDoc.PropertySets.Item("Inventor User Defined Properties")
'or oDrawDoc.PropertySets.Item(4) 'the 'custom' set is always the fourth set
Dim oCustomProp As Inventor.Property = Nothing
'if you try to get a custom property by name, and it is not found, it will throw an error
'use Try...Catch...End Try block to avoid the error, and let rule keep running, if needed
Try
oCustomProp = oCustomPropSet.Item("Custom Property Name")
Catch
'it was not found, so what to do now (create it, or let user know it was not found)
'MsgBox("Custom Property Was Not Found", vbCritical, "Property Not Found")
oCustomProp = oCustomPropSet.Add("Custom Property Value", "Custom Property Name")
End Try
Wesley Crihfield

(Not an Autodesk Employee)