Delay Addin Load

Delay Addin Load

Dale.Bartlett
Collaborator Collaborator
1,033 Views
6 Replies
Message 1 of 7

Delay Addin Load

Dale.Bartlett
Collaborator
Collaborator

I use a bootstrap addin to copy some files as per this thread: the-order-of-addins

 

The below code is the essence of it. The batch copy process is now a bit lengthy, and is failing as subsequent addins start loading. Is there a way to delay Revit loading additional addins until this batch process is complete?

 

 public Result OnStartup(UIControlledApplication app)
        {
            AAA_RevitBootStrap();

            String version = app.ControlledApplication.VersionName;
            //display splash window for 5 seconds
            SplashWindow.StartSplash();
            SplashWindow.ShowVersion(version);
            System.Threading.Thread.Sleep(5000);
            SplashWindow.StopSplash();

            return Result.Succeeded;
        }

        static void AAA_RevitBootStrap()
        {
            string lstrDllPath = Path.GetDirectoryName(SystemTools.MyDLLs());
            string lstrDllPathFull = lstrDllPath + "\\" + "AAA_RevitBootStrap.bat";
            System.Diagnostics.Process.Start(lstrDllPathFull);
        }



______________
Yes, I'm Satoshi.
0 Likes
Accepted solutions (1)
1,034 Views
6 Replies
Replies (6)
Message 2 of 7

matthew_taylor
Advisor
Advisor

Hi @Dale.Bartlett,

I went through this years back. I actually moved away from using an addin and used a standalone exe that monitored the files.

I set it to start on login.

It's much simpler than the gymnastics you'll have to go through! (And if Revit changes the way it does things, you need to rethink it.)


Cheers,

-Matt
_______________________________________________________________________________
Marking a post as a 'solution' helps the community. Giving a post 'Kudos' is as good as saying thanks. Why not do both?
0 Likes
Message 3 of 7

Dale.Bartlett
Collaborator
Collaborator

Hi @matthew_taylor,

You may well be right. The addin was working perfectly until R2017, but I now think that I am mistaken in thinking that the batch processing is the issue. The error message: "The invoked member is not supported in a dynamic assembly." refers to a function that uses reflection to return the executing dll name/location. Mustafa's suggestion here didn't resolve the error: the-invoked-member-is-not-supported

// return dll locations
        public static string MyDLLs()
        {
            System.Reflection.Assembly Asmbly = null;
            string strAssem = string.Empty;

            // get current dll name
            string lstrDllName = System.Reflection.Assembly.GetExecutingAssembly().GetName().Name;
            string lstrDllLocation = string.Empty;

            foreach (System.Reflection.Assembly Asmbly_loopVariable in System.AppDomain.CurrentDomain.GetAssemblies())
            {
                Asmbly = Asmbly_loopVariable;
                strAssem += Asmbly.FullName + Environment.NewLine;
            }

            foreach (System.Reflection.Assembly Asmbly_loopVariable in System.AppDomain.CurrentDomain.GetAssemblies())
            {
                Asmbly = Asmbly_loopVariable;
                lstrDllLocation = Asmbly.Location.ToString();

                string lstrDllNameTest = Path.GetFileNameWithoutExtension(lstrDllLocation);

                if (lstrDllName.ToUpper() == lstrDllNameTest.ToUpper())
                {           
                    break;
                }
            }
            return lstrDllLocation;
        }



______________
Yes, I'm Satoshi.
0 Likes
Message 4 of 7

jeremytammik
Autodesk
Autodesk

Dale,

 

I tend to agree with Matt's suggestion: if what you are doing is not intentionally supported by the Revit API, then try to solve it on your own with maximum Revit independency.

 

You could go in two directions:

 

  • Handle it in a standalone EXE before Revit gets its hands on anything.
  • Put everything into one single external add-in that handles everything after Revit has finished and the ApplicationInitialized call comes through.

 

http://www.revitapidocs.com/2017/1d917597-712c-cec3-db2a-8301c62a8ee3.htm

 

I hope this helps.

 

Please let us know how you end up solving it.

 

Thank you!

 

Cheers,

 

Jeremy



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

0 Likes
Message 5 of 7

Dale.Bartlett
Collaborator
Collaborator

HI Jeremy,

Thanks for the suggestions, and all agreed. Unfortunately, like a lot of users, I am in a corporate environment and not able to execute/install applications on user computers. That is why I have taken this approach, similar in concept to the old AutoCAD acad.lsp startup function. Essentially, I am copying all addins from a network location to the local user's C:\ProgramData\Autodesk. Your suggestion #2 won't work in that case as Revit will have the addins locked and loaded once the ApplicationInitialized call comes through. My system, with all its weaknesses has been working well. This latest error with the 2017 upgrade is something that I have yet to resolve. All responses are appreciated.




______________
Yes, I'm Satoshi.
0 Likes
Message 6 of 7

matthew_taylor
Advisor
Advisor

Hi @Dale.Bartlett,

Well, Applications are the issue. External commands are loaded when they are used, and can be loaded manually in memory if required.

 

If you're not concerned about being up-to-date immediately when Revit is started, you could load the latest 'onShutdown' by executing a script to do the copying (process.start - it would have to wait a set time for shutdown to finish). It appears you may 'wait' in batch files:
https://www.google.co.uk/search?hl=en&q=wait+in+batch+file&gws_rd=ssl

Of course, you may want to utilise that method to update your pre-Revit starting fully updater. 😉

 

Maybe the easiest way would be to delete all .addin files, copy the .dll files, then re-copy (or recreate) the .addin files? Only do it if an update is available. This may be the best way. As long as you're not supporting pre - RevitAddInItem.AllowLoadIntoExistingSession versions of Revit. (2013 and prior.)

You could easily do this if you name your updater addin earlier in the alpha-numeric loading hierarchy.

 

 

 


Cheers,

-Matt
_______________________________________________________________________________
Marking a post as a 'solution' helps the community. Giving a post 'Kudos' is as good as saying thanks. Why not do both?
0 Likes
Message 7 of 7

Dale.Bartlett
Collaborator
Collaborator
Accepted solution

Well, the batch processing time wasn't the issue, I was down a rabbit hole... Apologies. Thanks for the input, and whilst it may not be the most elegant solution, it works. Till R2018 at least. Regards, Dale




______________
Yes, I'm Satoshi.
0 Likes