Split Curves with a list of points

python
unhandled

(Yuchen Chen) #1

Hello there,

I am trying to shatter curves by points in gpyhton script, however, the result shows
" Parameter must be a Guid or string representing a Guid."
I go through the lines find out the problem is at rs.SplitCurve. I did find some people on the forum have the similar issue with the Guid problem, but still i cannot resolve my error. Hope someone is able to provide a clue! Thanks in advanced!
the attachment is the GH file and following is the Gpython code.

Preformatted textimport rhinoscriptsyntax as rs

mesh = mesh
curves = curves

pts = []
for i in range(len(curves)):
cmx = rs.CurveMeshIntersection(curves[i],mesh,False)
for j in range(len(cmx)):
pt = rs.AddPoint(cmx[j])
pts.append(pt)

newcurves = []

for i in range(len(curves)):
for j in range(len(pts)):
if rs.IsPointOnCurve(curves[i],pts[j]) == True:
param = rs.CurveClosestPoint(curves[i],pts[j])
splitedCrv = rs.SplitCurve(curves[i],param)
newcurves.append(splitedCrv)
indent preformatted text by 4 spaces

a = newcurves
Guidproblem.gh (4.4 KB)


(Yuchen Chen) #3

There is some typing mistake in the previous code

import rhinoscriptsyntax as rs


mesh = mesh 
curves = curves

pts = []
for i in range(len(curves)):
    cmx = rs.CurveMeshIntersection(curves[i],mesh,False)
    for j in range(len(cmx)):
        pt = rs.AddPoint(cmx[j])
        pts.append(pt)
        

newcurves = []

for i in range(len(curves)):
    for j in range(len(pts)):
        if rs.IsPointOnCurve(curves[i],pts[j]) == True:
            param = rs.CurveClosestPoint(curves[i],pts[j])
            splitedCrv = rs.SplitCurve(curves[i],param)
            newcurves.append(splitedCrv)

a = newcurves

(qythium) #4

A few things here:

  • If you’re using rhinoscriptsyntax functions, the type hint of the input has to be set to “ghdoc object when geometry”
  • rs.SplitCurve is a destructive operation, it modifies the original curve in-place and returns a list of splitted curves. So you have to make a copy of the original if you want to reuse it in your loop.
  • minor style tips: spot the edits below :slight_smile:
import rhinoscriptsyntax as rs

mesh = mesh # not necessary
curves = curves # 

pts = []
for curve in curves:
    cmx = rs.CurveMeshIntersection(curve, mesh, False)
    for x_pt in cmx:
        pt = rs.AddPoint(x_pt)
        pts.append(pt)

newcurves = []

for curve in curves:
    for pt in pts:
        if rs.IsPointOnCurve(curve, pt):
            param = rs.CurveClosestPoint(curve, pt)
            copied_curve = rs.CopyObject(curve)
            splitted_curves = rs.SplitCurve(copied_curve, param)
            newcurves.extend(splitted_curves)

a = newcurves 

(Yuchen Chen) #5

Hi @qythium,
thanks for the explanation! now i got why the splitcureve will cause the issue!
really appreciate for your help!