# Problem rescaling objects in Python

I am using the following code to rescale objects (to ~15) from a collection (Blender 3.4.)

    Current_Dimension = max(obj.dimensions.x, max(obj.dimensions.y, obj.dimensions.z))
if Current_Dimension > 0:
New_Scale = 15 / Current_Dimension
obj.scale = (New_Scale, New_Scale, New_Scale)


It works perfectly on almost all objects in my collection except a few that do not rescale. I am guessing either the Current_Dimension is wrong, or it is 0 for some reason. Any help would be appreciated.

• Hello and welcome. Have you tried printing the scale of those problematic objects before running the code on them? can you perhaps share the blend file of one sample object that is problematic? blend-exchange.com Feb 8 at 0:56
• @HarryMcKenzie So I did some printf of the problem object but the values seem normal: Current_Dimension: 179.7638397216797 <obj.dimensions (179.7638, 95.5675, 179.7638)> New_Scale: 0.08344281042963829 But after running the script, if I go see the scale in object edit mode, I can see that the scale is 0.286 instead of 0.083.. for some reason. Feb 8 at 12:58
• I added this at the beginning and end of the script but it did not help: bpy.context.view_layer.update() Feb 8 at 13:05
• can you share the blend file with the "defective" object? Feb 8 at 13:57
• Voting to close as it lacks details. We will need blend file. Feb 8 at 15:11

Ok after some debugging, I was able to figure out the problem was this line:

Current_Dimension = max(obj.dimensions.x, max(obj.dimensions.y, obj.dimensions.z)


It did not take into account the current scaling of the object. So the corrected line should be:

Current_Dimension = max(obj.dimensions.x / obj.scale.x, max(obj.dimensions.y / obj.scale.y, obj.dimensions.z / obj.scale.z))


Most of the objects did not have any scaling so it was working for those.

Before I started creating this script, I was trying to scale manually some of the objects and realized it would take forever. So, all those objects that I had previously scaled did not work.