API call for Set Icon / Icon Path for Button

steven.williams.as
Enthusiast

API call for Set Icon / Icon Path for Button

steven.williams.as
Enthusiast
Enthusiast

Is there an API call to access/set the button icon? It is available in the GUI in two ways:

  • Main interface → MAP Buttons → Right-click, Button Report → Icon Path column

2022-04-01 10.20.14 acad_5w60Y9zzcQ.png

2022-04-01 10.20.37 acad_hkcnhHrCR4.png

 

  • Edit Service Database → Service Information → Edit Service Template → Right-click a button

2022-04-01 10.22.49 acad_kiZUsQEQwq.png

2022-04-01 10.23.03 acad_rQqI3jfxsw.png

2022-04-01 10.23.31 acad_vPOpXhgmEz.png

 

It appears that the GetBase64ButtonImage() method may return that image, but the documentation is not clear on that, and I have not tried it myself yet. There also appears to be a similar (inaccessible) method internal unsafe string GetImagePath().

 

I cannot find any documentation in the API manual (C:\Program Files\Autodesk\Fabrication 2020\SDK\FabricationAPI.chm) that sets the icon path. Does such a property or method exist?

 

Edit: This is related to a question @ssimleness asked several years ago, but mine is the API version of the question.

0 Likes
Reply
Accepted solutions (1)
623 Views
2 Replies
Replies (2)

dyoung
Advocate
Advocate
Accepted solution

Namespaces -> Autodesk Fabrication -> Item Class -> Item Methods -> SetImage Method

Darren J. Young
http://www.darrenjyoung.com/
https://www.linkedin.com/in/darrenjyoung/
0 Likes

MartinMagallanes
Explorer
Explorer

@dyoung's suggestion works to report the image assigned to the ITM itself and is true when the button only contains a single ITM (or is the first assigned to a button) and the button's Icon has not been changed with the Set Icon option @steven.williams.as showed.

 

 

Thanks for pointing out this internal method because I had the same question today. It does work, returning the button's true icon path! The method "internal unsafe string GetImagePath()" can be used like this:

 

using Autodesk.Fabrication.DB;
using System;
using System.Reflection;

namespace MyNamespace
{
    public static class Methods
    {
        public static void GetIconPaths()
        {
            foreach (ServiceTemplate serviceTemplate in Autodesk.Fabrication.DB.Database.ServiceTemplates)
            {
                foreach (ServiceTab serviceTab in serviceTemplate.ServiceTabs)
                {
                    foreach (ServiceButton serviceButton in serviceTab.ServiceButtons)
                    {
                        Type buttonType = serviceButton.GetType();
                        MethodInfo methodInfo = buttonType.GetMethod("GetImagePath", BindingFlags.NonPublic | BindingFlags.Instance);
                        string iconPath = methodInfo.Invoke(serviceButton, null) as string;
                        //Do stuff here
                    }
                }
            }
        }
    }
}


Edit: I forgot to mention that unfortunately I haven't found a way to set this property but maybe you can do it by modifying the items in the button and selecting the one with the image you want first. Or setting all of them to the same image with @dyoung's method, if that doesn't affect other buttons. 

 

0 Likes