How do you extract the raw data / scrub unwanted data from a panel?

Hey all, I’m currently stuck with a weird issue in GH with managing data and I’m wondering if someone here can help me find a resolution or point me to some resources I can use to resolve this issue.

Thanks to some amazing help from inno, I was able to create a script that turns a surface/domain into a bunch of 1’s and 0’s which feed into a python program. When I plug my script output into a panel (top panel) everything looks exactly how it should and the data is formatted exactly how I need it.

However, if I copy and paste the output using the ‘copy all data’ button, it brings over header elements that break my script. If I plug the panel into my python script it breaks as well. If I copy just the raw data, then only the data in the body of the top panel is brough over and the script works just fine.

Is there a node to ‘scrub’ out that unwanted data and/or just extract the pure raw data from a panel? Any help would be greatly appreciated and source files are included below.

Maze Base.3dm (77.6 KB)
Maze Solver GH.gh (41.6 KB)

Image of the data output and what copy/pasting the “All Content” option looks like. You can see the unwanted data circled that I need to scrub. I’m almost positive that it’s those two elements in the panel that are what’s breaking my python script.

Python solution works when I copy and paste the raw data from the top panel

Python solution fails when I just shoot the output straight into the y input

You probably shouldn’t transform your data to text, you’ll make it only hard for yourself.

Instead of pushing your integers tree from the identity floor group through the two Python components before you get to your last Python component just directly connect that to your last Python component.

Then on the y input transform the tree to list of lists and use that instead of working with text data (which is what the out sockets really are: the data printed in text format).

So:

  1. set y input socket to tree access,
  2. import the tree helper module at the top of your last component:
import ghpythonlib.treehelpers as th
  1. change the tree to list of lists
y = th.tree_to_list(y)

Then do you work with y instead of a and at the end do

a = th.tree_to_list(the_path).

Again: don’t transform your data into text and use that, use the actual data.

Here a very simple example:

simple_treelist_example.gh (8.9 KB)

1 Like

Thank you for help! I had completely forgotten to set the access as tree access. Importing that module / function fixed a huge amount of my issues - going to be checking that in the future from now on.

I’m now running into an issue where the data from the tree has lost it’s matrix table like presentation (a 60x60 grid) and the data is being spewed out in an insanely long line. It seems that the line breaks ( \n ) are are being ignored and I’ve got some strange data that I wasn’t expecting at the start ( [[[[, ) and end ( ,]]]] ). Without it being in that grid pattern my program breaks from an index out of range error.

Is this expected behavior of the tree_to_list function in the treehelpers module? If so, is there a way I can convert that data dump to fall in-line format wise with the 60x60 grid I need?

Sorry if what I wrote is a little hard to follow, I’m still new to Python and learning as I go.

Based on the screenshot it looks like you are still using out socket. I told you to not use that, since that is text based. At most the out that gets filled by Python print calls should be used for debugging, not for relaying data between components.

Seeing that you have a \n in the panel it looks like you are still wanting to format the text. You are handling the wrong data.

I don’t have lunchbox, but let me create a second sample that hopefully highlights better what I was trying to say.

addendum:


maze_solver_hinting.gh (7.3 KB)

I cleaned your original script a bit and added a safeguard against eternal looping because the number grid I create is pure random and won’t give a result.

Anyway, the tree helper gives as result a list that contains the matrix, so take that first item out.

Note that I do not rely on print output on the out socket anywhere. For debugging purposes you can use print and look at out, but do not use that as a way to do computation and communication between components.

Note also that the maze solving Python component has the input maze set as tree access, and that the type hint is set to int. This is important for it all to work properly.

1 Like

If you absolutely need to pass string representations (i.e. text) of lists around - which as Nathan already pointed out is not recommended -, you need to parse them back to being Python lists to be able to use them as such!

Check this out for how that’s done:

In Python, you can always print(type(foo)), if you want to know the type of an object.

1 Like

@diff-arch and @nathanletwory Thank you both so much for the help. I was able to follow a lot of the guides you gave me and realized where I was handling the data incorrectly in my script. It is now functioning exactly as I hoped it would and this is resolved now. Thank you!

2 Likes