14
$\begingroup$

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?

$\endgroup$
  • $\begingroup$ Do you want these to have a target? $\endgroup$ – iKlsR Aug 14 '13 at 15:57
  • $\begingroup$ Yes, I want them all to have the same target. Basically, I want them all to have the same constraint. $\endgroup$ – Jason Aug 14 '13 at 16:14
18
$\begingroup$
  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.

$\endgroup$
  • $\begingroup$ That is exactly what I was looking for! I can't believe I never noticed this menu before. I also see it has a Clear Object Constraints command, which I now know is a thing! $\endgroup$ – Jason Aug 15 '13 at 16:47
  • $\begingroup$ This does not appear to work in newer versions of Blender. $\endgroup$ – VRM Aug 24 '17 at 19:31
  • $\begingroup$ @VRM I've just checked in the 2.79 release candidate and it still works. $\endgroup$ – Ray Mairlot Aug 25 '17 at 12:57
  • $\begingroup$ I was using a different branch when testing, my bad $\endgroup$ – VRM Aug 25 '17 at 14:34
4
$\begingroup$

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.

$\endgroup$
  • $\begingroup$ This addon has restored the old inbuilt functionality of pre 2.5 versions. Very useful in my opinion. $\endgroup$ – Haunt_House Aug 14 '13 at 19:48
4
$\begingroup$

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")
$\endgroup$
  • 1
    $\begingroup$ 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. $\endgroup$ – Jason Aug 14 '13 at 16:13
  • $\begingroup$ @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. $\endgroup$ – iKlsR Aug 14 '13 at 16:15
  • $\begingroup$ 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. $\endgroup$ – Jason Aug 15 '13 at 16:45
  • 1
    $\begingroup$ 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. $\endgroup$ – Jason Aug 15 '13 at 16:45

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.