can't set the location of the object by program? in my blender file, I have created two vehicles objects which named as 'AudiA2' and 'JeepCherokee'

now I have created a simple program to show them on the scene with different positions created from the program.

 def choose_car_position_byname(name, pos):    

    bpy.data.objects[name].hide_render = False;    
    print("location     ", bpy.data.objects[name].location )
    bpy.data.objects[name].location = bpy.data.objects[name].location + mathutils.Vector((pos,1,0))
    print("location     ", bpy.data.objects[name].location ) 

    return bpy.data.objects[name]

 car1 = choose_car_position_byname('AudiA2',1)
 car2 = choose_car_position_byname('JeepCherokee',0)


However from the program executed, I can only see one car on the scene, which is the car2. as shown below



Ultimately I found out the second car will block the first car, because if I added the following code, two car will show up

bpy.data.objects["AudiA2"].rotation_euler.z = 270 / 180 * math.pi


as shown in here





Now the question is why I can't set the location of the obj. I have tried many ways, but none of them is not working, it is totally puzzling me. My environment is OSX 10.10.1, blender 2.76.

# first approach   
bpy.data.objects["AudiA2"].location.x += 3.0
bpy.data.objects["AudiA2"].location.y += 2.0
bpy.data.objects["AudiA2"].location.z += 0.0


# second approach
vec = mathutils.Vector((3.0, 2.0, 1.0))
inv = bpy.data.objects['AudiA2'].matrix_world.copy()
inv.invert()
vec_rot = vec * inv
bpy.data.objects['AudiA2'].location = bpy.data.objects['AudiA2'].location + vec_rot    

# third approach
bpy.data.objects["AudiA2"].location = (20, 20, 10)

# fourth approach
bpy.data.objects["AudiA2"].location[0] = 3
bpy.data.objects["AudiA2"].location[0] = bpy.data.objects["AudiA2"].location[0] + 3

#fifth approach
bpy.data.objects['AudiA2'].location = bpy.data.objects['AudiA2'].location + mathutils.Vector((3,2,0))








The code and blender files are all uploaded to dropbox.
https://www.dropbox.com/s/fxar4owxvkxrxi7/scene2.blend?dl=0
https://www.dropbox.com/s/xvsg879k2bil2pn/batch3.py?dl=0

to work with the code, you have to pip install pypng, which could be used to output the png image.To run the application, the command is similar to this- 

./blender_application_path -b blend_path -P python_path


for example

./Applications/Blender/blender.app/Contents/MacOS/blender -b scene2.blend -P batch3.py
When directly manipulating transform values fails (it shouldn't, but it does sometimes), I often just try to use the transform operators insated, and it often fixes the problem.

 def choose_car_position_byname(name, pos):    
    o = bpy.data.objects[name]
    o.hide_render = False;    
    print("location     ", o.location )

    bpy.ops.object.select_all( action = 'DESELECT' )
    o.select = True
    bpy.context.scene.objects.active = o

    bpy.ops.transform.translate( value = ( pos, 1, 0 ) )

    print("location     ", o.location ) 

    return o

 car1 = choose_car_position_byname('AudiA2',1)
 car2 = choose_car_position_byname('JeepCherokee',0)


By the way, if this still fails, check if you have keyframes on the car objects' locations. If you do, that could definitely explain why they aren't moving (the keyframes will keep them in place).

EDITED: based on blend file, my suspicion has indeed been confirmed that you have keyframes on your car models. You need to delete these keyframes to enable control over the objects' locations via script. Here's how to do this (mouse cursor is a bit off due to weird issues in recording on my laptop's screen, you need to select a car object, then right click on any of the location boxes in the properties panel):