Grasshopper

algorithmic modeling for Rhino

How to find order of instantiated components on canvas

This may be one for David.

I am retrieving a grasshopper component from the canvas. If the components are of the same type, say a point component for instance, how is it possible to determine the order of construction of each point component on the canvas? i.e. which point component was the most recently constructed?

 

Views: 949

Replies to This Discussion

No. The only order is the Draw order, which can be changed by the user.

--

David Rutten

david@mcneel.com

Poprad, Slovakia

Does the draw order tothe order components are solved during a solution? I wodnt have thought u could drAw a downstream component if the inputs related to a up steam component hadnt been solved first

Solution and Drawing are not related processes. The order in which objects are solved has nothing to do with the order in which objects are drawn. Indeed, objects which are beyond the bounds of the canvas are never drawn but could be solved, and objects which haven not expired are never solved but can be drawn.

Generally, new objects are put at the top of the draw stack, so the older the object the more likely it is to be near the bottom of the list. However as soon as one of the items in the Arrange menu is used this order may be fractured.

--

David Rutten

david@mcneel.com

Poprad, Slovakia

Got it. Makes total sense.

So there is no way to understand the solution order. i.e. if we have five point components on the canvas say A B C D and E, where E is the lower most downstream component, how do I make sure I select E and not A through D?

You can certainly figure out which of all the point components is the leftmost one (or rather; "which are the leftmost ones" as components can be in parallel positions).

There's a FindAllDownstreamObjects() method on GH_Document which allows you to find all objects that rely on a starting object. There's no way to quickly find all upstream objects.

Another possibly fruitful line of inquiry would be CreateConnectivityDiagram() on GH_Document. It gives you a class which only represents the connections between objects, so it's easier to traverse and search it.

--

David Rutten

david@mcneel.com

Poprad, Slovakia

David, thank you for the reply.

Hope this is not too tedious for you.

I understand what you are saying but I don't think it helps if these components are not connected to one another.

This may be a dumb question, but as I understand it, the position of the components on the canvas does not dictate the order in which calculations are completed when initializing a solution. It depends on the order in which the components were laid on the canvas. i.e. for point A B C and D on the canvas where the inputs are reference geometry selected in rhino and not up stream components, and rearranged on the canvas in this order top to bottom:

A
B
C
D Solution order is ABCD

if we arrange in top to bottom alignment

C
A
B
D Solution order is still ABCD

if we rearange to

A B C D Solution order is still ABCD

if we arrange to

D A B C Solution order is still ABCD

if we add a new component and move to start

E A B C D Solution order is A B C D E

I'm guessing may be the order of components in a solution is given by the index returned by FindObjects method? This would tell me which component on the canvas is first in a solution.

Steve

The order of components that are solved is highly unpredictable. Mostly because components can request other component be solved while they themselves are being solved. Basically, this is what happens:

  1. Something changes, say, you drag a slider.
  2. This causes the slider object to be expired.
  3. The slider then expires all its targets which are not already expired themselves.
  4. These targets then expire all their targets which are not already expired, and so on and so forth until there are no more targets left to expire.
  5. A new solution now begins.
  6. The solver picks an expired object -pretty much at random- and tells it to solve itself.
  7. This object must first collect all input data, so it asks all its sources for their data. If one of these sources is expired, it must first be solved (this is where the recursive nature of the solver comes in).
  8. Once the object has collected all data and solved itself, control is handed back to the solver, which now picks the next expired object and tells it to solve itself.
  9. This repeats until there are no expired objects left.

To make things more complex, Grasshopper decides to solve certain types of objects first. This is a part of the program which is most likely going to change a lot as well in the near future.

If you are looking to find the point component that is furthest towards the right (highest X-coordinate) then it's fairly easy to do that. If you want to find a point component that is last in the data inheritance, that too is do-able, though somewhat more work. I'm not really sure if you are actually looking for these characteristics or if you want something else.

It is true that the x,y position of components on the canvas is utterly irrelevant when it comes to solve-order.

--

David Rutten

david@mcneel.com

Poprad, Slovakia

RSS

About

Translate

Search

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service