Visualizing custom hierachical objects

Hey there,

I am implementing a set of my own objects (i.e. Python classes) that contain different representations of the same geometry. For example a Wall, can have Brep, Lines, Points, …

Is there a way I can define a default visualization such that when I select a component that outputs my objects (say, walls) in grasshopper it displays them as surfaces? A work-around is currently to access the underlying geometry in a separate component (like wall.surface)

I can’t really get my head around that, but other solutions like the BHoM elements do something similar. Like in the image below, where the visualization is comprised of the wall surface as well as the openings in that wall. I just could not find the respective code that does it…

Thanks a lot in advance!
Best,
Max

Phew, I’m pretty sure this is either not possible or really complicated using python. I have looked for a way to implement preview behaviour of custom python types myself in the past and didn’t really end up with a working solution. Some thoughts and hints on this anyway:

  • If I remember correctly the display behaviour of grasshopper datatypes ist determined by the methods DrawViewportMeshes and DrawViewportWires but it is not really possible/feasible to overwrite these on custom python types (please someone correct me if I’m wrong, this is from memory).
  • Grasshopper components also implement the same methods. The component methods can be overwritten using python, so you can control the drawing of the preview for the python component but only if you use the new GHPython SDK mode. An example can be found here: GhPython add-on compiler with example

Hope this helps in a way. I’ll be glad to know if you find a way to implement it also on the type/object level. Let me know if you need a sample file for the mentioned workaround.

Hey – yes. This is possible on a component level in GhPython, but it’s safer and easier to develop this in C#, where a debugger is also available.

Thanks

Thanks,

Giulio


Giulio Piacentino
for Robert McNeel & Associates
giulio@mcneel.com