Currently running 2.79
I'm having issues figuring out how to select objects: This is my code, what I want it to do is create two spheres, and then resize the first created sphere after the second is created
def sphere(x, y, z, radius, resolution=30):
bpy.ops.mesh.primitive_uv_sphere_add(segments=resolution, ring_count=resolution, view_align=False, enter_editmode=False, location=(x, y, z))
bpy.ops.transform.resize(value=(radius, radius, radius), constraint_axis=(False, False, False), constraint_orientation='GLOBAL', mirror=False, proportional='DISABLED', proportional_edit_falloff='SMOOTH', proportional_size=1)
def renameActive(name):
bpy.context.active_object.name = name
def scale(x, y, z):
bpy.ops.transform.resize(value=(xScale, yScale, zScale), constraint_axis=(False, False, False), constraint_orientation='GLOBAL', mirror=False, proportional='DISABLED', proportional_edit_falloff='SMOOTH', proportional_size=1)
#change active
sphere(3,0,0,1)
renameActive("RescaleLater")
sphere(0,0,0,1)
renameActive("leaveAlone")
scene = bpy.context.scene
objs = scene.objects
rescaleSphere = objs['RescaleLater']
scene.objects.active= rescaleSphere
print(objs.active)
scale(1,2,1)
After running this, console shows:
< bpy_struct, Object("RescaleLater")>
So the active object should be what is being rescaled, but as shown below the sphere titled leaveAlone
is being scaled.
This is what shows up; the leaveAlone
sphere has been resized but in the scene outliner RescaleLater
has its name highlighted, though it's not actually 'active' in the sense where I can edit it through scripting as the activated object.
More elaboration: I know I can just resize immediately after creating the first sphere, but I need to figure this out to implement applying Boolean modifiers on specific objects (I can create the Boolean modifiers and tie them to the correct objects but haven't been able to apply), my code is more complex but this I've simplified it to this to get to the core problem of not being able to manually set the active object through python scripting. I can provide full code if helpful. Have also tried all the other versions of this question that I've seen here/elsewhere but haven't found something that works.