Grasshopper

algorithmic modeling for Rhino

Passing inputs to clusters and loading them into the document

Hi, I would like to include a component (cluster) loaded through a script given its file path.

I found a close solution on this thread, but I'd also need to pass an input to the cluster: would this be possible using a script or an add-on?

Regarding multiple inputs, if that helps, it would be fine to have just one input, structured as a data tree so that it contains all the needed data.

Thanks in advance for the help!

PS I'm using the latest versions of Grasshopper and Rhino

Views: 887

Replies to This Discussion

Hi Marco,

I'm encountering the same problem. So after so long a time, have you solved this?

Thank you for your sharing!

Hi Yijiang,

Actually I had come up with a workaround that worked.

Basically in my main definition I bake and save the geometry that I want to use in the external gh definition (which serves as a cluster), using a temporary .3dm file. 

 

The 3dm file is then used in the external definition to generate a new result, which is  then loaded in the main definition using a C# script, which gets the geometry from the cluster output components of the external definition:

In the external cluster the saved geometry is retrieved using the 3dm component:

And the final geometry is "sent" to a cluster output component, which is then retrieved by the script

I hope this is clear enough and helpful.

Marco

Just a side note: the Save component is from the Lunchbox plug-in.

Thank you for your help Marco!

Actually, I found the way out yesterday, getting inspired from James Ramsden's Blog.

I run a .gh format cluster saved at file_path and use it in a private function in my C# script.

Hope this can be helpful to you!

However, it makes me feel uncomfortable to pass the data like the following. Is there any other way to pass input data to the cluster?

//Create the component
var
cs = new CurveComponents.Component_CircleCNR();

//add the circle centre (input 0)
var pp = cs.Params.Input[0] as Grasshopper.Kernel.GH_PersistentGeometryParam<Grasshopper.Kernel.Types.GH_Point>;
pp.PersistentData.ClearData();
pp.PersistentData.Append(new GH_Point(new Point3d(0, 0, 0)));

Thanks for sharing again.

Yijiang

I misstyped the link of James's blog, here repost: 

link

Hi Yijiang, 

Unfortunately there are no real ways to programatically compute Grasshopper components, other than mimicking the actions that a user would do when manipulating the component in the usual way with a mouse.

The code you quoted above essentially mimicks the right-click action when you manually set the persistent data of a parameter. Like when you do this action manually, you have three things to do: choose which parameter to edit, clear the default value, and add your own value.

It is inelegant. But no elegant way was ever implemented.

If it is a real problem, the only solution I can offer is to see if you can re-design your component to not need to programatically access another component/cluster for calculation. Most Grasshopper functions are available programatically. For example, in my link, it would have been much easier if I'd used the following line instead of referencing the circle component:

Circle circle = new Circle(new Plane(origin, normal), radius);

Andrew Heumann wrote an interesting post about this a while back too, which you can read from here

Thank you James! :)

I asked a similar question a while back. Maybe this might help you? 

http://www.grasshopper3d.com/forum/topics/grasshopper-definition-as...

Thank you for sharing Dean!

But I think using saved cluster in external path could accelerate the computation.

RSS

About

Translate

Search

Photos

  • Add Photos
  • View All

© 2021   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service