Hops Tree Parameter Access

Hi @stevebaer I’m trying to input a tree into a Hops component with hs.HopsParamAccess.TREE
and getting an error that doesn’t provide much info:

Here’s a sample of my code:

@hops.component(
    "/treetest",
    name="TreeTest",
    description="Test Tree Input",
    icon="examples/pointat.png",
    inputs=[
        hs.HopsInteger("Integers", "I", "Integers in a tree", hs.HopsParamAccess.TREE),
    ],
    outputs=[
        hs.HopsInteger("Output Integers", "O", "Output integers")
    ]
)
def treetest(int_tree):
    return int_tree

Do you see anything wrong there?

I would stay away from tree input and output if you don’t need it. We haven’t done a whole lot of work in this area and it is pretty infrequent when you actually need to work with a tree in your function.

Do you really need a tree for input to your function? It’s pretty rare even in core grasshopper components for this.

I wouldn’t say it’s too rare, at least not for my daily workflow. For instance, if I’m trying to bring many many vectors of n-dimensions, I would put each of them into a list an pass it as such.

How would you pass a nested list from GH to CPython through Hops instead? Is there any other object that can handle this transaction?

WHAT?!?!!

I knew I was going to get flack for writing that. I should just resolve to writing nothing but bug reports here. I asked a question and provided a fact about core grasshopper, nothing more.

I understand that there is a need for tree input, but the majority of core components in grasshopper are item or list input and allow grasshopper to perform the iteration when trees are provided as input.

I added this to our buglist at

and will see what is going on.

Considering that data trees have always been at the core of Grasshopper, yeah, the statement was a surprise (to put it mildly).

Tree inputs and outputs are properly handled for components that have item and list access

@dadandroid the Hops component doesn’t actually support tree parameter access on the inputs. The component should be defaulting to list access and may well be throwing an error because the first list is empty (assuming you’re using the default inputs for the Series components). Strangely on my Mac I get a warning instead of an error.

The error because you have an empty branch (the first one) and you don’t need use tree access

@hops.component(
    "/tree",
    name="tree",
    description="test",
    icon="",
    inputs=[
        hs.HopsNumber("input", "i", "test")
    ],
    outputs=[
        hs.HopsNumber("output", "o", "test")
    ]
)
def tree(input):
    return input

That form calls the python server with one item at a time and then relies on GH to construct the output tree. David is looking to get at the whole tree at once.

2 Likes

FWIW I got around this by serializing the nested list into a json formated string and back, which seems to work since it’s a nested lists of integers. Probably won’t be so easy for other types, though

2 Likes

@dadandroid I just updated both Hops (0.5.0) and ghhops-server (1.3.0). This version supports passing trees from grasshopper to the python server.

2 Likes

Following up on Tree outputs.

Is there a streamlined method for converting list of lists to Trees for outputs?
Thanks

1 Like

@Hamilton_Forsythe what you can do is output a (flattened) list of geometries in one hops output, and the list lengths in another to rebuild the tree structure in Grasshopper.

It’s a workaround I’ve been using as well, but it becomes more tedious when the desired tree output should have more than one branch level.

Imagine now that the desired tree output could have different branching level depending on the inputs… yikes !

I’m wondering if hops is intentionally left to die for the new python3 in rhino8…
I wouldn’t be against it, as I would not be against a statement from the devs either :sweat_smile:

1 Like

Python3 in Rhino8!?! I’m so excited. I feel like all I do now-a-days is work around IronPython Limitations haha

1 Like

Hi @dadandroid, I met the same issue.
Can’t image that hops has such a problem of handling data tree…
Could you please be more specific on your method of JSON format?
Thanks!

Hi @antoinemaes,
Exactly the same feeling!!

Hi @dadandroid,
I don’t think the problem is settled down.
In the example, after the tree of number is imported in hops, the type of the data is not ‘list’, but ‘float’.
That means you can’t take out each item in the each for further processing.