algorithmic modeling for Rhino
I am having trouble with the new grasshopper parallel module when passing into it more than one argument. In my example I am passing in two arguments, but when I retrieve it within the offsetSrf() function, there is only one argument available. Does anyone know what I am doing wrong?
Code:
def offsetSrf(args):
print args
cur, surf = args #unpack input
cur = rs.coercecurve(cur)
result = ghcomp.OffsetonSrf(cur, d, surf)
return result
if parallel:
args = (c, s)
print args
print ("***************************")
slices = ghpythonlib.parallel.run(offsetSrf, args, True)
Tags:
Hi Jack,
The way parallel.run function works is that it takes a list of items, and then picks each item in that list and supplies the specified function with that item.
In your case (assuming the "c" and "s" input plugs are correctly set as lists) this is what it gets - a tuple of lists:
( [crv1,crv2,crv3,crv4], [srf1,srf2,srf3,srf4] )
The two items that parallel.run will take are:
[crv1,crv2,crv3,crv4] and [srf1,srf2,srf3,srf4].
And it will try to unpack them one by one, in each iteration:
cur, surf = [crv1,crv2,crv3,crv4]
cur, surf = [srf1,srf2,srf3,srf4]
Thus the error message: "too many values to unpack"
So just supply a list of lists, or list of tuples to make it work:
if parallel:
args = [[c[i],s[i]] for i in range(len(c))]
Please attach your files next time.
The node-in-code feature currently experiences some speed slowdowns. Looks like Steve and Giulio have found solution for this, or might even incorporate it in the next release of ghPython. Until then, using rhinocommon methods would be better.
Have in mind that each unecessary statement and line, adds a few milliseconds. I commented out all the redundant ones.
I am using an old AMD Sempron 3100 1.8Ghz, but still had a bit of speed increase in comparion with previous version. Your newer processor may have even more success.
hi djordje, is it possible do the same thing with a recursive function with more than 1 variable?
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