Select multiple data paths permutations

data paths permutations.gh (20.1 KB)
My question is whether this is possible without using Python. The idea is to have a tree with multiple paths as items where each branch has a permutation of all possible paths minus the current one. From those I want to select paths from another tree. In the other tree are branches with single or multiple items so the result tree should have a sublist. For example all paths with 0 or 1 items should end with “;0” while the ones with multiple items should end with the corresponding item index. Gemini did the python script.

python

import Grasshopper

from Grasshopper.Kernel.Data import GH_Path

from Grasshopper import DataTree

# Fixed: ‘object’ as a type inside brackets, followed by instantiation parentheses ()

output_tree = DataTree[object]()

if Paths is not None and Data is not None:

print("Processing {} paths branches...".format(Paths.BranchCount))



for i in range(Paths.BranchCount):

    try:

        target_path = Paths.Path(i)

    except:

        target_path = Paths.Key(i)

        

    branch_paths = Paths.Branch(i)

    

    for p in branch_paths:

        try:

            \# Clean and parse the path value safely

            if hasattr(p, "Indices"):

                gh_p = GH_Path(\*p.Indices)

            else:

                clean_str = str(p).strip("{}\[\]() ")

                if ";" in clean_str:

                    parts = \[int(x) for x in clean_str.split(";")\]

                elif "," in clean_str:

                    parts = \[int(x) for x in clean_str.split(",")\]

                else:

                    parts = \[int(clean_str)\]

                gh_p = GH_Path(\*parts)

            

            \# Directly try fetching the branch items

            source_items = Data.Branch(gh_p)

            if source_items:

                for item in source_items:

                    output_tree.Add(item, target_path)

        except Exception as ex:

            pass

a = output_tree

Thank you in advance!