Grasshopper

algorithmic modeling for Rhino

Hello!

I am working on a project involving Object-Oriented Programming with IronPython, and then actuating them in Grasshopper to obtain "physical" Rhino geometries as results. 

Component A, outputs an instance of a class type, which I refer to as Class Instance A for this discussion post.

Component B, has a for-loop, through which it does a few things, and makes "n" number of variations (in this case, just 3) of Class Instance A. Simplified/generalized structure of Component B is as follows:

a=[]

for i in range (n):

.....variation = DoSomething (StartShape)

.....a.append(variation)

.....for obj in ghenv.Component.OnPingDocument().Objects:

..........if obj.Name == "MakeAssembly":
...............obj.ExpireSolution(False)

I am not sure if I am using the ExpireSolution method correctly here. I also have found this (Grasshopper.Instances.ActiveCanvas.Document.NewSolution(False)) from some other discussions, but it doesn't seem to solve this problem. Or maybe I have the placement of ExpireSolution or NewSolution wrong. Upon pressing F6 then F5, Component B keeps updating Class Instance A, instead of "resetting" it to its original condition. For-loop in Component B must have the original Class Instance A every time, in order for it to spit out variations. I need to find a way to expire the solution for Component A only, at the end of each For-loop. Eventually, I need it to loop 100+ times, so manually pressing F5 is not really an option... Below is an image of what should happen:

What is the best way to tackle this problem (in either Grasshopper-Python or IronPython), so that the same original Class Instance A is fed in every time the loop is run in Component B?

Thank you! 

Views: 1956

Replies to This Discussion

Hi Juney

you should not expire a solution from within a solution and then request a new solution.
This is not really expected by Grasshopper.

Why are you not simply doing the computation 100 times in the component A to begin with? Is it for previewing?

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

Giulio,

Thank you so for your response! The reason why they were two components, was so that I could keep them as separate components for clearer organization and future use. I tried combining the two components into one Python component. The result is the same...

Below shows three images, where I pressed F5 three different times. As you can see, the StartShape and the variations (supposedly) are all the same. End goal is to get these three different results with one F5, instead of having to press it manually.

Turns out, I did not have to deal with NewSolution() or ExpireSoultion() at all. I used deepcopy() to make duplicates of the class object for every loop, and it worked. This essentially prevents the original Class Instance A from changing. Below is the updated diagram of the flow, in case anyone has similar problems and is interested.

RSS

About

Translate

Search

Photos

  • Add Photos
  • View All

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service