Python named variable problem reconciling bpy.type and bpy.ops

This might fall into the “you don’t need that” category, but knowing this may payoff in the future. I’m using a script to make a bunch of planes. I want to resize each plane before exiting the loop. Tried two methods, one works fine (before I name the variable) while the other fails (named variable) despite the ‘rotation_Euler’ working. I must be mixing up types. ‘rotation_Euler’ seems to be a Basic Object Operation reference by ‘bpy.types.Object’ which is right there in the assignment of the object to the name =‘o’ but the transform uses the reference ‘bpy.ops.transform

How do I correctly assign a variable name such that I can do the transform?

#default values
defaultSquareSize = 1
griddivs_Y = 4
griddivs_X = 4

def draw_grid(W, H, box):
while H != 0:
wTest = W
while wTest != 0:
x = defaultSquareSize * (wTest - 1)
y = defaultSquareSize * (H - 1)

creating the plane works just fine

    bpy.ops.mesh.primitive_plane_add(size=1, enter_editmode=False, align='WORLD', location=(x, y, 0))

resizing the plane works just fine

    bpy.ops.transform.resize(value=(padding, padding, 1))

creating a named variable for the object isn’t an issue

    o = bpy.context.active_object
    #o = bpy.context.object

rotating the object using its variable name works fine

    o.rotation_euler[2] = radians(20)

transform throws an AttributeError: ‘Object’ object has no attribute ‘transform’

    o.transform.resize(value=(padding, padding, 1))

    wTest -= 1
H -= 1

draw_grid(griddivs_X, griddivs_Y, defaultSquareSize)

Like the error message says, o.transform is wrong because o is an object and objects don’t have transform

I think probably you want object.scale. You can use this in the same way as you used rotation_euler. For example:
o.scale[0] = 2
or
o.scale = (2, 1, 1)
will set the scale of object o to 2 along the x-axis.

You could also do
o.scale[0] *= 2
or
o.scale *= mathutils.Vector((2, 1, 1))
if you want to take the existing scale of the object into account.

Alternatively, you could keep using bpy.ops.transform.resize() - it’ll always work on whichever object blender decides is the active object, so you don’t need to give it a specific object to act on.

Thanks, I thought it must be a type issue and it was. I can make this work for what I’m doing by applying the scale change before moving on with my other manipulations.

I’m going back to the API to see what makes the ops domain different from the obj domain and what each can do.

Thanks again for the help.