Revit API Forum
Welcome to Autodesk’s Revit API Forums. Share your knowledge, ask questions, and explore popular Revit API topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Relative path for folder

6 REPLIES 6
SOLVED
Reply
Message 1 of 7
cherrytruongmyhoa
1527 Views, 6 Replies

Relative path for folder

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

6 REPLIES 6
Message 2 of 7

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

Hi,

replace

C:\ProgramData

With

 

Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData)

 

 

Thanks & Regards

Sanjay Pandey

Message 4 of 7

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
in reply to: David_Robison

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

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);
Message 7 of 7

Hi David,

 

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

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Rail Community