Here is the code from one of the external iLogic rules I have used in the past, that is to be initiated from the active drawing document, and compares the Title and Description iProperty values from both the Drawing and the Model files, and if there is any differences, it notifies you and asks you what you want to do about it.
And there are 3 pre-defined options to choose from.
- Copy the value from the drawing back to the model
- Copy the value from the model to the drawing
- Or do nothing (in-case you might want to leave it that way, for some reason.
I think your problems may be stemming from how you are retrieving the iProperty values. Any time you use iProperty.Value(oPropertySet, oProperty) you are getting that property from the active document (the document that was active when you started the rule). There is an alternative way of using that line to retrieve iProperty values from components within an active assembly, by including the component as the first of three input variables within the (), but in general, when you want to access the iProperties of other documents, you should always go through the oOtherDoc.PropertySets.PropertySet.Property.Value = .
If ThisApplication.ActiveDocumentType <> DocumentTypeEnum.kDrawingDocumentObject Then
MessageBox.Show("The Rule named '" & iLogicVb.RuleName & "' attempted to run." & vbCrLf &
"However, it was terminated because the 'Active Document' is the wrong type fot it to work with." & vbCrLf &
"It only works for DRAWING DOCUMENTS.", "WRONG DOCUMENT TYPE",MessageBoxButtons.OK, MessageBoxIcon.Error)
Return
End If
Dim oMDoc As Document = ThisDrawing.ModelDocument
If oMDoc Is Nothing Then
Return
End If
Dim oDtoM As String = "COPY IT FROM DRAWING TO MODEL"
Dim oMtoD As String = "COPY IT FROM MODEL TO DRAWING"
Dim oDN As String = "DO NOTHING"
Dim oWhatToDo As New ArrayList
oWhatToDo.Add(oDtoM)
oWhatToDo.Add(oMtoD)
oWhatToDo.Add(oDN)
Dim oPropSets As PropertySets = oMDoc.PropertySets
'[ Compare Titles
Dim oInvSumInfo As PropertySet = oPropSets.Item("Inventor Summary Information")
Dim oModelTitle As String = oInvSumInfo.Item("Title").Value.ToString
Dim oDrawingTitle As String = iProperties.Value("Summary", "Title").ToString
If oModelTitle = oDrawingTitle Then
GoTo Description
ElseIf oModelTitle <> oDrawingTitle Then
oTitleAns = InputListBox("This Drawing's 'Title' doesn't match the referenced Model File's 'Title'." & vbNewLine &
"What do you want to do? ", oWhatToDo, oWhatToDo.Item(1), "TITLES DON'T MATCH", "OPTIONS")
If oTitleAns = "" Then
GoTo Description
ElseIf oTitleAns = oDtoM Then
oModelTitle = oDrawingTitle
oMDoc.Save
ElseIf oTitleAns = oMtoD Then
oDrawingTitle = oModelTitle
ElseIf oTitleAns = oDN Then
GoTo Description
End If
End If
']
Description :
'[ Compare Descriptions
Dim oDesTracProps As PropertySet = oPropSets.Item("Design Tracking Properties")
Dim oModelDesc As String = oInvSumInfo.Item("Description").Value.ToString
Dim oDrawingDesc As String = iProperties.Value("Project", "Description").ToString
If oModelDesc = oDrawingDesc Then
Return
ElseIf oModelDesc <> oDrawingDesc Then
oDescAns = InputListBox("This Drawing's 'Description' doesn't match the referenced Model File's 'Description'." & vbNewLine &
"What do you want to do?", oWhatToDo, oWhatToDo.Item(1), Title := "DESCRIPTIONS DON'T MATCH", ListName := "OPTIONS")
If oDescAns = "" Then
Return
ElseIf oDescAns = oDtoM Then
oModelDesc = oDrawingDesc
oMDoc.Save
ElseIf oDescAns = oMtoD Then
oDrawingDesc = oModelDesc
ElseIf oDescAns = oDN Then
Return
End If
End If
']
InventorVb.DocumentUpdate()
Wesley Crihfield

(Not an Autodesk Employee)