algorithmic modeling for Rhino
Hi all,
I am working on bit of python script on grasshopper which enable to simulate movement of drops of water on a surface.
It works well with most of points(drops) on the surface, but it makes an error when it comes to points on edges of the surface.
I guess it is because normal vectors at a few of points are invalid. After all, because of these invalid points, an error message comes out which is saying " Runtime error (PythonException) : Unable to add polyline to document " and it results in no output. Please give me some help if you know how to handle this problem. I post a code below.
Thanks in advance.
---------------------------------------------------------------------------------------------
import Rhino
import rhinoscriptsyntax as rs
import math
import ghpythonlib.components as gh
output_crvs = []
for pt1 in input_pt :
output_pts = []
newPt = pt1
output_pts.append(newPt)
while len(output_pts) <= 100:
newPt = outputpoint(base_srf, newPt, distance_factor)
output_pts.append(newPt)
output_crv = rs.AddPolyline(output_pts)
output_crvs.append(output_crv)
A = output_crvs
def outputpoint(base_srf, input_pt, distance_factor):
centre_point = rs.AddPoint(0,0,0)
height_point = rs.AddPoint(0,0,10)
zaxis = rs.VectorAdd(centre_point, height_point)
cp_pt = rs.SurfaceClosestPoint(base_srf, input_pt)
normal_vector = rs.SurfaceNormal(base_srf, cp_pt)
drain_vector = rs.VectorCrossProduct(normal_vector, zaxis)
dvector2 = rs.VectorUnitize(drain_vector)
dvector3 = rs.VectorRotate(dvector2, 90, normal_vector)
mpt = gh.DeconstructVector(distance_factor*dvector3)
moved_pt = rs.PointAdd(input_pt, mpt)
moved_uv = rs.SurfaceClosestPoint(base_srf, moved_pt)
output_pt = rs.EvaluateSurface(base_srf, moved_uv[0], moved_uv[1])
return output_pt
Tags:
Ideally you need to figure out why the error is happening but if you just want to pass the exception, you can use try - exception in python. You can find so many examples online. I just write the generic pattern here:
try:
# you code here
except:
# handle the exception
else:
# if exception didn't happen
finally:
# code that should be executed either exception happens or not
# useful for cases like closing the file, etc
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