3
$\begingroup$

Preferably not using selection, tried bpy.data.meshes.remove don't works for it

$\endgroup$
  • $\begingroup$ not a duplicate, simply using bpy.ops.delete will not remove the Curve data, until save and reopen, but my code below will. $\endgroup$ – zeffii Jun 12 '15 at 16:24
  • $\begingroup$ related: blender.stackexchange.com/questions/27234/… $\endgroup$ – p2or Jun 12 '15 at 16:31
3
$\begingroup$

Something like this,

  • First remove the Object that uses the Curve
  • Then remove the Curve data

code:

curves = bpy.data.curves
objects = bpy.data.objects
scene = bpy.context.scene

# remove the object
obj = bpy.data.objects[object_name]
cu = obj.data  # the curve
scene.objects.unlink(obj)
objects.remove(obj)

# remove the associated curve, if you need to and it doesn't have other users. 
curves.remove(cu)

You won't be able to remove Curve data if there are remaining Objects associated with that Curve data. cu.users will tell you how many users the Curve has, if that returns 0, the curve data can be removed with no other steps, but if it's more than 0 then other Objects are referencing the curve and you need to clear those references first.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.