2
$\begingroup$

How to get location from a list with python?

list = ["Cube1","Cube2", "Cube3"]

How can I get the Y location for the list?

I can get it for each individual object:

C1= bpy.data.objects["Cube1"].location

But I don't know how to convert list to [(X,Y,Z),(X,Y,Z),(X,Y,Z)]

$\endgroup$
  • 3
    $\begingroup$ loclist = [bpy.data.objects[name].location[:] for name in namelist]? Or .location.y for the Y's? But maybe is this a Python question, not a Blender question? $\endgroup$ – Robin Betts Jul 4 at 22:52
4
$\begingroup$

Assuming we have the default cube and three clones as our object names, we can build new lists for the locations, and the Y locations. You asked for both in the question and I was unsure which you actually wanted...

import bpy

list = ["Cube","Cube.001", "Cube.002", "Cube.003"]
locations = []
yLocs = []

for n in list:
    locations.append( bpy.data.objects[n].location )
    yLocs.append( bpy.data.objects[n].location.y )
    
print( locations )
print( yLocs )
| improve this answer | |
$\endgroup$

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.