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?
Solved! Go to Solution.
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?
Solved! Go to Solution.
Solved by WCrihfield. Go to 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
(Not an Autodesk Employee)
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
(Not an Autodesk Employee)
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 !
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 !
I assume this would only work from an Add-in, correct?
I assume this would only work from an Add-in, correct?
This is kind of what I was expecting. Thanks!
This is kind of what I was expecting. Thanks!
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 !
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.
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.
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.
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.