# How do I add a constraint to an object with Python?

I am currently writing a script, and have gotten to the point where I need to add a constraint from inside the script in my for loop. I have been unable to find any recent documentation on the subject however, it all being from a good 7-8 years ago for the most part.

How could I accomplish this?

import bpy

o = bpy.context.object
constraint = o.constraints.new('COPY_LOCATION')

#constraint properties
constraint.show_expanded = False
constraint.mute = True


https://www.blender.org/api/blender_python_api_2_77_release/bpy.types.ObjectConstraints.html?highlight=constraints#bpy.types.ObjectConstraints

https://www.blender.org/api/blender_python_api_2_77_release/bpy.types.CopyLocationConstraint.html?highlight=constraints

• Where is this in the documentation? I would like to be able to set values as well. – VRM May 17 '16 at 12:15