Select Multiple Data Paths Permutations

data paths permutations.gh (20.1 KB)
My question is whether this is possible without using Python and how it’s done. 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!

Yes. :upside_down_face:

Ok. Forgot to ask, how?

Your script doesn’t make sense at the moment. If there are 14 branches to the Data container, then there must be 14 to the Data Path container, no?

I’ve recreated what I assume you meant:
data paths permutations VR 1.gh (51.0 KB)

In case you did mean it the way you did:


data paths permutations VR 3.gh (45.9 KB)


I’d sooner work from the the paths you want to permute against though:


data paths permutations VR 2.gh (74.0 KB)


And use the original branch integers in the resulting branch addresses:


data paths permutations VR 4.gh (48.1 KB)

The VR 3 is the right one, I see that Branch while in renumber mode its able to actually pick all the branches and the later match tree changes it to the correct path address. Thank you looks really good.

I have another question, on the VR 1, can you explain how the Cross Reference with Diagonal mod is used for?

This is how I was creating the paths permutations:


Select Multiple Data Paths Permutations - Cross Reference Explanation.gh (56.9 KB)

Thank you very much, again.