Relative path for folder

Relative path for folder

Anonymous
Not applicable
2,257 Views
6 Replies
Message 1 of 7

Relative path for folder

Anonymous
Not applicable

Hi everyone,

 

I am starting with some first Revit add in and one thing I am concerned is how to create the relative path for my icon url for my add in as following code: 

 // Determine the data for a push button, include the name of the command to execute
                        PushButtonData pushButtonData51 = new PushButtonData("DetachModels", "DetachModels", thisAssemblyPath, "CherryBIMservices.BatchDetachedModel");

                        //Add push button to the ribbon panel
                        PushButton pushButton51 = ManagePanel.AddItem(pushButtonData51) as PushButton;

                        // Add a tool tip for a button
                        pushButton51.ToolTip = "Batch detach models";

                        // Add URL of image, set as Bitmap and set the image as the icon for the pushbutton
                        Uri uriImage51 = new Uri(@"C:\ProgramData\Autodesk\Revit\Addins\2017\CherryBIMservices\51.png");
                        BitmapImage bitmapImage51 = new BitmapImage(uriImage51);
                        pushButton51.LargeImage = bitmapImage51;

My question is how to replace the path : "

C:\ProgramData\Autodesk\Revit\Addins\2017\CherryBIMservices\51.png

by relative path. 

 

Thank you so much for your help.

 

Best Regards,

 

Cherry Truong

0 Likes
Accepted solutions (2)
2,258 Views
6 Replies
Replies (6)
Message 2 of 7

jeremytammik
Autodesk
Autodesk
Accepted solution

Dear Cherry,

 

I would recommend embedding your icon as an embedded resource:

 

http://thebuildingcoder.typepad.com/blog/2012/06/retrieve-embedded-resource-image.html

 

http://thebuildingcoder.typepad.com/blog/2018/05/scaling-a-bitmap-for-the-large-and-small-image-icon...

 

Then you will have no need for any file path at all, and life will be easy and sweet.

 

Cheers,

 

Jeremy

 



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

Message 3 of 7

Anonymous
Not applicable

Hi,

replace

C:\ProgramData

With

 

Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData)

 

 

Thanks & Regards

Sanjay Pandey

Message 4 of 7

David_Robison
Advocate
Advocate
Accepted solution

One more suggestion for you. I use:

 

System.Reflection.Assembly.GetExecutingAssembly().Location

 

This line of code gives you the path where your DLL is located. Make sure your PNGs are in the same folder and then it is easy to find them.

Message 5 of 7

0001des
Enthusiast
Enthusiast

I use David's method for my relative paths for my ribbon icons as well.  Use 

 

   Path.Combine()

 

to concatenate the path to the image name and extension.

Message 6 of 7

Anonymous
Not applicable

Hi Jimmy,

 

Thank you so much for your great help. 

I also found another solution for this by using: 

string thisAssemblyPath = Assembly.GetExecutingAssembly().Location; 
var iconPath40 = Path.Combine(outPutDirectory, "Icons\\Select2SectionBox.png");
Uri uriImage40 = new Uri(@iconPath40);
0 Likes
Message 7 of 7

Anonymous
Not applicable

Hi David,

 

Thank you for your suggestion. I just using exactly the same method with you :).

0 Likes