Retrieve current folder path

Retrieve current folder path

jjesusdelpino
Advocate Advocate
2,378 Views
5 Replies
Message 1 of 6

Retrieve current folder path

jjesusdelpino
Advocate
Advocate

Hi forum. Im trying to access to the Addins folder in which my dlls are installed:

 

C:\ProgramData\Autodesk\Revit\Addins\2019

 

 

I have tried: 

System.IO.Path.GetDirectoryName(Application.ExecutablePath);

wich output:

C:\Program Files\Autodesk\Revit 2019

 

And also tried:

Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData)

wich output:

C:\ProgramData

 

I can certainly add "\Autodesk\Revit\Addins\2019\" to the last one, but I wouldnt want to add this manually cause maybe someone change the instalation folder (is this even possible?) or the addins folder. Is there a way to retrieve "C:\ProgramData\Autodesk\Revit\Addins\2019" or wherever my dlls is placed with a single command order to minimize errors?

 

Regards.

0 Likes
Accepted solutions (2)
2,379 Views
5 Replies
Replies (5)
Message 2 of 6

RPTHOMAS108
Mentor
Mentor
Accepted solution

On the application object there are properties you can make use of:

 

Application.AllUsersAddinsLocation

Typically: C:\ProgramData\Autodesk\Revit\Addins\<Year>

Application.CurrentUserAddinsLocation

Typically: C:\Users\<User>\AppData\Roaming\Autodesk\Revit\Addins\<Year>

 

It is a bad idea to hardcode parts of a path as in different environments the locations may not be as expected. In virtualised environment for example.

 

 

0 Likes
Message 3 of 6

stever66
Advisor
Advisor
Accepted solution

Try using:

 

using System.Reflection;

string thisAssemblyPath =    Assembly.GetExecutingAssembly().Location;

 

Or for a macro, try:

string thisAssemblyPath = this.AddinFolder.ToString();

0 Likes
Message 4 of 6

jjesusdelpino
Advocate
Advocate

Stever66 solution worked perfectly for me. Also in macro.

After looking API.chm, pretty sure RPTHOMAS108 solution also works perfectly but still havent been able to check because I havent been able to get ApplicationServices.Application.

 

Thank you two. Regards

 

Edit: also works perfectly. check here to get applicationservices.application (https://forums.autodesk.com/t5/revit-api-forum/autodesk-revit-applicationservices-application-onstar...)

0 Likes
Message 5 of 6

RPTHOMAS108
Mentor
Mentor

You can get application as follows:

 

From IExternalCommand.Execute:

commandData.Application.Application

 

From IExternalApplication.OnStartUp/OnShutDown

application.ControlledApplication

 

From IExternalDBApplication.OnStartUp/OnShutDown

application

 

@stever66has probably given a more precise answer since it will list the location of your executing dll file (this can be elsewhere from the .addin file). Note also difference between .GetExecutingAssembly and .GetCallingAssembly.

 

Message 6 of 6

jjesusdelpino
Advocate
Advocate

Thanks for the clarification. 

 

Regards

0 Likes