VB.net Addin unload itself?

VB.net Addin unload itself?

pball
Mentor Mentor
1,135 Views
16 Replies
Message 1 of 17

VB.net Addin unload itself?

pball
Mentor
Mentor

I would like a DLL addin to be able to unload it self. I found some code that works running it from VBA but not from inside my addin. Is is possible for an addin to unload itself?

 

ThisApplication.ApplicationAddIns.ItemById("{idstringhere]").Deactivate()

Check out my style edits for the Autodesk forums
pball's Autodesk Forum Style
0 Likes
1,136 Views
16 Replies
Replies (16)
Message 2 of 17

HideoYamada
Advisor
Advisor

Hello pball,

 


@pball wrote:

I would like a DLL addin to be able to unload it self. I found some code that works running it from VBA but not from inside my addin. Is is possible for an addin to unload itself?

 

ThisApplication.ApplicationAddIns.ItemById("{idstringhere]").Deactivate()


I got same result with c# now. It seems that the add-ins cannot be disabled by themselves.

 

Note that the add-in is only disabled by Deactivate() and the dll isn't unloaded.

(To unload the dll, you must restart Inventor.)

 

=====

Freeradical

 Hideo Yamada

 

=====
Freeradical
 Hideo Yamada
https://www.freeradical.jp
0 Likes
Message 3 of 17

jjstr8
Collaborator
Collaborator

I am able to self-deactivate in C# in Inventor 2017.

0 Likes
Message 4 of 17

bradeneuropeArthur
Mentor
Mentor

Hi,

 

Create a new add in to unload the add in you want to unload!

Regards,

Arthur Knoors

Autodesk Affiliations & Links:
blue LinkedIn LogoSquare Youtube Logo Isolated on White Background


Autodesk Software:Inventor Professional 2025 | Vault Professional 2024 | Autocad Mechanical 2024
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:
My 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 !


 


EESignature

0 Likes
Message 5 of 17

HideoYamada
Advisor
Advisor

Hi,

 


@jjstr8 wrote:

I am able to self-deactivate in C# in Inventor 2017.


I tried with Inventor 2020 and got an exception.

Where did you do "Deactivate()"? I did at "OnExecute()".

 

=====

Freeradical

 Hideo Yamada

 

=====
Freeradical
 Hideo Yamada
https://www.freeradical.jp
0 Likes
Message 6 of 17

jjstr8
Collaborator
Collaborator

It was in an OnExecute method for one of my command's button definition.

0 Likes
Message 7 of 17

jjstr8
Collaborator
Collaborator

If that's exactly what you're using, the ']' at the end should be a '}'

0 Likes
Message 8 of 17

HideoYamada
Advisor
Advisor

Hi,

 


@jjstr8 wrote:

If that's exactly what you're using, the ']' at the end should be a '}'


You are right!

I could deactive with Inventor 2020.

(I had specified the internal name of AddIn to the argument of ItemById at my test.

 We have to use clsid that described in the manifest.)

 

=====

Freeradical

 Hideo Yamada

=====
Freeradical
 Hideo Yamada
https://www.freeradical.jp
0 Likes
Message 9 of 17

GeorgK
Advisor
Advisor

Hello @HideoYamada ,

 

please could you share your code.

 

Thank you

Georg

0 Likes
Message 10 of 17

HideoYamada
Advisor
Advisor

Hi,

 


@GeorgK wrote:

please could you share your code.

The codes and complied dll are attached to this post.

Please try this.

 

=====

Freeradical

 Hideo Yamada

=====
Freeradical
 Hideo Yamada
https://www.freeradical.jp
Message 11 of 17

HideoYamada
Advisor
Advisor

Sorry, I tried with C#.

I'll try with VB.net if you need. (Please let me know if so.)

=====
Freeradical
 Hideo Yamada
https://www.freeradical.jp
0 Likes
Message 12 of 17

GeorgK
Advisor
Advisor

Great. Thank you.

Georg

0 Likes
Message 13 of 17

pball
Mentor
Mentor

@jjstr8I checked and that typo is just in my post, the addin ID is properly formatted in my real code.

 

Long story short I noticed calling the sub where I try to deactivate the addin from the main Activate sub in the addin failed. While calling the sub after Inventor was started up worked. So I played around a bit and found the application events on ready event. Calling my sub from there works just fine. The only difference is instead of happening while the splash screen is up it happens after Inventor has loaded which isn't an issue for me.

 

        Private Sub m_appevents_onready() Handles m_ApplicationEvents.OnReady
            Log_User() 'This sub has the deactivate line in it
        End Sub
Check out my style edits for the Autodesk forums
pball's Autodesk Forum Style
0 Likes
Message 14 of 17

HideoYamada
Advisor
Advisor

Hi,

 

I didn't know the event 'OnReady'. This seems useful.

 

If you can, could you tell me the scenario why Deactivate at Activate?

Are you trying to cancel activation?

 

=====

Freeradical

 Hideo Yamada

 

=====
Freeradical
 Hideo Yamada
https://www.freeradical.jp
0 Likes
Message 15 of 17

pball
Mentor
Mentor

People around here do not like to update the company Addin I manage and I haven't found a simple way to have it auto update. So I finally got around to adding a nag if the addin is out of date. Figured I could also have the addin stop working so people would be more likely to update it. Sadly that nag and time bomb feature will only start working with the next update, assuming people update to this version lol.

Check out my style edits for the Autodesk forums
pball's Autodesk Forum Style
0 Likes
Message 16 of 17

HideoYamada
Advisor
Advisor

Hi,

 


@pball wrote:

People around here do not like to update the company Addin I manage and I haven't found a simple way to have it auto update. So I finally got around to adding a nag if the addin is out of date. Figured I could also have the addin stop working so people would be more likely to update it. Sadly that nag and time bomb feature will only start working with the next update, assuming people update to this version lol.


As far as I know, Inventor will not mark as "Loaded" if an exception is thrown at the add-in's Activate() to Inventor.

So I think you just throw some exception in Activate() to avoid the actication.

In this case Deactivate() will not be called and so you must release the resources if you have obtained at Activate().

 

I think it is more friendly that the alert message will be shown when the command is executed, rather than suddenly the add-in disappears.

(When the add-in disappears, you will get many phone calls from every users!!)

 

And more one thing, even if the add-in has deactivated at OnReady(), users can reactivate it at Addin Manager and the add-in has been marked as loaded (activated).

In this scenario user can execute the command and the trouble may cause if you don't initialize the add-in completely if it is expired.

 

=====

Freeradical

 Hideo Yamada

=====
Freeradical
 Hideo Yamada
https://www.freeradical.jp
0 Likes
Message 17 of 17

pball
Mentor
Mentor

The user will get a message before the addin is deactivated. There are also only 8 users here and most if not all of them will immediately ask me if something doesn't work. Which will end up with me telling them to upgrade or stop complaining. So I'm not concerned about users re-enabling the addin or getting angry phone calls. If I was supporting a large group with this addin, I would invest the time into a better more seamless solution like automagical upgrading.

 

This addin is just something I made for personal use and shared with everyone because I'm nice. So I don't have large amounts of time to invest as it isn't explicitly something I'm paid or told to do.

Check out my style edits for the Autodesk forums
pball's Autodesk Forum Style