I have more than 100 objects and I want them to point in a particular direction depending on their position. To move them to a particular position, I used:

bpy.context.scene.objects[""].location.xyz = ...

Is there similar command for setting the angle of rotation for an object? I am working in a crossroad with two lanes. The position of the cars are taken as input. So according to their coordinates they are placed on the road, pointing in the direction they need to. The track to constraint is not applying the correct direction to all of them. I checked my if condition. Some of the objects are getting hidden unnecessarily.

  • $\begingroup$ related: blender.stackexchange.com/questions/16275/… $\endgroup$ – zeffii May 30 '15 at 7:06
  • $\begingroup$ also related: blender.stackexchange.com/questions/19533/… $\endgroup$ – zeffii May 30 '15 at 7:18
  • $\begingroup$ If any of those suggestions helps answer your question, we can mark this as duplicate (no need to delete it) $\endgroup$ – zeffii May 30 '15 at 7:19
  • $\begingroup$ No they aren't answering it completely $\endgroup$ – Arun TechM Jun 1 '15 at 4:18
  • 1
    $\begingroup$ If the suggestions aren't helping but you still would like a solution, take some effort to be more descriptive in your question. Paint a representative scenario, use screenshots of multiple views or upload a .blend file (again, of something representative..doesn't have to be 100s of points) so we can better judge what answer might be most suitable. Right now we know too little. $\endgroup$ – zeffii Jun 1 '15 at 5:46

Here's how to set Euler rotation.

First: from mathutils import Euler

Then: obj.rotation_euler = Euler((0.3, 0.3, 0.4), 'XYZ')

If all the other track_to options are overkill. For more attribute references see the Object documentation

  • 1
    $\begingroup$ May you add the line: from mathutils import Euler for the code to work $\endgroup$ – Bruno Bieri Mar 16 '18 at 8:36
  • Consider [track to] constraint constraint panel in properties area constraint in action

After you have setup the constraint for one object, select the other objects, select the object with the constraint afterwards, press Space in the viewport, type and choose Copy Constraints to Selected Objects

  • $\begingroup$ I have a doubt. I tried using track to constraint as suggested by you. But once I run the script it is working for objects in particular positions only and not working for all of them. I have checked my if condition lot of times. But I'm not able to figure out where I went wrong. Could you please suggest where could I have gone wrong. Thanks $\endgroup$ – Arun TechM Jun 1 '15 at 4:07
  • 2
    $\begingroup$ FYI, the big arrow looks like something else... $\endgroup$ – Alex Jul 1 '18 at 6:44
  • $\begingroup$ @Alex Well you know what they say on Mars where everything is Green. Big Constraint Big Arrow. $\endgroup$ – atomicbezierslinger Jul 2 '18 at 17:06

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.