2
$\begingroup$

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'} 
$\endgroup$
2
  • $\begingroup$ What doesn't work when you try the second answer? $\endgroup$ Feb 15, 2022 at 0:25
  • $\begingroup$ @MartyFouts it just creates a new curve on top of my existing surface circle. I don't really understand how to utilize it in my case $\endgroup$
    – Increality
    Feb 15, 2022 at 0:29

1 Answer 1

2
$\begingroup$

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

$\endgroup$
1
  • $\begingroup$ 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. $\endgroup$
    – Increality
    Feb 15, 2022 at 17:57

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .