# Argument error with remove constraint py code

This is the constraint remove function:

class DeleteTrackTo(bpy.types.Operator):

bl_idname = "delete.trackto"
bl_label = "Delete TrackTo"
bl_options = {'REGISTER'}

def execute(self, context):

obj = bpy.context.active_object
constraint_to_remove = obj.constraints.get("TRACKTO")

obj.constraints.remove(constraint_to_remove)

return{'FINISHED'}


This is the Pie menu calling the constraint remove function:

class PieManipulateObject(Menu):
bl_idname = "pie.manipulateobject"
bl_label = "Object Edit"

def draw(self, context):
layout = self.layout

scene = context.scene

col.operator("object.track_set").type='TRACKTO'
col.operator("delete.trackto")


I get this error message when calling the remove function:

TypeError: ObjectConstraints.remove(): error with argument 1, "constraint" - Function.constraint does not support a 'None' assignment Constraint type

• it is obj.constraints.remove() – Chebhou Feb 15 '16 at 18:10
• you can always try it in blender python console and you 'll get auto completion this really help ( also the docs ) – Chebhou Feb 15 '16 at 18:12
• I adjusted the code a little but ran into the following error. – Claas Kuhnen Feb 15 '16 at 18:28
• you have to pass the name of the constraint not the type to the get() function ( which is returning None because it doesn't find the constraint with a name "TRACKTO" ), also it would be better to check if the constraint exist before deleting it – Chebhou Feb 15 '16 at 18:32
• @Chebhou I see. This then renders the problem that in case the Name got changed the script will fail. That is why I thought you could filter out the constraint via the type (trackto) and not via the individual name. – Claas Kuhnen Feb 15 '16 at 18:42