# Python nurbCrv

hello! hope u doing very well!

i need some help with python to generate a nurbsCrv from a list of points created in python script.

any idea?

thanks

Hi @oliver.jans,

Hope youâ€™re doing fine too!

Sure, letâ€™s say your list of points is called, well points, than you can do the following:

import Rhino.Geometry as rg

curve = rg.Curve.CreateInterpolatedCurve(points, 3) # 3 = degree
curve.ToNurbsCurve() # maybe redundant ?
1 Like

hello @diff-arch is there any method to edit weights??

thanks!!

Take a look at the NurbsCurve class documentation. You can search for â€śGrevilleâ€ť to see all methods that you can manipulate the Greville edit points with.

1 Like

@diff-arch hello again! I examined the link and thought i understood everything but was mistaken. i find it really hard to edit the greville pts very confusing. would u mind sharing some of your experience w/ me?

any time. no need to hurry

thanks!

Could you maybe explain what you want to do? It would make things much easier.

I need a pwk nurbs Quadratic Crv to edit weights of ctrl points. How do i edit weights w Python script?

I have no idea what that is! pwk?

Starting from what we had above, you could do the following to alter the control point weights:

import Rhino.Geometry as rg
import random

# Create an interpolated curve
curve = rg.Curve.CreateInterpolatedCurve(points, 3) # 3 = degree
# Make it rational which means that it has weighted control points
curve.Points.MakeRational()
print curve.IsRational

# Randomly change the weights
control_points = []
for i in range(curve.Points.Count): # loop through the control points by index
curve.Points.SetWeight(i, random.random()) # set a random weight for the control point at index i
control_points.append(curve.Points[i].Location) # optional

You have to tag me or reply to one of my answers directly, otherwise I wonâ€™t be notified, if you post something that Iâ€™m concerned with.

Anyways, the randomization produces quite funky results.

1 Like

Perfect! Thank u for posting

1 Like