Community
Inventor Programming - iLogic, Macros, AddIns & Apprentice
Inventor iLogic, Macros, AddIns & Apprentice Forum. Share your knowledge, ask questions, and explore popular Inventor topics related to programming, creating add-ins, macros, working with the API or creating iLogic tools.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Class Modules + 'Custom Event Triggers'

5 REPLIES 5
Reply
Message 1 of 6
MechMachineMan
1038 Views, 5 Replies

Class Modules + 'Custom Event Triggers'

MechMachineMan
Advisor
Advisor

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.


--------------------------------------
Did you find this reply helpful ? If so please use the 'Accept as Solution' or 'Like' button below.

Justin K
Inventor 2018.2.3, Build 227 | Excel 2013+ VBA
ERP/CAD Communication | Custom Scripting
Machine Design | Process Optimization


iLogic/Inventor API: Autodesk Online Help | API Shortcut In Google Chrome | iLogic API Documentation
Vb.Net/VBA Programming: MSDN | Stackoverflow | Excel Object Model
Inventor API/VBA/Vb.Net Learning Resources: Forum Thread

Sample Solutions:Debugging in iLogic ( and Batch PDF Export Sample ) | API HasSaveCopyAs Issues |
BOM Export & Column Reorder | Reorient Skewed Part | Add Internal Profile Dogbones |
Run iLogic From VBA | Batch File Renaming| Continuous Pick/Rename Objects

Local Help: %PUBLIC%\Documents\Autodesk\Inventor 2018\Local Help

Ideas: Dockable/Customizable Property Browser | Section Line API/Thread Feature in Assembly/PartsList API Static Cells | Fourth BOM Type
0 Likes

Class Modules + 'Custom Event Triggers'

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.


--------------------------------------
Did you find this reply helpful ? If so please use the 'Accept as Solution' or 'Like' button below.

Justin K
Inventor 2018.2.3, Build 227 | Excel 2013+ VBA
ERP/CAD Communication | Custom Scripting
Machine Design | Process Optimization


iLogic/Inventor API: Autodesk Online Help | API Shortcut In Google Chrome | iLogic API Documentation
Vb.Net/VBA Programming: MSDN | Stackoverflow | Excel Object Model
Inventor API/VBA/Vb.Net Learning Resources: Forum Thread

Sample Solutions:Debugging in iLogic ( and Batch PDF Export Sample ) | API HasSaveCopyAs Issues |
BOM Export & Column Reorder | Reorient Skewed Part | Add Internal Profile Dogbones |
Run iLogic From VBA | Batch File Renaming| Continuous Pick/Rename Objects

Local Help: %PUBLIC%\Documents\Autodesk\Inventor 2018\Local Help

Ideas: Dockable/Customizable Property Browser | Section Line API/Thread Feature in Assembly/PartsList API Static Cells | Fourth BOM Type
5 REPLIES 5
Message 2 of 6
Anonymous
in reply to: MechMachineMan

Anonymous
Not applicable

Might it be easier to use iLogic and set the trigger to on save?

0 Likes

Might it be easier to use iLogic and set the trigger to on save?

Message 3 of 6
MechMachineMan
in reply to: Anonymous

MechMachineMan
Advisor
Advisor
Definitely would be easier. But then you miss out on a world of
opportunities and functionality.

--------------------------------------
Did you find this reply helpful ? If so please use the 'Accept as Solution' or 'Like' button below.

Justin K
Inventor 2018.2.3, Build 227 | Excel 2013+ VBA
ERP/CAD Communication | Custom Scripting
Machine Design | Process Optimization


iLogic/Inventor API: Autodesk Online Help | API Shortcut In Google Chrome | iLogic API Documentation
Vb.Net/VBA Programming: MSDN | Stackoverflow | Excel Object Model
Inventor API/VBA/Vb.Net Learning Resources: Forum Thread

Sample Solutions:Debugging in iLogic ( and Batch PDF Export Sample ) | API HasSaveCopyAs Issues |
BOM Export & Column Reorder | Reorient Skewed Part | Add Internal Profile Dogbones |
Run iLogic From VBA | Batch File Renaming| Continuous Pick/Rename Objects

Local Help: %PUBLIC%\Documents\Autodesk\Inventor 2018\Local Help

Ideas: Dockable/Customizable Property Browser | Section Line API/Thread Feature in Assembly/PartsList API Static Cells | Fourth BOM Type
0 Likes

Definitely would be easier. But then you miss out on a world of
opportunities and functionality.

--------------------------------------
Did you find this reply helpful ? If so please use the 'Accept as Solution' or 'Like' button below.

Justin K
Inventor 2018.2.3, Build 227 | Excel 2013+ VBA
ERP/CAD Communication | Custom Scripting
Machine Design | Process Optimization


iLogic/Inventor API: Autodesk Online Help | API Shortcut In Google Chrome | iLogic API Documentation
Vb.Net/VBA Programming: MSDN | Stackoverflow | Excel Object Model
Inventor API/VBA/Vb.Net Learning Resources: Forum Thread

Sample Solutions:Debugging in iLogic ( and Batch PDF Export Sample ) | API HasSaveCopyAs Issues |
BOM Export & Column Reorder | Reorient Skewed Part | Add Internal Profile Dogbones |
Run iLogic From VBA | Batch File Renaming| Continuous Pick/Rename Objects

Local Help: %PUBLIC%\Documents\Autodesk\Inventor 2018\Local Help

Ideas: Dockable/Customizable Property Browser | Section Line API/Thread Feature in Assembly/PartsList API Static Cells | Fourth BOM Type
Message 4 of 6
Jef_E
in reply to: MechMachineMan

Jef_E
Collaborator
Collaborator

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


Please kudo if this post was helpfull
Please accept as solution if your problem was solved

Inventor 2014 SP2
0 Likes

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


Please kudo if this post was helpfull
Please accept as solution if your problem was solved

Inventor 2014 SP2
Message 5 of 6

SometimesInventorMakesMeAngry
Advocate
Advocate

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.

0 Likes

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.

Message 6 of 6

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

0 Likes

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.

Post to forums  

Autodesk Design & Make Report