1
$\begingroup$

This code should resize objects. It works great in 2.79, but not in 2.8.

I get this error:

AttributeError: 'bpy_prop_collection' object has no attribute 'dimensions'

This is my code, I can't find the error:

   #SCALE AUTOMATICALLY

    dimX = bpy.context.scene.objects.dimensions.x
    dimY = bpy.context.scene.objects.dimensions.y
    dimZ = bpy.context.scene.objects.dimensions.z

    multiple = 5 / dimZ

    bpy.context.scene.objects.dimensions = (dimX * multiple, dimY * multiple, 5)
$\endgroup$
2
  • 1
    $\begingroup$ Are you trying to change the dimensions of every object? $\endgroup$
    – Robert Gützkow
    Commented Oct 25, 2019 at 20:48
  • $\begingroup$ FWIW I dispute the claim that the code posted works in any version. $\endgroup$
    – batFINGER
    Commented Nov 28, 2019 at 12:44

1 Answer 1

1
$\begingroup$

You're referring to multiple objects, which altogether have no attribute "dimensions". Each individual object has, though:

for obj in bpy.context.scene.objects: 
    dimX, dimY, dimZ = obj.dimensions
    multiple = 5/dimZ
    obj.dimensions = (dimX * multiple, dimY * multiple, 5)

Be aware that division by zero could be an issue. Also I'm not sure if all objects have dimensions (cameras?). You could add if obj.type != "MESH" or dimZ == 0: continue as the second line of your forloop.

$\endgroup$
1
  • 2
    $\begingroup$ or obj.dimensions *= multiple $\endgroup$
    – batFINGER
    Commented Nov 28, 2019 at 12:45

You must log in to answer this question.

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