algorithmic modeling for Rhino
As I am somewhat new to python, I'm struggling to set up a parallel Shape in Brep node. I have the x input set to Item access with a brep type hint and the y input set to list access with a brep type hint. Any help would be appreciated. Eventually I would like to run both as tree access so I can test 3 lists of 60 items into 3 lists of 1 brep.
Tags:
Hi Nate,
Try changing your x and y input access types from "Item access" to "List access" (right click on them).
Thanks for the quick response Djordje,
I get a different error when I switch both x and y to list access...
{1;0}
0. Runtime error (ArgumentTypeException): Intersect() takes exactly 2 arguments (1 given)
1. Traceback:
line 25, in run, "C:\Users\nholland\AppData\Roaming\McNeel\Rhinoceros\5.0\Plug-ins\IronPython (814d908a-e25c-493d-97e9-ee3861957f49)\settings\lib\ghpythonlib\parallel.py"
line 8, in script
line 21, in helper, "C:\Users\nholland\AppData\Roaming\McNeel\Rhinoceros\5.0\Plug-ins\IronPython (814d908a-e25c-493d-97e9-ee3861957f49)\settings\lib\ghpythonlib\parallel.py"
I'm not sure what this error is telling me either.
I am not a parallel expert, and have been struggling myself in the last period, but here is my guess:
ghpythonlib.parallel.run() function accepts three arguments:
- name of the function you are calling (in this case: "Intersect")
- list (in this case "x")
- flatten results (in this case "y").
I guess that seems to be the problem: you defined your "Intersect" function with two arguments, and ghpythonlib.parallel.run() is feeding it with only one - "x".
To solve this, just define your "Intersect" function with one argument (let's say "y"), and inside it, use a global variable "x":
import ghpythonlib.components as ghc
import ghpythonlib.parallel
def Intersect(_y):
result = ghc.ShapeInBrep(x,_y)
if result: return result
a = ghpythonlib.parallel.run(Intersect, y, True)
Other than that replace your "y" as a third argument in ghpythonlib.parallel.run() with either True or False, as that's what the function is expecting.
And here is the solution Steve Baer made for supplying two arguments into the function instead of one (in a form of a list of tuples, and then unpacking it inside the function.
In your case the code would look like this:
import ghpythonlib.components as ghc
import ghpythonlib.parallel
def Intersect(_breps):
_x,_y = _breps
result = ghc.ShapeInBrep(_x,_y)
if result: return result
breps = []
for item in y:
breps.append((x,item))
a = ghpythonlib.parallel.run(Intersect, breps, True)
Please, please attach your files for any future issues.
That was exactly it, Thank you.
For others here is the final version that runs with tree access
import ghpythonlib.components as ghcomp
import ghpythonlib.parallel
from System import Object
from Grasshopper import DataTree
from Grasshopper.Kernel.Data import GH_Path
a = DataTree[Object]()
output = [ ]
for i in range(x.BranchCount):
p = GH_Path(i)
brep=x.Branch(i)
shape=y.Branch(i)
def Intersect(Brep2):
result = ghcomp.ShapeInBrep(brep, Brep2)
if result: return result
o = ghpythonlib.parallel.run(Intersect, shape)
a.AddRange(o,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
Added by Parametric House 0 Comments 0 Likes
© 2024 Created by Scott Davidson. Powered by