# Python Scripting: Remove Curve Object

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

• not a duplicate, simply using bpy.ops.delete will not remove the Curve data, until save and reopen, but my code below will. – zeffii Jun 12 '15 at 16:24
• – p2or Jun 12 '15 at 16:31

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

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.