Grasshopper

algorithmic modeling for Rhino

Hi everyone, a cosmetics question:
would anybody be so kind to tell me how/where to put the code to add a category icon to my assembly/GHA?
I guess I'll have to add a class to the assembly to put it in, but I couldn't find any info/discussions about it...

Kind regards,
Pieter

Views: 994

Replies to This Discussion

You can call it whenever you want. A good place would be to put it in the PriorityLoad method of a GH_AssemblyPriority derived class. That one gets called only once and before any other calls to your assembly.

Thank you for replying David, I appreciate it. Since I'm learning to script through internet resources this might just lead me to some relevant info. Because - to be honest - I don't understand what you just said (yet) ~ I'll do some more searching/learning.

If in the mean time anyone knows where to find a good resource, I would really like to learn about it:)

When Grasshopper loads a GHA file, it uses Reflection to inspect all the publicly exposed types. most importantly it tries to find all components and parameters, but there are other types of class that are also handled.

Every class in a GHa which derives from (i.e. "inherits") the GH_AssemblyPriority class will be instantiated, and the method PriorityLoad() will be called. This is a mechanism that allows the developer to easily do stuff before the GHa gets properly loaded. For example the developer might want to check to see if a valid license is available, and if there isn't, it can prevent the further loading of the GHA.

To actually make this work in your project (I'm assuming C#), you need to add the following class:

public class MyCategoryIcon : Grasshopper.Kernel.GH_AssemblyPriority
{
  public override Grasshopper.Kernel.GH_LoadingInstruction PriorityLoad()
  {
    Grasshopper.Instances.ComponentServer.AddCategoryIcon("MyCategory", somebitmap);
    Grasshopper.Instances.ComponentServer.AddCategoryShortName("MyCategory", "MyCat");
    Grasshopper.Instances.ComponentServer.AddCategorySymbolName("MyCategory", 'M');

    return Grasshopper.Kernel.GH_LoadingInstruction.Proceed;
  }
}

Great! Thanks so much for your kind help again David!
I did some searches earlier this evening in persuance of your previous reply and found these:

http://www.grasshopper3d.com/forum/topics/sdk-changes-and-new-featu...
http://www.grasshopper3d.com/forum/topics/only-get-plugin-working-i...
http://www.grasshopper3d.com/forum/topics/add-a-new-menuitem-in-gra...
http://www.grasshopper3d.com/forum/topics/add-activation-to-gha
http://www.grasshopper3d.com/forum/topics/best-practices-with-exter...


but then sat with my dear friend (a visiting 11 yr old Greyhound) and was watching two StarTrek movies in a row. Really nice to see your reply just before calling it a day:) Again, I really appreciate you taking the time to explain.

RSS

About

Translate

Search

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service