0
$\begingroup$

Could someone explain this to me?

bpy.ops.mesh.primitive_cube_add(size=2)
obj = bpy.context.object
obj.location = (1, 2, 3)
obj.dimensions = (1, 2, 3)
print(obj.dimensions) # => <Vector (2.0000, 2.0000, 2.0000)>

I have a longer script but basically does the same thing. I'm trying to grab the obj.dimensions.z of a current obj, bpy.context.object, after I change it. But it keeps giving me the original value before it was changed. Even though the scale is applied. Am I missing something really obvious?? Thanks all. I am losing my mind.

enter image description here

$\endgroup$
4
  • $\begingroup$ bpy dimensions are for the unscaled object. You need to apply scale in object mode if you want them to match or you need to multiply by the object's world matrix. $\endgroup$ Commented Jan 7, 2022 at 17:25
  • $\begingroup$ I'm confused, what do you mean 'for the unscaled object'?? Applying the scale would give me the correct dimensions? $\endgroup$ Commented Jan 7, 2022 at 17:27
  • $\begingroup$ You're confused because I was confused. Ignore my comment. Sorry. $\endgroup$ Commented Jan 7, 2022 at 17:28
  • 1
    $\begingroup$ Well, dude I applied the scale and it came out correctly... bpy.ops.object.transform_apply(location=False, rotation=False, scale=True) print(obj.dimensions) # => <Vector (1.0000, 2.0000, 3.0000)> $\endgroup$ Commented Jan 7, 2022 at 17:30

1 Answer 1

0
$\begingroup$

So I don't like this answer because I feel like in earlier versions you could just grab the dimensions of an object as it stood in that moment... But apparently you need to "apply the scale". Thanks Marty, even though you were confused the suggestion worked. So,

        obj.dimensions.z = height_block
        bpy.ops.object.transform_apply(location=False, rotation=False, scale=True)

        ##### OBJ PROPERTIES ########
        #############################
        x_dimension, y_dimension, z_dimension = obj.dimensions
        print(z_dimensions) # => 3

If anyone can explain this better for me I'd love to understand it more in depth.

$\endgroup$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .