Ghpython Data Problem

Hello Forum, I am currently facing an issue with a GhPython script I am developing, specifically with maintaining my data structure when trying to divide curves to obtain their points. The script either returns a flat list or generates nested lists in the form of “System.Collections.Generic.List” that I am unable to extract properly.

I am attaching the relevant portion of the script below, which is the last part where the issue occurs. I would appreciate any insights or suggestions you might have.

Here is a snippet of my current code:

# Create DataTree for the divided points
Divide_Points_1_tree = DataTree[object]()

# Define the number of divisions and kinks parameter
count = 4  # Number of divisions
kinks = False

# Iterate through the branches of Explode_1_tree maintaining the structure
for i in range(Explode_1_tree.BranchCount):
    branch = Explode_1_tree.Branch(i)
    path = Explode_1_tree.Path(i)  # Maintain the DataTree structure

    divided_points = []

    for curve in branch:
        # Divide the curve into points with the same parameter
        divided = gh.DivideCurve(curve, count, kinks)[0]  # We only get the points

        # Ensure the output is a list and extract properly
        if isinstance(divided, list):
            divided_points.extend(divided)
        else:
            divided_points.append(divided)

    # Add to the DataTree while maintaining the original hierarchy
    Divide_Points_1_tree.AddRange(divided_points, path)

Custom = Divide_Points_1_tree


Ghpython_Problem.gh (18.2 KB)

In this script, I am attempting to pass data that initially comes out nested within a “System.Collections.Generic.List” from the output. When I try to use this data in another script as shown above, it still remains nested in lists of lists. How can I mitigate or fix this issue in a Python script to ensure a cleaner and more manageable data structure?

Thank you very much for your time and help.

Best regards,

Henry :slight_smile: