2
$\begingroup$

I have a very straight-forward code, it's not working. I wonder why does it select nothing and raise "No points selected" error. (Yes, it's a Nurbs curve, not Bezier)

import bpy

obj = bpy.context.active_object

spline = obj.data.splines[0]
bpy.ops.object.mode_set(mode = 'EDIT')
bpy.ops.curve.select_all(action='DESELECT')
bpy.ops.object.mode_set(mode = 'OBJECT')

if spline:
    for pt in spline.points:
        pt.select = True

bpy.ops.object.mode_set(mode = 'EDIT')
bpy.ops.curve.separate()
bpy.ops.object.mode_set(mode = 'OBJECT')
$\endgroup$

1 Answer 1

2
$\begingroup$

It seems that when you switch to Edit Mode using bpy.ops.object.mode_set(mode='EDIT'), Blender enters a different mode of operation where it creates a temporary copy of the original spline data to enable editing without directly affecting the original object's data. I made a print trace and I get different addresses for the same spline in Object Mode and Edit Mode:

enter image description here

This script will work:

import bpy

obj = bpy.context.active_object

bpy.ops.object.mode_set(mode = 'OBJECT')
spline = obj.data.splines[0]
print("Spline Address in Object Mode:", spline)

bpy.ops.object.mode_set(mode = 'EDIT')
spline = obj.data.splines[0]
print("Spline Address in Edit Mode:  ", spline)

bpy.ops.curve.select_all(action='DESELECT')

if spline:
    for pt in spline.points:
        pt.select = True

bpy.ops.object.mode_set(mode = 'EDIT')
bpy.ops.curve.separate()
bpy.ops.object.mode_set(mode = 'OBJECT')
$\endgroup$
2
  • 1
    $\begingroup$ thank you a lot! You saved my nervous system and my PC also ( ̄▽ ̄)" $\endgroup$
    – Void
    Commented Aug 4, 2023 at 6:28
  • $\begingroup$ you're welcome! :) $\endgroup$
    – Harry McKenzie
    Commented Aug 4, 2023 at 6:31

You must log in to answer this question.

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