8
$\begingroup$

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.

$\endgroup$
8
  • $\begingroup$ related: blender.stackexchange.com/questions/16275/… $\endgroup$
    – zeffii
    Commented May 30, 2015 at 7:06
  • $\begingroup$ also related: blender.stackexchange.com/questions/19533/… $\endgroup$
    – zeffii
    Commented May 30, 2015 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
    Commented May 30, 2015 at 7:19
  • $\begingroup$ No they aren't answering it completely $\endgroup$
    – Arun TechM
    Commented Jun 1, 2015 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
    Commented Jun 1, 2015 at 5:46

2 Answers 2

8
$\begingroup$

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

$\endgroup$
1
  • 1
    $\begingroup$ May you add the line: from mathutils import Euler for the code to work $\endgroup$ Commented Mar 16, 2018 at 8:36
1
$\begingroup$
  • 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

$\endgroup$
3
  • $\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
    Commented Jun 1, 2015 at 4:07
  • 4
    $\begingroup$ FYI, the big arrow looks like something else... $\endgroup$
    – Alex
    Commented Jul 1, 2018 at 6:44
  • $\begingroup$ @Alex Well you know what they say on Mars where everything is Green. Big Constraint Big Arrow. $\endgroup$ Commented Jul 2, 2018 at 17:06

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .