  hello everone
I created nurbs curve rs.AddNurbsCurve, but does not appear in rhino window，Such as pictures，I use rhinocommon can successfully create nurbs curve，Such as pictures，How do I use rs.AddNurbsCurve create nurbs curve，help me，thanks

I am able to repeat the problem. I’ll see that a fix makes it into the next Rhino SR.

Thanks for reporting.

1 Like

Hi dale
I solved this problem,rs.addnurbscurve weighs must be set parameters,orchange the code,Example：
#coding=utf-8

import scriptcontext
import rhinoscriptsyntax as rs
import utility as rhutil
import Rhino
import math
import System.Guid, System.Array, System.Enum

""“Adds a NURBS curve object to the document
Parameters:
points = list containing 3D control points
knots = Knot values for the curve. The number of elements in knots must
equal the number of elements in points plus degree minus 1
degree = degree of the curve. must be greater than of equal to 1
weights[opt] = weight values for the curve. Number of elements should
equal the number of elements in points. Values must be greater than 0
"”"
points = rhutil.coerce3dpointlist(points, True)
cvcount = len(points)
knotcount = cvcount + degree - 1
if len(knots)!=knotcount:
raise Exception(“Number of elements in knots must equal the number of elements in points plus degree minus 1”)
if not weights:
weights = [2 for i in range(cvcount)]
else:
if len(weights)!=cvcount:
raise Exception(“Number of elements in weights should equal the number of elements in points”)
weights = weights
rational = (weights!=None)

``````nc = Rhino.Geometry.NurbsCurve(3,rational,degree+1,cvcount)
#nc = Rhino.Geometry.NurbsCurve.Create(rational,degree,points)
for i in xrange(cvcount):
cp = Rhino.Geometry.ControlPoint()
cp.Location = points[i]
if weights: cp.Weight = weights[i]
nc.Points[i] = cp
for i in xrange(knotcount): nc.Knots[i] = knots[i]
if rc !=System.Guid.Empty:
scriptcontext.doc.Views.Redraw()
else:
raise Exception("Unable to add curve to document")
return rc
``````

pts = rs.GetObjects()
knot = [0.0,0.0,0.0,1.0,1.2,3.0,3.0,3.0]
weight = [8,6,3,8,4,8]
if curve:
print(curve,type(curve))
return curve

print rs.CurveWeights(cv)

Great work

HIi dale
I found another problem,rs.OffsetSurface not be offset trim Surface and Triangle Surface， e,Example：

import scriptcontext
import math
import Rhino
import System.Guid
import utility as rhutil
import object as rhobject
import rhinoscriptsyntax as rs

def OffsetSrf(surface_id, distance, tolerance=None, both_sides=False, create_solid=False):
“”“Offsets a trimmed or untrimmed surface by a distance. The offset surface
Parameters:
surface_id = the surface’s identifier
distance = the distance to offset
tolerance [opt] = The offset tolerance. Use 0.0 to make a loose offset. Otherwise, the
document’s absolute tolerance is usually sufficient.
both_sides [opt] = Offset to both sides of the input surface
create_solid [opt] = Make a solid object
Returns:
identifier of the new object if successful
None on error
“””
brep = rhutil.coercesurface(surface_id, True)
face = None
if brep is None: return scriptcontext.errorhandler()
face = brep
if tolerance is None: tolerance = scriptcontext.doc.ModelAbsoluteTolerance
newbrep = Rhino.Geometry.Brep.CreateFromOffsetFace(face, distance, tolerance, both_sides, create_solid)
if newbrep is None: return scriptcontext.errorhandler()
if rc==System.Guid.Empty: return scriptcontext.errorhandler()
scriptcontext.doc.Views.Redraw()
return rc Thanks

Got it, thanks!

I have the same problem.
I created nurbs curve rs.AddNurbsCurve, but does not appear in rhino window,Such as pictures，How do I use rs.AddNurbsCurve create nurbs curve，help me，thanks

Can you provide the source code that you cannot make work? I’d rather not re-type your screen capture…

– Dale

Hi, @dale
I am sorry not to paste my source code…
I pasted the source code.

import rhinoscriptsyntax as rs
import random as rd

curve = rs.GetObject(“Select a curve”, 4)

if curve:
points = rs.CurvePoints(curve)
knots = rs.CurveKnots(curve)
degree = rs.CurveDegree(curve)

``````newpoints = []
for p in points:
dx = rd.randrange(0,5)
dy = rd.randrange(0,5)
dz = rd.randrange(0,5)
d = [dx, dy, dz]
newpoints.append(q)

print newcurve``````

Hi.
Your code has non ascii characters and improper indentation. Better paste code in a code block like this:

``````import rhinoscriptsyntax as rs
import random as rd

curve = rs.GetObject("Select a curve", 4)

if curve:
points = rs.CurvePoints(curve)
knots = rs.CurveKnots(curve)
degree = rs.CurveDegree(curve)

newpoints = []
for p in points:
dx = rd.randrange(0,5)
dy = rd.randrange(0,5)
dz = rd.randrange(0,5)
d = [dx, dy, dz]
newpoints.append(q)

print newcurve
``````

Sorry, I can not reproduce the problem.

If you run the `SelCrv` command do you only get the original curve in your selection?

thanks,
I pasted your code in my python, but nurbs curve doesn’t appear. and error code doesn’t appear either…
now I use rhino5. The setting is wrong??

Your screen capture with the printed `Id` shows that it was added to the document. Forcing a redraw by moving things around doesn’t show it? Does running the `SelCrv` command select it?

Yes, Running the `SelCrv` command select a curve

Running the `SelCrv` command only selected one curve? Not two: the original curve plus the new one?

Running the Selcrv command in rhino can select two curves, thanks.
but on the screen, i cannot see the new curve.(I cheched the display setting and show command, layer)

If you run the `SelLast` command followed by the menu: `View->Zoom->ZoomSelected` do you see it?

If I run the SelLast command, zoom_selected commmand doesn’t work like screen capture.

The code you posted works here in both Rhino 5 SR14 and Rhino 6 SR3.

If you are using Rhino 5 and are not using SR14, then I suggest you download and install the service release.