Quantcast
Channel: Scripting - McNeel Forum
Viewing all articles
Browse latest Browse all 5783

Handling exception

$
0
0

@lepli wrote:

Dear 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

Posts: 3

Participants: 2

Read full topic


Viewing all articles
Browse latest Browse all 5783

Trending Articles