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
Solved! Go to Solution.
Solved by David_Robison. Go to Solution.
Solved by jeremytammik. Go to 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
Then you will have no need for any file path at all, and life will be easy and sweet.
Cheers,
Jeremy
Hi,
replace
C:\ProgramData
With
Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData)
Thanks & Regards
Sanjay Pandey
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.
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.
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);
Hi David,
Thank you for your suggestion. I just using exactly the same method with you :).