Alternate way to do grasshopper icons with Rider

I finally figured out how to insert an icon when using Rider as the IDE. Then I realized that this post already existed (whoops).

So I guess this post will now be about an alternate way to specify the icon for a component.

Before I go further, this is basically my first crack at anything C# (my background is Python with a small amount of Java), so let me know if I’m laying down bad information.

First thing is make sure the project has the System.Resources.Extensions assembly installed (hopefully that’s the appropriate term).

Next is to make sure the following is in the <PropertyGroup> tag in the csproj file:

<GenerateResourceUsePreserializedResources>true<GenerateResourceUsePreserializedResources>

So it should look something like this:

    <PropertyGroup>
        <TargetFramework>net48</TargetFramework>
        <Version>1.0</Version>
        <Title>CirclePortalIn</Title>
        <Description>Description of CirclePortalIn</Description>
        <TargetExt>.gha</TargetExt>
        <GenerateResourceUsePreserializedResources>true</GenerateResourceUsePreserializedResources>
    </PropertyGroup>

If you don’t have a Resources.resx file, get that created:


image

Once that’s created, get a base encoding of the image you want to use for an Icon. This will go in the <Value> tag. The entire entry should look something like this:

<data name="Icon" type="System.Drawing.Bitmap, System.Drawing,
    Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
        mimetype="application/x-microsoft.net.object.bytearray.base64">
    <value>
      iVBORw0KGgoAAAANSUhEUgAAABgAAAAYEAYAAACw5+G7AAAFwGlUWHRYTUw6Y29tLmFkb2JlLnhtcAAAAAAAPD94cGFja2V0IGJlZ2luPSLvu78iIGlkPSJXNU0wTXBDZWhpSHpyZVN6TlRjemtjOWQiPz4KPHg6eG1wbWV0YSB4bWxuczp4PSJhZG9iZTpuczptZXRhLyIgeDp4bXB0az0iWE1QIENvcmUgNS41LjAiPgogPHJkZjpSREYgeG1sbnM6cmRmPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5LzAyLzIyLXJkZi1zeW50YXgtbnMjIj4KICA8cmRmOkRlc2NyaXB0aW9uIHJkZjphYm91dD0iIgogICAgeG1sbnM6eG1wPSJodHRwOi8vbnMuYWRvYmUuY29tL3hhcC8xLjAvIgogICAgeG1sbnM6cGhvdG9zaG9wPSJodHR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yPxcXJi/kXRQCQCq6uNg+zvZHxoa2pgOGxel9QAD8/7O5F80/T3/45NK/X1wUjE+FAnZDEH/H64uMiOVFTotmgWdcrLiZaXjT6SpWyAjg8PiTY34eqqHptWCgTg1hY+Dg5UK21+zMm9eHQELy/h6CgF7u4ytWrccTHe0AA7Osj/+qr6v8UtJFdCBllnJ7y5geEwBoaGoMNhz7DDAT0eyQNvb+0aF2V5oOnqIpqbg42NUCannMDk/S2vw7o6eHEB/X4M7++n60PzkVJuNRn5qiNlKJSrT5R/6dY3R7Ibw5tFHHsAAAAASUVORK5CYII=
    </value>
  </data>

Feel free to change the name attribute to whatever you want, but that’s what will be referenced.

Now in the cs file for your component:

        /// <summary>
        /// Provides an Icon for every component that will be visible in the User Interface.
        /// Icons need to be 24x24 pixels.
        /// You can add image files to your project resources and access them like this:
        /// return Resources.IconForThisComponent;
        /// </summary>
        // protected override System.Drawing.Bitmap Icon => null;
        protected override System.Drawing.Bitmap Icon
        {
            get
            {
                return Resources.Icon;
            }
        }

And that should be it!
image

Hopefully this is useful to someone.

3 Likes