There is replace items for a list.I wonder is there something similar for replacing branch contents?
Lists and Branches are basically the same thing. GH calls them ābranchesā as that fits within the ātreeā concept, but they are just List<T>
types.
I am not a programmer. I dont really understand what āListā means. I am just able thinking with ānormalā widgets. Are you saying that I can use the replace items widget for branches too? But how?
more specifically
http://grasshopperprimer.com/en/1-foundations/1-4/2_what-is-a-list.html
A list (or a branch) is an ordered collection of items. Thereās a first item (at index=0
), a second item (at index=1
), a third item (at index=2
), etc. You cannot have items at negative indices. You also cannot have items at index=n
without having items at all indices between zero and n
. Note that each item (sometimes also called āelementā) can be null. Null items lack a value entirely, but they still occupy a position within the list.
Technically a list can contain no items at all, if it has length zero, but itās debatable whether or not thatās conceptually really a list. Programmatically yes, within the Grasshopper UIā¦ maybe.
If you want to get the n
th item out of a branch, youād use the List Item component with an index of n-1
.
If you want to replace the n
th item in a branch with another value, youād use the Replace Items component with an index of n-1
.
Thanks but I know what a List is but there was āTā letter afterwards which was hidden because David put among special characters
Thanks David, maybe I misunderstand, but what you wrote works only if there is only one branch in the list. Because Replace Items will replace every nth item in every branch. And this is logical because every branch has its own āListā and the numbering starting again from zero.
What I want is to replace item not in all branches, but only in one specific branch.
What I am suggesting maybe a new widget would be nice which does the same thing with branches what replace item does with a LIST. Is there any solution for my problem?
Actually if you follow grasshopperās logic, it is really missing. See my figure. You can get a branch item called āTree Itemā, but cannot replace it? Why?
I have already designed how it will look like.
Ah, so you want to replace a single item in a tree. I think indeed that component would be nice to have and consistency seems to demand it, but in lieu of it @HS_Kimās solution is what I would recommend as well. Split Tree is very powerful and flexible and allows you to peel apart a tree and then put it back together again in the right order easily.
Hi Kim
It is very kind of you, that you put together this.
It is pretty complicated instead of the simple and logical widget. Does it mean regarding execution that it is slow comparing to a native widget I am recommending?
Slower, but probably not noticable.
@DavidRutten, I am getting an error when I select index -1 in Replace Items:
I ended up just using ListLength minus one, and that worked, but I thought -1 should workā¦
GH1.0.0007, btw.
tx,
dh
If you want indices outside of the (0, n-1) range to work the Wrap input will need to be true.
Ah, of course. Thanks!
Thank you so much, @HS_Kim, for your unselfish sharing!