Hi there, hoping some help with some more programmeresq stuff.
I'm currently reading a book on excel vba and it goes over how you can create custom event handling for the application by using a class module and initializing that within a module, so I'm trying that here, but its giving me an error.
Here is what I have put in for code so far:
Class Module Named clsAppEvents:
Public WithEvents invApp As Inventor Private Sub invApp_OnSaveDocument(ByVal DocumentObject As Document, ByVal BeforeOrAfter As EventTimingEnum, ByVal Context As NameValueMap, HandlingCode As HandlingCodeEnum) MsgBox ("Document Was Saved!") End Sub
Module named EventModule:
Public myAppEvent As New clsAppEvents Sub TrapAppEvent() Set myAppEvent.invApp = ThisApplication End Sub
However, trying to run the trap events macro causes a:
Comple Error: Object does not source automation events.
Is there any way to make this sort of thing work in inventor?
Ideally I want to avoid creating a full macro, but be able to use my vba project to program in a check on file save to remind the user to update a spreadsheet we have.
Hi there, hoping some help with some more programmeresq stuff.
I'm currently reading a book on excel vba and it goes over how you can create custom event handling for the application by using a class module and initializing that within a module, so I'm trying that here, but its giving me an error.
Here is what I have put in for code so far:
Class Module Named clsAppEvents:
Public WithEvents invApp As Inventor Private Sub invApp_OnSaveDocument(ByVal DocumentObject As Document, ByVal BeforeOrAfter As EventTimingEnum, ByVal Context As NameValueMap, HandlingCode As HandlingCodeEnum) MsgBox ("Document Was Saved!") End Sub
Module named EventModule:
Public myAppEvent As New clsAppEvents Sub TrapAppEvent() Set myAppEvent.invApp = ThisApplication End Sub
However, trying to run the trap events macro causes a:
Comple Error: Object does not source automation events.
Is there any way to make this sort of thing work in inventor?
Ideally I want to avoid creating a full macro, but be able to use my vba project to program in a check on file save to remind the user to update a spreadsheet we have.
Might it be easier to use iLogic and set the trigger to on save?
Might it be easier to use iLogic and set the trigger to on save?
I use this in visual studio, hope it helps!
' Application Events object. Private m_AppEvents As ApplicationEvents Public Sub Activate(ByVal addInSiteObject As Inventor.ApplicationAddInSite, ByVal firstTime As Boolean) Implements Inventor.ApplicationAddInServer.Activate ' This method is called by Inventor when it loads the AddIn. ' The AddInSiteObject provides access to the Inventor Application object. ' The FirstTime flag indicates if the AddIn is loaded for the first time. ' Initialize AddIn members. m_inventorApplication = addInSiteObject.Application ' TODO: Add ApplicationAddInServer.Activate implementation. ' e.g. event initialization, command creation etc. oAppEvents = m_inventorApplication.ApplicationEvents End Sub Private Sub OnActivateDocument(ByVal DocumentObject As Inventor._Document, ByVal BeforeOrAfter As Inventor.EventTimingEnum, ByVal Context As Inventor.NameValueMap, ByRef HandlingCode As Inventor.HandlingCodeEnum) _ Handles oAppEvents.OnActivateDocument ' Check if the timining is after the document is activated. If BeforeOrAfter = EventTimingEnum.kAfter Then DDC.GetCurrentDocumentDescription() End If End Sub
I use this in visual studio, hope it helps!
' Application Events object. Private m_AppEvents As ApplicationEvents Public Sub Activate(ByVal addInSiteObject As Inventor.ApplicationAddInSite, ByVal firstTime As Boolean) Implements Inventor.ApplicationAddInServer.Activate ' This method is called by Inventor when it loads the AddIn. ' The AddInSiteObject provides access to the Inventor Application object. ' The FirstTime flag indicates if the AddIn is loaded for the first time. ' Initialize AddIn members. m_inventorApplication = addInSiteObject.Application ' TODO: Add ApplicationAddInServer.Activate implementation. ' e.g. event initialization, command creation etc. oAppEvents = m_inventorApplication.ApplicationEvents End Sub Private Sub OnActivateDocument(ByVal DocumentObject As Inventor._Document, ByVal BeforeOrAfter As Inventor.EventTimingEnum, ByVal Context As Inventor.NameValueMap, ByRef HandlingCode As Inventor.HandlingCodeEnum) _ Handles oAppEvents.OnActivateDocument ' Check if the timining is after the document is activated. If BeforeOrAfter = EventTimingEnum.kAfter Then DDC.GetCurrentDocumentDescription() End If End Sub
I believe you should replace
Set myAppEvent.invApp = ThisApplication
with
Set myAppEvent.invApp = ThisApplication.ApplicationEvents
I know it's been years since this was posted, but maybe it'll help someone searching for this.
I believe you should replace
Set myAppEvent.invApp = ThisApplication
with
Set myAppEvent.invApp = ThisApplication.ApplicationEvents
I know it's been years since this was posted, but maybe it'll help someone searching for this.
you need to initialize your class
Dim WithEvents oAppEvents As ApplicationEvents
Private Sub Class_Initialize()
Dim invapp As Inventor.Application
set invapp = ThisApplication
Set oAppEvents = invapp.ApplicationEvents
End Sub
Private Sub oAppEvents_OnSaveDocument(DocumentObject As Document, BeforeOrAfter As EventTimingEnum, Context As NameValueMap, ByRef HandlingCode As HandlingCodeEnum)
If BeforeOrAfter = kBefore Then
MsgBox "your are about to save " & DocumentObject.DisplayName & " !!!"
End If
HandlingCode = kEventNotHandled 'tell Inventor to handle the events like it usually does
End Sub
After that, you simply need to generate an instance of your class module for the event to subscribe
you need to initialize your class
Dim WithEvents oAppEvents As ApplicationEvents
Private Sub Class_Initialize()
Dim invapp As Inventor.Application
set invapp = ThisApplication
Set oAppEvents = invapp.ApplicationEvents
End Sub
Private Sub oAppEvents_OnSaveDocument(DocumentObject As Document, BeforeOrAfter As EventTimingEnum, Context As NameValueMap, ByRef HandlingCode As HandlingCodeEnum)
If BeforeOrAfter = kBefore Then
MsgBox "your are about to save " & DocumentObject.DisplayName & " !!!"
End If
HandlingCode = kEventNotHandled 'tell Inventor to handle the events like it usually does
End Sub
After that, you simply need to generate an instance of your class module for the event to subscribe
Can't find what you're looking for? Ask the community or share your knowledge.