# How to get Global object location - Python

I'm trying to make script which will get object.location but it doesn't works: result of my script is:

Trawa.196 and its location is: Vector (0.0000, 0.0000, 0.0000)>

And every object in my scene has these values

ObjectName = "Grass."

for i in range(1,200):
if(i<10):

objectTrawa = bpy.data.objects[str(ObjectName)]
objectTrawa.select = True
print(ObjectName, "and its location is: ", objectTrawa.location)
bpy.ops.object.select_all(action='DESELECT')
if(i>=10 and i<100):
objectTrawa = bpy.data.objects[str(ObjectName)]
objectTrawa.select = True
print(ObjectName, "and its location is: ", objectTrawa.location)
bpy.ops.object.select_all(action='DESELECT')
if(i>=100):
objectTrawa = bpy.data.objects[str(ObjectName)]
objectTrawa.select = True
print(ObjectName, "and its location is: ", objectTrawa.location)
bpy.ops.object.select_all(action='DESELECT')

• have you tried debugging parts of your script using the build in python console? Jun 3 '18 at 14:29
• Try objectTrawa.matrix_world.translation for the final world matrix location. Jun 3 '18 at 14:49
• Also this is how you pad zeros before string to keep it length 3: str(15).zfill(3), that should simplify your code a lot. Jun 3 '18 at 14:55

Thanks @Jaroslav Jerryno Novotny for help: I'm dumb because I forgot to select everything and set origin to center of its surface/volume (every object had pivot in the middle). But anyway thanks for "objectTrawa.matrix_world.translation" I will use it instead of location and zfill() function (I didn't even think that this would be so good for my code)

final code

ObjectNameNumber = 1

for i in range(1,649):