Replacing branch content

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

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 nth item out of a branch, you’d use the List Item component with an index of n-1.
If you want to replace the nth item in a branch with another value, you’d use the Replace Items component with an index of n-1.

1 Like

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?
replace branch
I have already designed how it will look like. :slight_smile:
replace tree item

Take a look at the attachment. (13.8 KB)

1 Like

When If you want to replace more than one branches…

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.



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!