Shifting Path in C#

Hi all,

I have a DataTree in C# Scripting component and would like to reduce its path, for instance, {a;b;c} into {a;b} - same as the “Shift Path” component in Grasshopper. Does anyone know how? Thanks,

W

Hi @woojsung ,

Call the CullElement method on each data tree GH_Path, in order to shift them by -1. Then add all the shifted paths to a new data tree. Branches will automatically adapt to the shifted paths.
Here is python code, but I am sure you can convert it to C#:

branches = dt.Branches
paths = dt.Paths


# shift paths by -1
newPaths = [p.CullElement()   for p in paths]


# add all branches to a new data tree with shifted paths
dt_shifted = Grasshopper.DataTree[System.Object]()

for i in xrange(dt.BranchCount):
    dt_shifted.AddRange(branches[i], newPaths[i])

@djordje,

Thanks for the reply. I will try this in c#. Thank you.

W