Grasshopper

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

Views: 1195

Attachments:

Replies to This Discussion

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.

Attachments:

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

In that case you are doing it pretty well.
By the way, I made a mistake. The line:

newTree.AddRange(diff, _paths)

should be:

newTree.AddRange(diff, path)

Or you could just delete the line:

path = ghp.GH_Path(_paths)

RSS

About

Translate

Search

Photos

  • Add Photos
  • View All

Videos

  • Add Videos
  • View All

© 2021   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service