Hi wattzie,
Multithreading in RhinoPython editor is possible but you will have to install grasshopper and ghpython first: Download and install the latest grasshopper version. Download the ghpython.gha file. Fire up your Rhino, type “Grasshopper” into the command box. When grasshopper window loads, go to File → Special Folders → Components Folder. Copy the downloaded ghpython.gha file to this folder. Right click on it → Properties. Click on “unblock”, if such button appears. If it does not, you are good to go. Close the Grasshopper and Rhino. Fire the Rhino and Grasshopper again. Now, I am not sure if this has been fixed with the latest release of ghpython, but just in case it hasn’t do this too: double click to Grasshopper canvas and type: Python script. Click on the icon at the very bottom of the search box that will appear. This will add ghpython component to your canvas. Open it (double click on it) and type: print "hello world". Click on “Ok”. Close the Grasshopper window and open the RhinoPython editor one.
Paste the following code:
import rhinoscriptsyntax as rs
import ghpythonlib.parallel
import Rhino
import time
def pickVertices(_vertices, _normals):
angles = []
points = []
zAxis = rs.VectorCreate([0,0,1],[0,0,0])
for i,normal in enumerate(_normals):
angle = rs.Angle2(([0,0,0],_normals[i]), ([0,0,0],[0,0,1]))[0]
angles.append(angle)
if (angle > gradient-tolerance) and (angle < gradient+tolerance):
points.append(_vertices[i])
return points
def pickVerticesParall(_vertNrmls):
vertex, normal = _vertNrmls
angles = []
points = []
angle = rs.Angle2(([0,0,0],normal), ([0,0,0],[0,0,1]))[0]
angles.append(angle)
if (angle > gradient-tolerance) and (angle < gradient+tolerance):
points.append(vertex)
return points
meshId = rs.GetObject("pick up your mesh", 32, True)
if meshId:
parallel = rs.GetString("use parallel?", "no", ["yes", "no"])
meshObj = rs.coercemesh(meshId)
vertices = [vertex for vertex in meshObj.Vertices]
normals = [normal for normal in meshObj.Normals]
gradient = 23
tolerance = 1
if parallel == "yes":
time1a = time.time()
vertNrmls = [(vertices[i],normals[i]) for i in range(len(vertices))]
ptsObj = ghpythonlib.parallel.run(pickVerticesParall, vertNrmls, True)
time1b = time.time()
print round(time1b - time1a, 3)
elif parallel == "no":
time2a = time.time()
ptsObj = pickVertices(vertices, normals)
time2b = time.time()
print round(time2b - time2a, 3)
try:
ptIds = rs.AddPoints(ptsObj)
except:
pass
meshVerticesParallel.py (1.6 KB)
Check both parallel and non parallel methods, and the differences in processing time will be printed out.
Have in mind that even more quicker “way” is using directly RhinoCommon methods instead of rhinoscriptsyntax functions. So you will get even more speed gain if you replace the line 22 with:
angle = Rhino.Geometry.Vector3d.VectorAngle(normal, Rhino.Geometry.Vector3d(0,0,1))*180/3.14