Hi again.
Sorry for the delay, but I have been ridiculously busy and have also had to make some changes to the code.
I wasn't able to get that code to work, unfortunately. I also decided it would be simpler to just get to code to run an existing iLogic rule, so I altered it to just run my iLogic rule instead:
Code Module:
'This is the Code Module!
Dim oEvents2 As cEvents2 'make sure "cEvents2" here matches your class module name!
Public Sub RevisionChangeEvents()
Set oEvents2 = New cEvents2 'make sure "cEvents2" here matches your class module name!
End Sub
-Code module as before, I have just used oEvents2/cEvents2 as cEvents2 is what I named my edited class code.
Class Module Code:
Private WithEvents oAppEvents As ApplicationEvents
Private WithEvents oDocEvents As DocumentEvents
Private Sub Class_Initialize()
Set oAppEvents = ThisApplication.ApplicationEvents
Set oDocEvents = ThisApplication.ActiveDocument.DocumentEvents
End Sub
Private Sub oAppEvents_OnActivateDocument(ByVal DocumentObject As Document, ByVal BeforeOrAfter As EventTimingEnum, ByVal Context As NameValueMap, HandlingCode As HandlingCodeEnum)
If BeforeOrAfter = kAfter Then
If DocumentObject.DocumentType = kDrawingDocumentObject Then
Set oDocEvents = ThisApplication.ActiveDocument.DocumentEvents
Else
Set oDocEvents = Nothing
End If
End If
End Sub
Private Sub oDocEvents_OnChange(ByVal ReasonsForChange As CommandTypesEnum, ByVal BeforeOrAfter As EventTimingEnum, ByVal Context As NameValueMap, HandlingCode As HandlingCodeEnum)
If BeforeOrAfter = kAfter Then
RuniLogic "Revision"
'If (ReasonsForChange And kFilePropertyEditCmdType) = kFilePropertyEditCmdType Then
'RuniLogic "Revision"
quit:
End If
End If
End Sub
Public Sub LaunchRevisionClass() '<--- This is what you would tie to a button in a toolbar.
RuniLogic "Revision"
End Sub
'Public Sub LaunchMyRule2() '<--- This is what you would tie to a button in a toolbar.
' RuniLogic "MyRule2"
'End Sub
Public Sub RuniLogic(ByVal RuleName As String)
Dim iLogicAuto As Object
Dim oDoc As Document
Set oDoc = ThisApplication.ActiveDocument
If oDoc Is Nothing Then
MsgBox "Missing Inventor Document"
Exit Sub
End If
Set iLogicAuto = GetiLogicAddin(ThisApplication)
If (iLogicAuto Is Nothing) Then Exit Sub
iLogicAuto.RunRule oDoc, RuleName
End Sub
Function GetiLogicAddin(oApplication As Inventor.Application) As Object
Set addIns = oApplication.ApplicationAddIns
'Find the add-in you are looking for
Dim addIn As ApplicationAddIn
On Error GoTo NotFound
Set addIn = oApplication.ApplicationAddIns.ItemById("{3bdd8d79-2179-4b11-8a5a-257b1c0263ac}")
If (addIn Is Nothing) Then Exit Function
addIn.Activate
Set GetiLogicAddin = addIn.Automation
Exit Function
NotFound:
End Function
-Class module runs my iLogic rule
The problem I now have is that as you said, the rule will run whenever there is any change in the document. This is a bit inconvenient since I would like to run a few additional rules, one of which activates each sheet in turn and adds a revision table (and deleting any existing ones). I don't want this to happen unless the revision has changed.
Is there any way to have the code trigger only when the revision is changed?
Thanks!
P.S. I still don't know why I wasn't able to get the other code to work, but this seems to work fine, other than that it triggers too often.