2

Is there a way to select specific vertices (control points) on a nurbs surface? I'm working with a Nurbs Surface Circle, and want to select the highlighted vertices with Python.

enter image description here

I see this answer for mesh

As well as this answer for nurbs curve, but am not quite able to get it working. Here is my code thus far:

def execute(self, context):
    bpy.ops.surface.primitive_nurbs_surface_circle_add()
    bpy.ops.object.editmode_toggle()
    bpy.ops.curve.subdivide()
    bpy.ops.curve.select_all(action = 'DESELECT')
return {'FINISHED'} 

Increality
  • 411
  • 3
  • 14

1 Answers1

2

To access the control points of a nurbs curve, you first select the curve, then the spline within the curve, and finally the points within the spline:

import bpy

Replace the next line with code to select your Nurbs Circle

curve = bpy.data.curves["NurbsCircle"]

Since it's a Nurbs circle, there's only one spline

spline = curve.splines[0]

for index, point in enumerate(spline.points): print(index, point.co)

is an example that will print out all of the control points in a default Nurbs circle.

If you want, for instance, all of the selected points, you could use point.select:

for index, point in enumerate(spline.points):
    if point.select:
        print(index, point.co)

will print

2 <Vector (-1.0000, 0.0000, 0.0000, 1.0000)>
5 <Vector (1.0000, 1.0000, 0.0000, 0.3536)>

for this selection:

Nurbs circle with two points selected.

Instead of printing, you can do whatever you want with the control points, including selecting them by using something like point.select = True in the above loop.

You can read more about the fields in a Curve in the Blender manual

Marty Fouts
  • 33,070
  • 10
  • 35
  • 79
  • I copied exactly what you wrote into a new script with nothing else in it, "NurbsCircle" in that first line throws an error in this case. I do have the Nurbs circle in the scene. Tried changing the name to "SurfCircle", which fixes the error but does nothing: curve = bpy.data.curves["SurfCircle"] Am I doing something wrong?

    I also edited my question to show my original code.

    – Increality Feb 15 '22 at 17:57