Understood. I’m currently working on a series of tutorial content - you’ll have to bear with me in that example.
i got as far as this:
def get_leaf_node_indexes(data, indexes=[], results=[]):
"""
Recursive function to get all the indexes of the leaf nodes
in a nested dictionary.
:param data: The nested dictionary to traverse.
:param indexes: The list of indexes to keep track of the current node path.
:param results: The list of leaf node indexes to return.
:return: A list of all the indexes of the leaf nodes in the dictionary.
"""
if isinstance(data, dict):
for key, value in data.items():
new_indexes = indexes + [key]
get_leaf_node_indexes(value, new_indexes, results)
else:
results.append(indexes)
return results
indexes = get_leaf_node_indexes(data)
where data
is the incoming navis content and indexes
is the output you can use to extract the leaf nodes (geometry)
data = {
"level1": {
"level2a": {
"level3a": {
"leaf_node1": "value1"
},
"level3b": "leaf_node2"
},
"level2b": {
"level3c": {
"leaf_node3": {
"level4a": "leaf_node4"
}
}
},
"level2c": "leaf_node5"
},
"leaf_node6": "value2"
}
[
['level1', 'level2a', 'level3a', 'leaf_node1'],
['level1', 'level2a', 'level3b'],
['level1', 'level2b', 'level3c', 'leaf_node3', 'level4a', 'leaf_node4'],
['level1', 'level2c', 'leaf_node5'],
['leaf_node6']
]
I haven’t thoroughly tested this by using that list of lists to get the value of each leaf node. Perhaps that is a starter hint for you to try yourself, it will depend on your DynamoPython cred.
In the meantime, do you recall the trouble with receiving Navis commits directly?