List - Pick from index in order row

Asgardesign's Avatar

Asgardesign

16 Mar, 2021 10:44 PM

Hello, I'm using nodebox to make some generative graphics. I'm stuck and can't resolve even if I know it's conceptually simple.
I created a .csv with a series of Hex color values in the same column. I need to take a single row using an index to point the exact row. The node I need is a mix of "pick" and "switch", but the "pick" node pick have a random seed and the switch is used for multiple input. Are there any workaround?
Thanks in advance
A.

  1. Support Staff 1 Posted by john on 17 Mar, 2021 01:31 AM

    john's Avatar

    Hi Asgardesign,

    There are several ways to do this.

    If you have a simple list of values and you want to take, say, the 4th item in the list, you can use a slice node. Feed the list into the list port, set start index to the item you want, and set size to 1; that will return the item. When setting the start index remember that counting in NodeBox starts with 0, so to pick the 4th item you should set start index to 3.

    If you have a CSV with multiple columns and you want to pick a particular row based on the value of an index column, use a filter_data node. Feed the table into the data port, set Key to the column you are using to store your indices, set Op to =, and set Value to the value of your index. This will return all rows with an index equal to Value; if your index column has only distinct values (no repeats) this will return a single row.

    Since Filter_data returns entire rows, you will then need to feed the filter_data node into a lookup node to retrieve just your hex value.

    Notice I said that you need to set Key to "the column you are using to store your indices". When you look at a CSV table from NodeBox in Data mode it will show the first column with number indices (0, 1, 2, etc.) labeled "index". But that index column is not an actual column in your CSV and cannot be used as a key when filtering. To filter by index you will need an actual column in your CSV table with ID values you can use to identify each row. You can even call that column "Index" if you want and place numbers (0, 1, 2. etc.) in that column. Or you could call it "color name" and put unique color names in that column that can serve as identifiers to pick a particular hex value.

    If your CSV only has a single column (e.g. "hex") and you don't want to add your own index column, you can just use a lookup node (Set key to "hex" or whatever the column is labeled) on the CSV node. This will return a simple list of hex codes. You can then use the slice node on that list as described above.

    Please let me know if that all makes sense and solves your problem. If not, feel free to reply and attach your CSV; I will make a quick network for you that will return individual hex codes.

    Have fun!

    John

  2. 2 Posted by Asgardesign on 17 Mar, 2021 08:35 AM

    Asgardesign's Avatar

    That's perfect, many thanks :)

  3. Asgardesign closed this discussion on 23 Mar, 2021 10:37 PM.

Comments are currently closed for this discussion. You can start a new one.

Keyboard shortcuts

Generic

? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac

Recent Discussions

06 Jun, 2023 06:44 AM
12 May, 2023 10:17 PM
07 May, 2023 11:53 PM
07 May, 2023 04:43 PM
17 Apr, 2023 11:34 AM

 

15 Apr, 2023 01:31 AM
15 Apr, 2023 01:23 AM
14 Apr, 2023 02:54 AM
11 Apr, 2023 03:53 PM
08 Apr, 2023 09:59 PM
08 Apr, 2023 08:14 AM