19

I have a large number of objects, and I wish to add a Track to constraint to each object. When I select the group of them and then add the constraint, it is added to only the active object, of course. How can I add the constraint to all selected objects?

Jason
  • 1,653
  • 2
  • 13
  • 18

3 Answers3

28
  1. With the objects selected, add the desired constraint to the active object.
  2. From the 3D View header menu choose Object > Constraints > Copy Constraints to Selected Objects.

All the objects will now have the same constraint.

This method doesn't require an add-on to work.

Ray Mairlot
  • 29,192
  • 11
  • 103
  • 125
5

You could also just loop through the selected objects and apply the contraint to each one.

The line with objs.target is an example of how to set the target object. In this example, I assume that all the selected objects will have an Empty as the target.

import bpy
context = bpy.context

for x in bpy.context.selected_objects:
    objs = x.constraints.new(type='TRACK_TO')
    objs.target = context.scene.objects.get("Empty")
iKlsR
  • 43,379
  • 12
  • 156
  • 189
  • 1
    I like this answer because it gives me more flexibility than my discovered answer, but it's also a lot more complex than just using an add-on. – Jason Aug 14 '13 at 16:13
  • @Jason it is very simple to use actually, just drop it into the text editor and run it as you need it. If need be, you can also put it into a small addon and map a shortcut to it. Also, based on your comment on the question, if you want to add a new object with the same constraint and target, just select it and run the script again. – iKlsR Aug 14 '13 at 16:15
  • I'm comfortable using Python to manipulate Blender, but this seems like a task that someone might want to do who was a relative newcomer to Blender. For newcomers, Python can be intimidating. For complicated tasks that are relatively uncommon, I think a Python solution is fine, but for a task that is simple or common, I would rather there be a UI solution. – Jason Aug 15 '13 at 16:45
  • 1
    That being said, your solution did show me how to create a new constraint using Python, which is something that I was having trouble with. – Jason Aug 15 '13 at 16:45
  • Happy to report that this solution STILL works as of Blender 2.83. Thanks! – Coby Randal Jul 15 '20 at 15:05
5

I discovered how to do this using an add-on.

  1. Enable the "Copy Attributes Menu" addon

  2. Use Ctrl+C to activate the menu

  3. Choose "Copy Selected Constraints"

This doesn't let you modify the constraints, though, or remove them.

Jason
  • 1,653
  • 2
  • 13
  • 18