[Solved] GHPyhon access to Grasshopper.GUI


(IVELIN PEYCHEV) #1

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


Button and context menu options on component through GhPython
Functions I want
(Giulio Piacentino) #2

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.


(IVELIN PEYCHEV) #4

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


(Giulio Piacentino) #5

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


(IVELIN PEYCHEV) #6

Thanks for the info @piac