algorithmic modeling for Rhino
Hi everyone, I think I have a little problem with something I thought very easy but unfortunately I cannot find a way to overcome it.
I did a component in python in gh to get out of a surface tesselation the points of each panel. Using .Branch(i) I can, in a loop, retrieve the element from the tree I have input.
My problem is when I want to OUTPUT a tree, I got stuck with the ArgymentTypeException telling me that the tree type expected and what I am feeding into it are not consistent:
Runtime error (ArgumentTypeException): expected IEnumerable[LineCurve], got LineCurve
So I can manage to export the elements flatten into a list but not as a tree. How can I do in this scenario (and in general with different types of geometries)? What is IEnumerable about?
Thanks a Lot!
V.
This is the script:
import rhinoscriptsyntax as rs
import clr
clr.AddReference("Grasshopper")
from Grasshopper.Kernel.Data import GH_Path
from Grasshopper import DataTree
import Rhino
b = []
tree = DataTree[Rhino.Geometry.LineCurve]()
for i in range(0,y):
a = (x.Branch(i))
branchList = x.Branch(i)
branchPath = x.Path(i)
line = rs.AddLine(a[0],a[2])
b.append(line)
tree.AddRange(rs.coercecurve(line),branchPath)
Tags:
Hi Vincenzo.
You should use AddRange when you want to add a list.
In this case just use Add to add a single line.
tree.Add(rs.coercecurve(line),branchPath) should work.
-Mostapha
Thank you a lot Mostapha!!!
Another question then, what if I would access / create a tree which has element in more than one level (like branches out of branches).
Is there a x.Branch(i)(j) command?
Or x.Branch(i).Branch(j)?
If it is not clear I'll try to make an example.
You can use (i,j). Something like this should work:
import clr
clr.AddReference("Grasshopper")
from Grasshopper.Kernel.Data import GH_Path
from Grasshopper import DataTree
from System import Object
a = DataTree[Object]()
branches = range(10)
paths = range(5)
for i in branches:
for j in paths:
p = GH_Path(i,j)
a.Add(i, p)
Welcome to
Grasshopper
Added by Parametric House 0 Comments 0 Likes
Added by Parametric House 0 Comments 0 Likes
Added by Parametric House 0 Comments 0 Likes
Added by Parametric House 0 Comments 0 Likes
© 2024 Created by Scott Davidson. Powered by