I want to run this script and have it pick up references the four pre-existing "my_xxx" objects, so that the script can then operate on them. However, all four variables end up referring to my_Sun, and it is the only object that moves.
Question: I would like to understand why this isn't working the way I expect, am I missing something obvious?
Question: What is the correct way to assign python variables to pre-existing objects based on name, if this isn't right?
import bpy
bpy.ops.object.select_all(action="DESELECT")
bpy.ops.object.select_pattern(pattern="my_Cube")
cube = bpy.context.active_object
bpy.ops.object.select_all(action="DESELECT")
bpy.ops.object.select_pattern(pattern="my_Cone")
cone = bpy.context.active_object
bpy.ops.object.select_all(action="DESELECT")
bpy.ops.object.select_pattern(pattern="my_Suzanne")
monkey = bpy.context.active_object
bpy.ops.object.select_all(action="DESELECT")
bpy.ops.object.select_pattern(pattern="my_Sun")
sun = bpy.context.active_object
bpy.ops.object.select_all(action="DESELECT")
print ("monkey.name: ", monkey.name)
print ("cone.name : ", cone.name)
print ("cube.name: ", cube.name)
print ("sun.name: ", sun.name)
monkey.location = 5,5,5 # note to self: use "location" not "position" !!!
cone.location = 5,5,5
cube.location = 5,5,5
sun.location = 5,5,5
Output to terminal:
monkey.name: my_Sun
cone.name : my_Sun
cube.name: my_Sun
sun.name: my_Sun
RESULTS: Only sun is moved to new location 5, 5, 5


cone. Then I am thinking I clear all selection withbpy.ops.object.select_all(action="DESELECT")and then make the next object the active object. Thus the second part of the question "What is the correct way to assign python variables to pre-existing objects based on name...?" – uhoh Mar 17 '16 at 10:14prints andobj.locationassignments are just to demonstrate that what I am trying to do is not working. I'll fix the "position" - I'm trying to integrate with Skyfield whereobj.locationis calledobj.position(), and when I retyped the line during cleanup (delete other debugging lines) I must have crossed wires. – uhoh Mar 17 '16 at 10:20objects.get(name)where objects is one of the objects collection bpy.data.objects (all in fle) scene.objects (all in scene) or it returns None if there is no object with name name. To make it the active object use 'scene.objects.active = scene.objects.get("my_Doughnut")` Which is my answer again really. – batFINGER Mar 17 '16 at 10:20bpy.context.active_object- is that less reliable? Is it causing trouble here? – uhoh Mar 17 '16 at 10:29