Assign a toolbar icon to the Extension?

Thiago_Sase wrote on 4/26/2025, 6:15 AM

@jetdv Hello, Sir. Please, could you help me? How should I start to write lines of code to assign a toolbar icon, a PNG file, to my extension, just the way that shows up for scripts?

Comments

zzzzzz9125 wrote on 4/26/2025, 7:14 AM

@Thiago_Sase Just use something like:

public static void SetIconFile(CustomCommand cmd, string fileName)
{
    cmd.IconFile = Path.Combine(Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location), fileName);
}

 

For example, use:

SetIconFile(cmd, "iconfilename.png");

This will read the iconfilename.png file in the same folder as the extention dll for this custom command.

jetdv wrote on 4/26/2025, 10:58 AM

It's set in the custom command itself. I use the "script file" location tell me where it is and put it in the same folder as the custom command.

        string scriptFile = Assembly.GetExecutingAssembly().CodeBase.Substring(8);
        myPI.IconFile = Path.GetDirectoryName(scriptFile) + Path.DirectorySeparatorChar + "MyIcon.png";

 

Thiago_Sase wrote on 4/26/2025, 1:49 PM

@zzzzzz9125 @jetdv Thank you. Both solutions worked perfect. Thank you both very much!