algorithmic modeling for Rhino
Hi there,
I'm trying to make a multi threading ghpython component to run in paralel a command for booleand difference.
I have a series of bpreps that each need to be cut with 4 other breps.
I've atached a grasshopper file and ghpython script that i came up with. but still i cant figure out how i can transform it into a paralell run script.
Any help is appreciated.
Thank you,
Ionut
ghpython node code:
import rhinoscriptsyntax as rs
import ghpythonlib.components as ghcomp
import scriptcontext as sc
import Rhino
import ghpythonlib.parallel
#for accesing gh classes
import clr
clr.AddReference("Grasshopper")
from Grasshopper.Kernel.Data import GH_Path
from Grasshopper import DataTree
mytree = DataTree[Rhino.Geometry.Brep]()
for i in range(0,x.BranchCount,1):
sub1 = x.Branches[i]
ins1 = y.Branch(i)
diff = []
diff = Rhino.Geometry.Brep.CreateBooleanDifference(sub1,ins1,0.01)
if diff: mytree.AddRange(diff)
a = mytree
Tags:
Hi Ionut,
Parallel's run function needs some list or tuple to work on.
That leaves the original Brep data tree out of it. But you can use the branches paths as a list:
import Rhino
import ghpythonlib.parallel
import Grasshopper.Kernel.Data as ghp
import Grasshopper.DataTree as ghdt
newTree = ghdt[Rhino.Geometry.Brep]()
paths = x.Paths
def boolD(_paths):
diff = Rhino.Geometry.Brep.CreateBooleanDifference(x.Branch(_paths),y.Branch(_paths),0.01)
path = ghp.GH_Path(_paths)
newTree.AddRange(diff, _paths)
return diff
if parallel:
ghpythonlib.parallel.run(boolD, paths, False)
a = newTree
Btw, I use a different notation for importing DataTree and GH_Path, than you. Do not be confused with it.
You may need to refresh your data parameters once you download the attached .gh file (meaning copy the original ones). It's the issue grasshopper issue.
Hello,
Thank you very much for the thourough explination, it realy makes sense when written like this.
Also i like the fact that you pass a list of tree branch values for the parallel function. I saw that it can only handle one list of items but coudnt figure out what to use. Yours is a very elegant function.
As far as notations, this was my first python script and the coding was quite sloppy. Im still getting the hang of it.
The good point is that it works like a charm.
Tahnks again.
Ionut
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