Match "content" array index to tree branch

Hi,

I want to be able to select an individual object out of 29 objects in a scene similar to this tutorial: https://support.shapediver.com/hc/en-us/articles/360023385492-Tutorial-User-interface-with-clickable-3d-objects.

I am using a web page with JavaScript and the embed ticket to access the ShapeDiver model. All of my 29 objects from my scene go into a single asset (different from the example). This is because having each object as a distinct asset (as in the example), I would have to define 29 ShapeDiverDisplayGeometry components in my Grasshopper script – one for each object – as far as I understand the example. Any change in the number of objects in the scene would require to adjust the number of ShapeDiverDisplayGeometry components in the script accordingly. Thus I prefer to have all 29 objects in a single asset.

I intend to access them individually by their index in the “content” array of the particular asset (holding 29 objects).

Now I am wondering if there is a way to determine in advance which index in the “content” array each of the objects will have in the ShapeDiver asset? I want to output additional attribute values for the selected object which are present in the Grasshopper script. Since I do not know which tree branch (index) does match which of the indices in the “content” array, I am not able to filter the data accordingly.

Maybe my approach is not correct. Any suggestions?

Thanks,
Eduard

You don’t need to use separate ShapeDiverDisplayGeometry components. Simply use one and make sure to structure the data tree in a predictable way, for example using a pattern {0}, {1}, {2}, etc… with a simple ordering of the branches. Then the content array of the online asset will match the order of the branches in Grasshopper and you will be able to access and select them individually.

You can edit/modify the contents of these two clusters if you must - vTrE and vList - all standard GH components so will work fine with ShapeDiver. Use them together as shown or separately.

Hi @pavol,

thanks - it worked! But for an unknown reason I get only 22 objects in the content array although I am feeding in 25 branches in the Grasshopper definition:

Thanks,
Eduard

That is the assets overview of the scene. As you can see there is only one asset named zoneAttributeValues present:

What would be the equivalent code for the ShapeDiver Viewer v3 to list all assets?

api.scene.get(null, "CommPlugin_1").data

And then show or hide them, based on their name?
Thanks!