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

Hi Anders,

I think I solved the problem partially. These are the main events that you can track in a ghPython component:

#ghenv.Component.PingDocument
#ghenv.Component.AttributesChanged
#ghenv.Component.DisplayExpired
#ghenv.Component.ObjectChanged
#ghenv.Component.SolutionExpired
#ghenv.Component.Params.ParameterChanged

# ...

The first one solved my problem with changing the input value. I uploaded the fixed version if you want to check.

I should still look for GHDoc events so I can add/remove the handler for alt+tab, etc...

Cheers,

Mostapha

Excellent work Mostapha, one giant leep as they say :)

I can't seem to open the file, probably because I am still running GH 0.8.00.66 and GhPython 0.5.0.0 (holding on for a more stable 0.9+ Python component due to a project I'm working on). Would it be possible to post the source as a text/.py file?

Thanks again.

Best,

Anders

 

Thanks Andres... Attached is the .py file.

Attachments:

Cool, thanks Mostapha. Looks good :)

RSS

About

Translate

Search

Videos

  • Add Videos
  • View All

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service