Permutations of datatree branches


So I’ve been looking for this function for a while and thought I should share the sollution now when I have figured out an answer.

The question was - How do I get every possible combination of a set of branches in a data tree?

After some digging and trying out python in grasshopper I came up with the following sollution:

    import itertools as it
    import Grasshopper as gh

    y = x.BranchCount

    Kombinationer = it.permutations(range(y))

    a = []

    dtb = gh.DataTree[object]()

    for index,value in enumerate(Kombinationer):
        for ie,ve in enumerate(value):
            branchList = x.Branch(ve)
    a = dtb

It takes a datatree “x” and outputs all permutations of it’s branches as “a” while keeping the order of the items in each branch intact.

When you go above a length of 7 branches, it starts to become slow, so if anyone has an Idea of how to make it faster, that would be great to know!

Permutations of (15.7 KB)