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")



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 

        pie = layout.menu_pie()


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

  • 1
    $\begingroup$ it is obj.constraints.remove() $\endgroup$ – Chebhou Feb 15 '16 at 18:10
  • $\begingroup$ you can always try it in blender python console and you 'll get auto completion this really help ( also the docs ) $\endgroup$ – Chebhou Feb 15 '16 at 18:12
  • $\begingroup$ I adjusted the code a little but ran into the following error. $\endgroup$ – Claas Kuhnen Feb 15 '16 at 18:28
  • 1
    $\begingroup$ 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 $\endgroup$ – Chebhou Feb 15 '16 at 18:32
  • $\begingroup$ @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. $\endgroup$ – Claas Kuhnen Feb 15 '16 at 18:42

Your Answer

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

Browse other questions tagged or ask your own question.