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: 

Activate Event Listener on Startup

7 REPLIES 7
SOLVED
Reply
Message 1 of 8
SometimesInventorMakesMeAngry
878 Views, 7 Replies

Activate Event Listener on Startup

SometimesInventorMakesMeAngry
Advocate
Advocate

I have some VBA event listener classes that I'd like to keep activated at all times. Unfortunately, when Inventor is closed or crashes, these classes are disactivated, so I have to manually activate them every time Inventor starts.

 

I imagine this is intentional to prevent some Inventor-breaking script to keep running forever, but the scripts I wrote have no such problems. Is there a way to keep these listeners active across Inventor sessions or activate them on startup? 

0 Likes

Activate Event Listener on Startup

I have some VBA event listener classes that I'd like to keep activated at all times. Unfortunately, when Inventor is closed or crashes, these classes are disactivated, so I have to manually activate them every time Inventor starts.

 

I imagine this is intentional to prevent some Inventor-breaking script to keep running forever, but the scripts I wrote have no such problems. Is there a way to keep these listeners active across Inventor sessions or activate them on startup? 

Tags (1)
Labels (1)
7 REPLIES 7
Message 2 of 8

WCrihfield
Mentor
Mentor
Accepted solution

You would need to create a standalone application to have something remain active when Inventor closes or crashes, then restarts.  You would likely need to create an Autodesk Addin for it to start automatically when Inventor starts.  Simple VBA macro's won't handle that sort of behavior by themselves, without the help of something with a higher level of access, independent of Inventor.

 

If this solved your problem, or answered your question, please click ACCEPT SOLUTION.
Or, if this helped you, please click 'LIKE' 👍.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes

You would need to create a standalone application to have something remain active when Inventor closes or crashes, then restarts.  You would likely need to create an Autodesk Addin for it to start automatically when Inventor starts.  Simple VBA macro's won't handle that sort of behavior by themselves, without the help of something with a higher level of access, independent of Inventor.

 

If this solved your problem, or answered your question, please click ACCEPT SOLUTION.
Or, if this helped you, please click 'LIKE' 👍.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 3 of 8

bradeneuropeArthur
Mentor
Mentor

you could create a new class if the Inventor Application is closed.

Check if the inventor session is running every 1 minute with getobject and createobject.

If not create it new with Create Object!

Regards,

Arthur Knoors

Autodesk Affiliations:

Autodesk Software:Inventor Professional 2024 | Vault Professional 2022 | Autocad Mechanical 2022
Programming Skills:Vba | Vb.net (Add ins Vault / Inventor, Applications) | I-logic
Programming Examples:Drawing List!|Toggle Drawing Sheet!|Workplane Resize!|Drawing View Locker!|Multi Sheet to Mono Sheet!|Drawing Weld Symbols!|Drawing View Label Align!|Open From Balloon!|Model State Lock!
Posts and Ideas:Dimension Component!|Partlist Export!|Derive I-properties!|Vault Prompts Via API!|Vault Handbook/Manual!|Drawing Toggle Sheets!|Vault Defer Update!


! For administrative reasons, please mark a "Solution as solved" when the issue is solved !

0 Likes

you could create a new class if the Inventor Application is closed.

Check if the inventor session is running every 1 minute with getobject and createobject.

If not create it new with Create Object!

Regards,

Arthur Knoors

Autodesk Affiliations:

Autodesk Software:Inventor Professional 2024 | Vault Professional 2022 | Autocad Mechanical 2022
Programming Skills:Vba | Vb.net (Add ins Vault / Inventor, Applications) | I-logic
Programming Examples:Drawing List!|Toggle Drawing Sheet!|Workplane Resize!|Drawing View Locker!|Multi Sheet to Mono Sheet!|Drawing Weld Symbols!|Drawing View Label Align!|Open From Balloon!|Model State Lock!
Posts and Ideas:Dimension Component!|Partlist Export!|Derive I-properties!|Vault Prompts Via API!|Vault Handbook/Manual!|Drawing Toggle Sheets!|Vault Defer Update!


! For administrative reasons, please mark a "Solution as solved" when the issue is solved !

Message 4 of 8

I assume this would only work from an Add-in, correct?

0 Likes

I assume this would only work from an Add-in, correct?

Message 5 of 8

This is kind of what I was expecting. Thanks!

0 Likes

This is kind of what I was expecting. Thanks!

Message 6 of 8

You also can start Inventor with a standalone app.

An add in would also help on this but that was not your question!

Regards,

Arthur Knoors

Autodesk Affiliations:

Autodesk Software:Inventor Professional 2024 | Vault Professional 2022 | Autocad Mechanical 2022
Programming Skills:Vba | Vb.net (Add ins Vault / Inventor, Applications) | I-logic
Programming Examples:Drawing List!|Toggle Drawing Sheet!|Workplane Resize!|Drawing View Locker!|Multi Sheet to Mono Sheet!|Drawing Weld Symbols!|Drawing View Label Align!|Open From Balloon!|Model State Lock!
Posts and Ideas:Dimension Component!|Partlist Export!|Derive I-properties!|Vault Prompts Via API!|Vault Handbook/Manual!|Drawing Toggle Sheets!|Vault Defer Update!


! For administrative reasons, please mark a "Solution as solved" when the issue is solved !

You also can start Inventor with a standalone app.

An add in would also help on this but that was not your question!

Regards,

Arthur Knoors

Autodesk Affiliations:

Autodesk Software:Inventor Professional 2024 | Vault Professional 2022 | Autocad Mechanical 2022
Programming Skills:Vba | Vb.net (Add ins Vault / Inventor, Applications) | I-logic
Programming Examples:Drawing List!|Toggle Drawing Sheet!|Workplane Resize!|Drawing View Locker!|Multi Sheet to Mono Sheet!|Drawing Weld Symbols!|Drawing View Label Align!|Open From Balloon!|Model State Lock!
Posts and Ideas:Dimension Component!|Partlist Export!|Derive I-properties!|Vault Prompts Via API!|Vault Handbook/Manual!|Drawing Toggle Sheets!|Vault Defer Update!


! For administrative reasons, please mark a "Solution as solved" when the issue is solved !

Message 7 of 8

Can you explain a little bit more about this method, please? I've made a few apps that get the Inventor App object via Marshal, but I'm having trouble with this event handler implementation.

 

I basically copied Brian/Adam's post here, but I can't seem to make it work. It looks to me like they're writing for an Add-in, so I am not implementing the ApplicationAddInServer interface and my Activate method does not have parameters. Is there something else I need to do like place the .dll in a specific place for this to work? I've never had to do that for any app before.

0 Likes

Can you explain a little bit more about this method, please? I've made a few apps that get the Inventor App object via Marshal, but I'm having trouble with this event handler implementation.

 

I basically copied Brian/Adam's post here, but I can't seem to make it work. It looks to me like they're writing for an Add-in, so I am not implementing the ApplicationAddInServer interface and my Activate method does not have parameters. Is there something else I need to do like place the .dll in a specific place for this to work? I've never had to do that for any app before.

Message 8 of 8

If anyone else is wondering about this, you can do something like

    using System.Windows.Forms;
    public static void Main()
    {
        ApplicationEvents appEvents = InventorApp.ApplicationEvents;
        appEvents.OnSaveDocument += 
            new ApplicationEventsSink_OnSaveDocumentEventHandler(AppEvents_OnSaveDocument);
        MessageBox.Show("ok");
    }

and then your handler can have the following format:

    private static void AppEvents_OnSaveDocument(_Document DocumentObject, 
                                                    EventTimingEnum BeforeOrAfter, 
                                                    NameValueMap Context, 
                                                    out HandlingCodeEnum HandlingCode)
    {
        HandlingCode = HandlingCodeEnum.kEventNotHandled;
        if(BeforeOrAfter == EventTimingEnum.kBefore)
        { 
            System.Windows.Forms.MessageBox.Show("It worked!");
            System.Console.WriteLine(InventorApp.ActiveDocument.DisplayName);
        }
    }

 I used a messagebox in Main to keep the process active. Otherwise, execution stops after you subscribe to the event and your handler never runs. I tried while(true), but that was way too resource intensive. If someone has a better way of doing this, please let me know.

0 Likes

If anyone else is wondering about this, you can do something like

    using System.Windows.Forms;
    public static void Main()
    {
        ApplicationEvents appEvents = InventorApp.ApplicationEvents;
        appEvents.OnSaveDocument += 
            new ApplicationEventsSink_OnSaveDocumentEventHandler(AppEvents_OnSaveDocument);
        MessageBox.Show("ok");
    }

and then your handler can have the following format:

    private static void AppEvents_OnSaveDocument(_Document DocumentObject, 
                                                    EventTimingEnum BeforeOrAfter, 
                                                    NameValueMap Context, 
                                                    out HandlingCodeEnum HandlingCode)
    {
        HandlingCode = HandlingCodeEnum.kEventNotHandled;
        if(BeforeOrAfter == EventTimingEnum.kBefore)
        { 
            System.Windows.Forms.MessageBox.Show("It worked!");
            System.Console.WriteLine(InventorApp.ActiveDocument.DisplayName);
        }
    }

 I used a messagebox in Main to keep the process active. Otherwise, execution stops after you subscribe to the event and your handler never runs. I tried while(true), but that was way too resource intensive. If someone has a better way of doing this, please let me know.

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report