Self updating AddIn

Self updating AddIn

Jef_E
Collaborator Collaborator
2,961 Views
24 Replies
Message 1 of 25

Self updating AddIn

Jef_E
Collaborator
Collaborator

Hi!

 

I made an AddIn that is actively used at my company. And by actively I mean by the users and the developer (me), so there are frequent updates for the AddIn holding new features and bug fixes.

 

Currently when a new version goes live, a Email is sent to ALL of the end-users that they need to run the installer to get the latest .dll file on their computer.

 

To avoid that someone forgets or ignores the email I would like to compare the AddIn .dll files the local one stored under

 

C:\Program Files\Autodesk\Inventor 2014\Bin

And the one on the network drive ( or maybe in the future, on the FTP server ). I did some research and found a way to do this check.

 

Dim myFileVersionInfo As FileVersionInfo
myFileVersionInfo = FileVersionInfo.GetVersionInfo("C:\Program Files\Autodesk\Inventor 2014\Bin\xxxx.dll")

Dim serverFileVersionInfo As FileVersionInfo
serverFileVersionInfo = FileVersionInfo.GetVersionInfo("T:\Inventor\Tools\xxxxx\xxxxx.dll")

Debug.Print(String.Compare(myFileVersionInfo.ProductVersion, serverFileVersionInfo.ProductVersion))

When this result = -1 the local file is out of date and the .dll file should be replaced. Problem is.. When Inventor is running the .dll file cannot be replaced. How should I handle this?

 

My check is currently situated in the activate sub

        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
            
            ' Check for the file
            FileVersionCheck()

        End Sub


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

Inventor 2014 SP2
0 Likes
2,962 Views
24 Replies
Replies (24)
Message 2 of 25

pball
Mentor
Mentor
I'll be keeping an eye out on this topic since I'd implement this also.

The only way I can see being able to update an addin is to have it install/copy the update after Inventor closes. It should be possible to hook an event when Inventor is closing, check that no other instances of Inventor are open, and then create something that would persist after Inventor closes that does the updating. I'm not sure how a secondary process would be created except for having a helper program that would be ran.

Thinking about it I did have a script create a batch file that would be run when the script exited and the batch file would then do something and then start the script again and finally delete itself. That seems a bit janky for an addin though. Perhaps there is a better programming method for something like that.
Check out my style edits for the Autodesk forums
pball's Autodesk Forum Style
0 Likes
Message 3 of 25

Jef_E
Collaborator
Collaborator

Maybe this will not work but what if...

 

        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
            
            ' Check for the file
            If FileVersionCheck = -1 Then

                 ' Quit Inventor
                 m_inventorApplication.Quit

                 ' Replace the .dll file with new version
 
                 '  Start a new process                
                 Process.Start("C:\Program Files\Autodesk\Inventor 2014\Bin\Inventor.exe)

                 '  Kill the current addin from memory
                 me.dispose


            End If

        End Sub

This is untested and a longshot maybe, I don't know what happens with the AddIn process when Inventor Quits. Does the process get terminated???



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

Inventor 2014 SP2
0 Likes
Message 4 of 25

frederic.vandenplas
Collaborator
Collaborator

I have sporadicly about 50 users , i place the dll on the server, and close the sessions of that file on the server, update the dll (fast, fast, fast, ...) and no one even noticed anything. No installers needed, the addin is installed with the package we deliver.

I do the same for Autocad.

Everyone is up to date without informing, mailing and so on.

 

If you think this answer fullfilled your needs, improved your knowledge or leads to a solution,
please feel free to "kudos"
0 Likes
Message 5 of 25

Jef_E
Collaborator
Collaborator

How do you point your Inventor for a .dll outside of the Inventor BIN folder?



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

Inventor 2014 SP2
0 Likes
Message 6 of 25

frederic.vandenplas
Collaborator
Collaborator
<Addin Type="Standard">
  <!--Created for Autodesk Inventor Version 19.0-->
  <ClassId>{55adb922-404a-441f-a3c1-0154b7b8c2ce}</ClassId>
  <ClientId>{55adb922-404a-441f-a3c1-0154b7b8c2ce}</ClientId>
  <DisplayName>XXX</DisplayName>
  <Description>XXX</Description>
  <Assembly>serverpath\name.dll</Assembly>
  <LoadOnStartUp>1</LoadOnStartUp>
  <UserUnloadable>0</UserUnloadable>
  <Hidden>0</Hidden>
  <SupportedSoftwareVersionGreaterThan>17..</SupportedSoftwareVersionGreaterThan>
  <DataVersion>1</DataVersion>
  <UserInterfaceVersion>1</UserInterfaceVersion>
</Addi
If you think this answer fullfilled your needs, improved your knowledge or leads to a solution,
please feel free to "kudos"
0 Likes
Message 7 of 25

pball
Mentor
Mentor

@Jef_E

I'm fairly certain when you exit Inventor any addin will be terminated because the addin should be a child of Inventor.

 

@frederic.vandenplas
Could you please elaborate some more. You say you replace the dll on the network, do you have Inventor using the dll off the network? I didn't really follow what you were saying.

 

Never mind got to posting a bit late apparently. Really wish the forum would warn you if there were new posts since the time you started to write a reply.

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

frederic.vandenplas
Collaborator
Collaborator

Sorry for that 🙂

 

we make a package of our software, which will later be deployed in another package (this is basically a script which copies heritage fonts, settings, but also the .addin file to the Inventor Addins folder which is located in C:\ProgramData\Autodesk\Inventor Addins)

This is easy, if a user needs another version of the software, the dll is also available.

 

In the .addin file i point to the dll which is on the server.

 

If i need to update the dll, i could stay until everyone has gone home, or in the other case, i log on on the server and go to the session manager where i can kill all the clients who are using the dll

 

https://technet.microsoft.com/en-us/library/cc725689(v=ws.11).aspx

 

I prefer not to do the 2nd option but it works anyway (never, ever heard a complaint)

 

So in fact i don't even install the dll, which is the best part of the registry free addin functionality with inventor or autocad

 

Hope this is clear, if other questions, just ask 🙂

If you think this answer fullfilled your needs, improved your knowledge or leads to a solution,
please feel free to "kudos"
0 Likes
Message 9 of 25

pball
Mentor
Mentor

I did some more searching and the best way I've come across to auto update something is using an external updater program. Below is how I would try to go about it.

 

Have your addin check if there is a new version available.

Prompt user that there is a new update, either let them choose to update or tell them Inventor will be closed.

Have the addin save the updater.exe from its resources and start the updater.exe

Have the addin close Inventor

The updater.exe would wait until Inventor is closed, if there are multiple Inventors open it might have to ask you to close them

When no Inventors are open the updater.exe can copy the updated dll/addin file

The updater.exe can then start Inventor and close

 

This method would require making an updater.exe that would copy the updated file(s) after Inventor is closed and then restarting Inventor. It should be possible to add this exe file as a resource to the addin, that way nothing extra needs to be distributed. It would also be possible to update the updater.exe in future versions of the addin and replace any existing one when updating again.

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

w.pepping
Advocate
Advocate

There is another simple way to update the add-in automatically.

I have an add-in (master-dll) that is automatic loaded when Inventor starts. The only thing this dll does is to load other dll-files (work-dll's)

The trick is that before the work-dll-files are loaded the master-dll checks if the version of the work-dll on the server is newer and download and overwrite it with the old dll on the users pc (C:\ProgramData\...)

It works fine if you make often updates to your programs, but if you want to add a complete new function that needs a new button on the Inventor ribbon then you have to update the master-dll.

Get control of your sheet metal files.
Download the app from matprop.com
0 Likes
Message 11 of 25

Anonymous
Not applicable

Hi Wim,

 

Your approach looks like it would be perfect for use in company solutions with regular updates. But I can't get it to work. What I've done is install the work-dll's like normal, but I prevent the work-dll's to load automatically. In my master-dll I tried to load the work-dll's by using the activate() method of the corrosponding work-dll GUID, is this the correct way to load the work-dll? 

 

When I tried this activate() method on two work-dll's these dll's get loaded but other add-in's (for example: the content center add-in) will not get loaded. When I load these work-dll's with automatically load like normal the other add-in's also load normal. 

 

Some difference between my approach and yours is that I use the master-dll only to check and replace the versions of the work-dll's. All other commands and ribbon buttons are in the work-dll's. Could this be a problem?

0 Likes
Message 12 of 25

Jef_E
Collaborator
Collaborator

I used a .exe that is set as start-up program. This .exe replaces the files each time a boot is performed. Close enough for me.



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

Inventor 2014 SP2
0 Likes
Message 13 of 25

bradeneuropeArthur
Mentor
Mentor

Hi,

 

I do similar:

I create a *.bat file and write a script to copy file from XXXXX on the server, to YYYYY in the dll location folder of inventor.

 

this bat file I place in the startup folder of our workstations.

 

on every startup the file that is newer is copied...

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 14 of 25

NachoShaw
Advisor
Advisor

Hey

 

We all have different approaches. My method is to have a text file residing on my web server that i update (generates when i compile my app) that has the current version. When my app loads, it checks the url and reads the version then compares it with the current version. If the url version is greater, i provide the option to download and install it which invokes a download then closes the current app.

Nacho
Automation & Design Engineer

Inventor automation Programmer (C#, VB.Net / iLogic)
Furniture, Sheet Metal, Structural, Metal fab, Tradeshow, Fabrication, CNC

EESignature


Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.


0 Likes
Message 15 of 25

freesbee
Collaborator
Collaborator

....my 100+ workstations run a StartUP script that replaces the addin elements locally reading them from a network share properly prepared. I do not need any third-party tool (it's done natively by ROBOCOPY) and it has never given a problem in the last 9 years.
(oh, sorry: I noticed too late that another user has already given this suggestion two posts earlier, but I am not able to delete my post)

Maybe it helps

Massimo Frison
CAD R&D // PDM Admin · Hekuma GmbH
0 Likes
Message 16 of 25

Anonymous
Not applicable

I found a way to do this by making a separate addin to acquire the DLL from a server location and using system.reflection to create a new instance of the other library and loading it after its copied. Using this method I'm able to update the DLL on the server and the other DLL copies it to the workstations and runs it. 

I can provide code if anyone's interested.

0 Likes
Message 17 of 25

pball
Mentor
Mentor

Please do share some code. Thanks

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

nmunro
Collaborator
Collaborator

You can actually take advantage of how Inventor loads add-ins to do this quite easily. As with Bolter99's reply you need a second add-in to manage this. The key is to assign a 'lower' value to the 'GuidAttribute' attribute of this management add-in. This attribute is defined just above the declaration of the addin class in the 'AddInServer' file.  Note that the following are not complete, you may require other attributes. This same GUID is included in the .addin file that enables registry free registration of your addin.

 

C#: [GuidAttribute("<your guid goes here>")]

       public class StandardAddInServer: ApplicationAddInServer

       

VB.NET: <GuidAttribute("<your guid goes here>")>

               Public Class StandardAddInServer

               Implements Inventor.ApplicationAddInServer

 

Inventor loads add-ins in order by their GUID. If the management add-in has a lower value (hex value), it will initialize first. In the Activate method for the class, call a routine to copy the newer version of your add-in over the existing one.

 

You do have to be very careful about handling any errors and maintaining the existing version of your add-in if anything goes wrong in the process. I've used this technique since 2012 and it works really well.

        


https://c3mcad.com

0 Likes
Message 19 of 25

Anonymous
Not applicable

Heres the code I used to load the DLL:-

 

Imports System.Reflection  

Sub LoadLibraries()
            'This is where the "Updates" will be loaded.
            For Each Library As FileInfo In New DirectoryInfo(My.Settings.Libraries).GetFiles("*.dll", SearchOption.TopDirectoryOnly)
                Try
                    Dim newPath As String = IO.Path.Combine(My.Application.Info.DirectoryPath, Library.Name)
                    Try
                        IO.File.Copy(Library.FullName, newPath, True)
                    Catch ex As Exception
                        'Likely 2nd instance of Inventor.
                    End Try

                    'Load it!
                    oAssembly = Assembly.LoadFrom(newPath)
                    'We get the type of the application (Class_Root_Namespace.Name_Class)
                    oType = oAssembly.GetType("Class_Root_Namespace.Name_Class")
                    'We create an type instance
                    oObject = Activator.CreateInstance(oType)
                    'We execute the methode Hello
                    'oObject.ThisApplication = g_inventorApplication  'call a command from the class1
                    oObject.Activate(addInSiteObj, True)

                    'If TypeOf oObject.ThisApplication Is Inventor.Application Then
                    '    Dim tests As Inventor.Application = CType(oObject.ThisApplication, Inventor.Application)
                    '    MsgBox(tests.SoftwareVersion.DisplayName)
                    'End If
                Catch ex As Exception

                End Try
            Next

 

Then put the LoadAssemblies sub into the Activate sub.

0 Likes
Message 20 of 25

Slothian
Contributor
Contributor

@nmunro Can you possibly expand further on the guid 'lower value' determines the load order. I tried this myself as I have 2 addins loading and would like to have them load in order. I copied the guid number from the addin I wanted to laod second, pasted it into the the other addin and in the last hex number sequence reduced the number by approx 40 (decimal). I then updated all references in that addin to point to the new guid. End result was the addins still load in the same order (addin 2 then addin 1). I checked this by adding message boxes in the standardaddinserver.activate.

0 Likes