Append menu items to Grasshopper components with C#

How to add items to the right-click menu in Grasshopper.

This example shows how we can add a text item to the right-click menu, and change a field within the class of our Grasshopper component.

Custom menu item in right click menu in Grasshopper

The code to do this is written for compiled C# components written in an environment such as Visual Studio. Add these methods to your component class.

        protected override void AppendAdditionalComponentMenuItems(System.Windows.Forms.ToolStripDropDown menu)
        {
            base.AppendAdditionalComponentMenuItems(menu);
            Menu_AppendItem(menu, "Flip myBool", Menu_DoClick);
        }

        private void Menu_DoClick(object sender, EventArgs e)
        {
            myBool = !myBool;
        }
        public bool myBool = false; 

This creates the menu item called ‘Flip myBool’ when we right-click the component. When we click on the menu item, it calls the Menu_DoClick method. We can define any method (with any name) that we want here.

References

http://www.grasshopper3d.com/forum/topics/set-input-parameter-from-a-pop-up-menu-vb

Add a Comment

Your email address will not be published. Required fields are marked *

Time limit is exhausted. Please reload CAPTCHA.