Grasshopper

algorithmic modeling for Rhino

Is there a way to "nest" functions in grasshopper? Something like:

fn( fn( fn(a,b), fn(a,b) ), fn (a, b) )

I tried using delegate/ anonymous functions in C# and had some success. However, I cannot seem to go more than one level deep. This is based on an answer to someone else's question, here.

For example, this shows a working script where a function is defined in one c# node then solved in the second node. The "Make box" components pass a function to the "execute delegates" component, which then assigns variables to the anonymous function and solves based on those vars.

The next image shows how the "Execute Delegates" node only tries to solve one layer down, and so it expects two Breps, instead of knowing that it should solve "bottom up", by generating the Breps, then joining them (the join is defined as another deferred/ anonymous function, within the "Boolean Union" node. To be clear, all nodes shown are custom c# nodes.

I also attached the Grasshopper file, as seeing the code is probably helpful... Thoughts?

Views: 689

Attachments:

Replies to This Discussion

I don't understand. The last C# component tries to invoke a delegate which takes two breps, but you're giving it three points. Was this supposed to work on points?

MakeBoxA and MakeBoxB each return a delegate function which expects three points and creates a brep. Id like to have the "Execute Delegates" components solve those delegates, then use the resulting breps to solve the Boolean delegate function.

That's not the way function nesting works in C#. Delegates are only described by their signature, not their contents. Once you put one delegate inside another delegate, nobody will ever be able to figure out it's in there.

What you're after will involve you designing an entire system which maintains delegate functions separately, and can figure out on its own how to invoke them in turn and which arguments are supposed to go into each one. This is not exactly trivial.

Ok, thank you. Im going to try a different route then.

RSS

About

Translate

Search

Photos

  • Add Photos
  • View All

Videos

  • Add Videos
  • View All

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service