Hi, I was trying to use method two for compiling ghpython nodes as described here:
Tutorial: creating a Grasshopper component with the Python GHPY compiler - Serengeti (Rhino WIP) / Developer - McNeel Forum
I want my package to contain a dropdown menu, and attempted to add the following code to replicate the setup I’ve used in c# before:
class DropdownMenu(Grasshopper.Kernel.GH_AssemblyPriority):
def PriorityLoad(): # override method
Grasshopper.GH_DocumentEditor+=OnAggregateShortcutMenuItems
return Grasshopper.Kernel.GH_LoadingInstruction.Proceed
def OnAggregateShortcutMenuItems(self, e):
# Get a reference to the main Grasshopper canvas
ribbon = e.MainMenu # Get ribbon
_item = System.Windows.Forms.ToolStripMenuItem()
_item.Text = "Button Name"
_item.Click += ItemClick1 # Add a click event handlers
_cowiMenu = System.Windows.Forms.ToolStripMenuItem()
_cowiMenu.Text = "Menu Name"
_cowiMenu.DropDownItems.Add(_item)
# Add the custom menu item to the Grasshopper canvas menu
ribbon.Items.Add(_cowiMenu);
def ItemClick1(self, args):
System.Diagnostics.Process.Start("O:\\Applications\\Global")
But it does not seem to run the “PriorityLoad” function when Rhino starts. I tested by adding a message box. Is it possible to add this type of functionality to a .ghpy assembly?
The compilation file and the code itself is attached.
AssemblyNode.py (4.9 KB)
Main.py (83 Bytes)
Br
Audun Mathias Øvstebø