0
$\begingroup$

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.

$\endgroup$
5
  • $\begingroup$ 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 $\endgroup$ Feb 8, 2023 at 0:56
  • $\begingroup$ @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. $\endgroup$ Feb 8, 2023 at 12:58
  • $\begingroup$ I added this at the beginning and end of the script but it did not help: bpy.context.view_layer.update() $\endgroup$ Feb 8, 2023 at 13:05
  • $\begingroup$ can you share the blend file with the "defective" object? $\endgroup$ Feb 8, 2023 at 13:57
  • $\begingroup$ Voting to close as it lacks details. We will need blend file. $\endgroup$ Feb 8, 2023 at 15:11

1 Answer 1

0
$\begingroup$

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.

$\endgroup$

You must log in to answer this question.

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