Add a custom icon image to Grasshopper plugin tabs

Thanks will, I tried your suggestion, but no difference. I’ve already had the following code in Class1.cs in the project attached to my OP

using Grasshopper;

namespace MyProject1
{
    class Class1 : Grasshopper.Kernel.GH_AssemblyPriority
    {
        public override Grasshopper.Kernel.GH_LoadingInstruction PriorityLoad()
        {
            Instances.ComponentServer.AddCategoryIcon("MyProject1", Properties.Resources.smile_16);
            Instances.ComponentServer.AddCategorySymbolName("MyProject1", 'M');
            return Grasshopper.Kernel.GH_LoadingInstruction.Proceed;
        }
    }
}
1 Like

The image needs to be 24x24 not 16x16 if I remember correctly. Also, I use a public class.

2 Likes

Spot on Michael I missed that detail. The above works as expected when the class is made public.

1 Like

Hello
can you please explain in detail how to add a picture to the bar menu
I did as you created the class and announced the fields in the resources but the equal picture is not added?
can you please post the full example from VS 2019?

using Grasshopper;

namespace ToolBox
{
class LogoToolBarMenu : Grasshopper.Kernel.GH_AssemblyPriority
{
public override Grasshopper.Kernel.GH_LoadingInstruction PriorityLoad()
{
Instances.ComponentServer.AddCategoryIcon(“ToolBox”, Properties.Resources.Logo24x24);
Instances.ComponentServer.AddCategorySymbolName(“ToolBox”, ‘S’);
return Grasshopper.Kernel.GH_LoadingInstruction.Proceed;
}
}
}

Resources

    internal static System.Drawing.Bitmap Logo24x24
    {
        get
        {
            object obj = ResourceManager.GetObject("Logo24x24", resourceCulture);
            return ((System.Drawing.Bitmap)(obj));
        }
    }

You also have not made your class public…

1 Like

thank you very much for the answer!

I didn’t notice, but as I added it began to compile

but now another problem

now such a window crashes when loading

or I incorrectly connected the resource file?

I don’t add resources by code. I add them with visual studios resources folder. Then be sure to set them to embedded resource.

1 Like

Thank you. Great. Everything worked out !!! Rays of Gratitude it all worked :grinning: :innocent: :slightly_smiling_face: :slightly_smiling_face:

Thanks @Michael_Pryor for helping wrap our minds around this. Here is how I ended up using your recommendation with code, just because I’m not using VS.

using System;
using System.Drawing;
using System.Linq;
using Grasshopper;
using Grasshopper.Kernel;

namespace Plugin_1_Day_3
{
  public class Plugin_1_Day_3Info : GH_AssemblyInfo
  {
       // all the name, icon, description, guid, etc stuff...
  }
  public class CategoryIcon : Grasshopper.Kernel.GH_AssemblyPriority
  {
    public override Grasshopper.Kernel.GH_LoadingInstruction PriorityLoad()
    {
      var assembly = System.Reflection.Assembly.GetExecutingAssembly();
      var resourceName = assembly.GetManifestResourceNames().Single(n => n.EndsWith("AverageIcon.png"));
      var stream = assembly.GetManifestResourceStream(resourceName);
      Bitmap dasIcon = new Bitmap(stream);
      Grasshopper.Instances.ComponentServer.AddCategoryIcon("Workshop", dasIcon);
      Grasshopper.Instances.ComponentServer.AddCategorySymbolName("Workshop", 'w');
      return Grasshopper.Kernel.GH_LoadingInstruction.Proceed;
    }
  }
}

image

just wrapping things up after looking at this thread, being able to make icons makes all the difference!

2 Likes

Can this be done for a Python only plugin?

1 Like