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:


    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)
  • 1
    $\begingroup$ Are you trying to change the dimensions of every object? $\endgroup$ – Robert Gützkow Oct 25 '19 at 20:48
  • $\begingroup$ FWIW I dispute the claim that the code posted works in any version. $\endgroup$ – batFINGER Nov 28 '19 at 12:44

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.

| improve this answer | |
  • 2
    $\begingroup$ or obj.dimensions *= multiple $\endgroup$ – batFINGER Nov 28 '19 at 12:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.