[Solved] GHPyhon access to Grasshopper.GUI

Is it possible to instantiate GHpython component and within it to manipulate how it looks graphically on Grasshopper canvas?

For example with python script to access Grasshopper.GUI api and add a slider to the component or adding a button functionality

This is not a typical usage of a scripting component. Why would this be something that needs to be written?

It’s possible, but not really advisable. A scripting component should still be a scripting component, otherwise, it would not be possible to understand what it really is.

Hi @piac

My idea is implementing a switch, by clicking, user passes one or the other value to the output of the component.

EDIT: or the N-th value

All the stuff you are after is, in a way or anther, the modification of virtual methods in http://developer.rhino3d.com/api/grasshopper/html/T_Grasshopper_Kernel_GH_Component.htm

You will have to override the object Attributes, and pass your own instance. http://developer.rhino3d.com/api/grasshopper/html/P_Grasshopper_Kernel_GH_DocumentObject_Attributes.htm
The instance is implementing these methods:
http://developer.rhino3d.com/api/grasshopper/html/T_Grasshopper_Kernel_IGH_Attributes.htm

I would suggest implementing this in C#, as this is really involved in a object-oriented way and the interface was meant for a standard .Net language, so type safety is important. However, it’s also possible in Python.

On the old forum, you can find a breakdown of how methods are invoked (by @DavidRutten):

also, there are some discussions regarding Attributes on the old Grasshopper forum:
https://www.google.com/search?q=implement+attributes+site%3Awww.grasshopper3d.com

2 Likes

Thanks for the info @piac