algorithmic modeling for Rhino
Hi,
I am working on a bunch of tools to help organize the objects on the canvas. At the moment I am using GH_Components as containers for these, but ideally, these functions would get their own keyboard shortcut, such as <ctrl-L> for "Insert generic parameters to the left of every selected object".
Is it possible to create custom keyboard shortcuts? And if not, does anyone have any suggestions as to how to easily call these custom functions?
Tags:
Although you can find the menu on the Grasshopper window by iterating over the controls in Grasshopper.Instances.DocumentEditor.Controls, and, once found, you can insert menu items into it, the Grasshopper window does have its own shortcut handling logic. Just assigning a shortcut combo to a new menu item won't do the trick.
The steps needed for add menu items to GH and have them respond to shortcuts are:
To be honest I've never tested this...
But it does work, even if it isn't particularly elegant.
The field is static, meaning it is shared amongst all instances of that class. When a script file is compiled, the resulting type is stored inside a dictionary and if the exact same script occurs somewhere else it'll retrieve the type from there, rather than compiling anew. So static fields are shared amongst all C# component instances that run the exact same code.
If you change the script slightly (even just whitespace), it will compile again and you'll get a second menu item.
Incidentally you could also add buttons to the toolbar, or even add additional toolbars to the main form if you'd feel so inclined. None of that will allow you to use shortcut keys, but it might still be an interesting alternative for quick-access tools.
Thanks so much David.
That is working beautifully! I had a bit of a challenge getting it to work in my plugin, but adding the lines below seems to make it work. Is this how you would go about it as well?
public override GH_LoadingInstruction PriorityLoad()
{
Instances.CanvasCreated += RegisterMenuItems;
return GH_LoadingInstruction.Proceed;
}
protected void RegisterMenuItems(GH_Canvas canvas)
{
Instances.CanvasCreated -= RegisterMenuItems;
GH_DocumentEditor documentEditor = Instances.DocumentEditor;
if (documentEditor != null)
{
this.CreateTidyMenu(documentEditor);
}
}
Thanks again!
Welcome to
Grasshopper
Added by Parametric House 0 Comments 0 Likes
Added by Parametric House 0 Comments 0 Likes
© 2024 Created by Scott Davidson.
Powered by