Grasshopper

algorithmic modeling for Rhino

Hello,

How can I cause specific components in my Grasshopper definition to bake their contents to the Rhino document?

I found this tutorial that does it from Rhino's Python editor, but I need to do the same from within a GHPython script.

Cheers,

Max

Views: 784

Replies to This Discussion

Hi Max

good discussion but... do you need exactly this in Grasshopper?

This won't be as easy as writing the script from the other window (from the EditPythonScript editor). The reason is that when a GhPython component is computing, it might well be that the other part is not computed yet. If you need to bake in GH, I would suggest that you use one of the baking components (also in script) that exist out there.

Please let me know if they would not work for you.

Thanks

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

  • I am not sure this will answer your question but there is the selectable preview node by Alan Tai that dynamically bakes grasshopper data :

http://www.food4rhino.com/project/selectablepreview?etx

It has other purpose than baking and it appears to be in C# though.

  • If you don't need the baking to be 'dynamic' you can use Lunchbox or Human but you probably know that (I guess that's what Giulio was referring to).
  • If you need it to be dynamic and in Python then I don't know how to help!

What's 'dynamic' in this context?

If you mean to delete the previous outcome of the iteration, that is also possible to do also in a script. I am not sure if there is a pre-made component for that, but it would be possible also from there.

Let's see what Max needed before speculating.

import Rhino as rh
from System.Collections.Generic import *
from System import *
ghdoc = ghenv.Component.Attributes.Owner.OnPingDocument()
rhdoc = rh.RhinoDoc.ActiveDoc
componentsToBake = [x for x in ghdoc.ActiveObjects() if x.Name == "Mesh Sphere"]
for component in componentsToBake:
    ids = List[Guid]()
    component.BakeGeometry(rhdoc,ids)

Change "Mesh Sphere" in the above to find the component you're looking to bake. As Giulio points out, there is no guarantee that the object in question has finished solving, since this script is executed during a solution - so use w/ caution. 

Please... add a big warning at the beginning of the script.
Otherwise, later someone will get bitten.

Thanks a lot everyone for your help!

Andrew's script actually does exactly what I was looking for.

I can understand why Guilio has his concerns, but it seems to me that if I simply connect the components in the order in which I want them to execute, it seems to work fine? (See attached)

Cheers,

Max

Attachments:

RSS

About

Translate

Search

Videos

  • Add Videos
  • View All

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service