Grasshopper

algorithmic modeling for Rhino

Hello,

I am an extreme rookie (just opened the program for the first time yesterday) and have a dumb question. I am making a series of lines that have specific edge and interior conditions (they are derived from research about shoulder and lane widths of various roads). In order to create adjustable lanes of road, all with the same ( but adjustable) width, I used array. I would like to figure out how to select the last line arrayed to create the final edge (shoulder) condition. I have uploaded the file for reference. Thanx

Views: 2758

Attachments:

Replies to This Discussion

Hi Diana,

Unfortunately I have an older version of GH with me so I cannot open your reference file correctly, but from what you wrote about it sounds like you simply need a List Item button to extract the line from the list created by the array.

When I am at my newer version of GH then I will take a look to make sure I'm suggesting something that is still useable.

 

Cheers,

Andrew 

Thank you for getting back to me so quickly. I am unclear how I would select the last item on a list that varies. I have included a screen shot, if that helps.

Attachments:

Here's the proper logic, not using the cheat I mentioned in my earlier reply:

  • We have a list of 6 items, all individual words. The first has index=0, the second item index=1, the third item index=2, the last item index=5. You can see these indices in front of the items in the first panel.
  • The number of items in this list is 6, the highest valid index is 5.
  • We can measure how many items a list contains using the [List Length] component. This component returns 6.
  • By subtracting one from this list length, we get the highest possible index, which is 5.
  • We then use this highest possible index to select the last item from the list using the [List Item] component.

As mentioned below, by using an index of -1 and wrapping set to True, we can get rid of two components. I suppose you could say there's a proper way of doing it and a smart way of doing it.

--

David Rutten

david@mcneel.com

Tirol, Austria

Hi Diana,

you can use the [List Item] component to select specific elements in a list (i.e. array) of data. The official way to select the last item would be to measure the length of the list (11 in your case), then subtract one and select the item at that index. Remember that items in lists are accessed using a zero-based system, so the first item is at index 0, the second item at index 1 and so on.

It's easier however to cheat and use an index of -1 and make sure Wrap is set to True. This will allow you to select the last item in a list without measuring the length of the list first. If you use -2 you'll select the second to last item, and so on and so forth.

--

David Rutten

david@mcneel.com

Tirol, Austria

That worked perfectly. Thank you sooooo much :)

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