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

"Number of elements in knots must equal the number of elements in points plus degree minus 1"

$
0
0

@gehlot wrote:

I am trying to generate a new curve by identifying knots, degrees, points and weight from an existing curve. I am getting all the 4 necessary information to feed it back into the command “newcurve_id = rs.AddNurbsCurve(new_curve_points, knots, degree, weights)”. However, it shows me an error that Number of elements in knots must equal the number of elements in points plus degree minus 1. Can someone please help?
Below is the script that I am using.

import rhinoscriptsyntax as rs

def smoothingvector (point, prev_point, next_point, s):
pm = (prev_point+next_point)/2.0
va = rs.VectorCreate(pm, point)
vm = rs.VectorScale(va, s)
return vm

def smoothcurve(s):
curve_id = rs.GetObject(“Open curve to smooth”, 4, True)
curve_points = rs.CurvePoints(curve_id)
print curve_points
new_curve_points =
for i in range(1, (len(curve_points)-1)):
vm = smoothingvector(curve_points[i], curve_points[i-1], curve_points[i+1], s)
new_curve_points.append( rs.PointAdd(curve_points[i], vm) )
knots = rs.CurveKnots(curve_id)
print knots
degree = rs.CurveDegree (curve_id)
print degree
weights = rs.CurveWeights(curve_id,0)
print weights
newcurve_id = rs.AddNurbsCurve(new_curve_points, knots, degree, weights)
print newcurve_id
if newcurve_id: rs.DeleteObject(curve_id)
return newcurve_id

smoothcurve(.9)

Posts: 4

Participants: 2

Read full topic


Viewing all articles
Browse latest Browse all 5834