Grasshopper

algorithmic modeling for Rhino

Hi All,

Following David's example in this thread I have been trying to implement the RhinoCommon CustomDisplay class, but using Python instead of VB. I think I got the basics down of how to add an instance of the class, add some custom geometry to it and update it properly (i.e. do a "redraw") each time the component inputs update (see the attached file for an example). You will notice that there is a boolean toggle which takes care of adding the geometry to the CustomDisplay when "True" and disposes of it when it is set back to "False". Now my main problem is how to dispose of and delete my CustomDisplay instance when the following events occur:

1) If the user alt+tabs to another Grasshopper document.

2) If the user closes the Grasshopper document

3) If the user closes Grasshopper

From David's example I've deduced that one needs to access the Grasshopper SDK and get the current "GH_Document" (see also this thread) and then from there make calls to this document and see whether it is enabled etc. I've barely scratched the surface of accessing the GH SDK from Python (except this), so I'm a little lost at sea here! I have tried trawling through the SDK documentation, but I am having a hard time translating most of the calls to Python. For instance how to get the current GH document using this.owner.OnPingDocument();

Any pointers would be greatly appreciated!

Thanks,

Anders

Ps. It would be great to add the two circular point display modes to the CustomDispay as described in this request.
 

Views: 5919

Replies to This Discussion

It is quite difficult to do this. If you only want to draw geometry while the GH_Document you're in is drawing itself, then it is far easier to override the DrawViewportMeshes and DrawViewportWires methods. However I don't think you can do this in a python script component.

There are plenty of events in Grasshopper that signal changes in active documents etc. but I have no idea how Python handles events.

I attached a C# script component which maintains a local CustomDisplay instance and which responds to document swaps on the main canvas.

--

David Rutten

david@mcneel.com

Poprad, Slovakia

Attachments:

Thanks David,

I suspected that it might be difficult to access such functionality via Python, maybe I'll try the Rhino.Python board and see if Steve or someone else has tried doing anything similar.

It is not really that big of a deal, but I do occasionally forget to flip my DisplayToggle back to false before closing the Grasshopper definition. Which of course means that I have a CustomDisplay lingering about which I have to restart Rhino to get rid of.

Would it be possible (using RhinoCommon) to somehow dispose and delete any and all instances of CustomDisplay? A sort of general cleanup on aisle three for the drowsy and forgetful :)

It is certainly possible to add such a feature, but it won't be able to distinguish between CustomDisplay instances that ought to be cleaned up and someone elses CustomDisplay instances that need to stick around.

There are better ways of doing this sort of thing. For example, we could make it so that you can assign a GUID to any CustomDisplay instance, then later ask for all instances that match a certain GUID. This will mean you cannot get access to someone elses CustomDisplay unless you know what GUID they used.

However something as awkward as this needs to be discussed in depth with the Seattle HQ guys, so I certainly don't want to commit to anything now.

--

David Rutten

david@mcneel.com

Poprad, Slovakia

Reading it back it does seem like a rather awkward approach actually! It works just fine for anything I can imagine doing with it as of now, so I really wouldn't worry about it. In fact the whole CustomDisplay class is really rather cool and intuitive I find.

The only (indirect) request I would ask is to add the circular point display to the PointStyle Enumerations, so that one can use them in CustomDisplay (with radius, color etc.). I tried airing the idea on the Rhino 5 forum without any response. Since I noticed that you added the option to preview points in Grasshopper in using these new styles, perhaps you would have some say in this regard?

Hi, not sure if this thread is still alive.

I achieve the function in pretty simple code by copying your code.

But the problem is whenever I move the curve, the original display does not disappear...

Not very familiar with doing lower layer of Rhino thing...

Any thoughs?

Attachments:

Hi Anders,

Steve actually has an example for add and remove handlers in python -> StarMaker

class CustomObjectDraw():

    # calcute bounding box for updated objects
    self.UpdateGeometries(self, object_ids)

    # calculate new dipslay bounding box
    rc.Display.DisplayPipeline.CalculateBoundingBox += self.MyDisplayCalBBox

    # draw the objects
    rc.Display.DisplayPipeline.PostDrawObjects += self.MyDisplayPostDrawObjects

   

    def RemoveHandler(self, sender, e):

       # this function removes the conduit
       rc.Display.DisplayPipeline.PostDrawObjects -= self.MyDisplayPostDrawObjects
       rc.Display.DisplayPipeline.CalculateBoundingBox -= self.MyDisplayCalBBox
       sc.doc.Views.Redraw()

I tried to use this method in a simple script:

(http://www.grasshopper3d.com/forum/topics/how-to-remove-objects-dra...) but I didn't know how to track the changes in the component (e.g. if any of the input changed remove the handler) so the display lingers in the screen! Hope you can solve that part and then it will be all solved!

Mostapha

Hi Mostapha,

I somehow completely missed this example on the Rhino.Python forum! Thanks for bringing it to my attention. Looks like it could provide some further clues into drawing "dynamic" geometry from Rhino.Python. Pretty slick use of windows forms as well, very inspiring indeed.

I think I will start a new thread "over there" focusing on best practices for doing this kind of stuff. I'm sure that things have must evolved in the two+ years since the Starmaker example was posted (i.e. David did the CustomDisplay class etc.). To be continued... 

Nice! Fingers crossed!

Anders,

Seems this is the way to get the Owner.OnPingDocument in a GHPython component. I don't know how to use it though:

ghenv.Component.Attributes.Owner.OnPingDocument

Hi Mostapha,

Nicely done! I will for sure look into to this again once I get a bit more free time. In continuation of the thread, I've come to not think of this as a big deal when using a switch for the custom display. That said it would still be great to figure out how to access the required functionality. Looks like Steve may have a look into this at the Delft Hack Fest. Fingers crossed indeed ;)

Hi Anders... awesome! That sounds really good! I hope Steve finally put an end to this discussion... Indeed! ;)

RSS

About

Translate

Search

Videos

  • Add Videos
  • View All

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service