Page MenuHome

Assignments not working properly for Object.dimensions
Closed, InvalidPublic

Description

Working:

bpy.context.object.dimensions.z = 5
bpy.context.object.dimensions.xy = (2,2)
bpy.context.object.dimensions.xyz = (3,3,3)
bpy.context.object.dimensions.zxy = (3,5,4)
bpy.context.object.dimensions.zyx = (1,2,3)
bpy.context.object.dimensions.xzy = (7,6,5)

Not working:

bpy.context.object.dimensions.xz = (3,3) --> sets X to 3, Y to 0 and keeps previous Z
bpy.context.object.dimensions.yz = (2,2) --> sets X to 0, Y to 2 and keeps previous Z
bpy.context.object.dimensions.zx = (5,5) --> sets X to 5, Y to 0 and keeps previous Z
Auto-complete suggestion, that do not work: any combination of four like xyzw or duplicates like xzz --> Error not writeable


Furthermore, it's not possible to set dimensions individually (happened in modal func):
bpy.context.object.dimensions.x = 1
bpy.context.object.dimensions.y = 2
bpy.context.object.dimensions.z = 3
--> only z (the last assignment) was applied

Example: run script from attached .blend, move mouse, then hit Esc --> Z will reset, X and Y will be kept

Details

Type
Bug

Event Timeline

At first glance I would say that "Vector_swizzle_set()" in mathutils_Vector.c does undesired stuff with memcopy.
[the same thing happens not just for "dimensions" but for location as well]

I attached a patch that appears to solve the first part (assigning .xz .yz .zx) though this is just a suggestion

havent looked into assigning .x .y .z though...

separate assignments after each other seem to work if scene gets updates in-between:

context.object.dimensions.x = self.first_value_x
context.scene.update()
context.object.dimensions.y = self.first_value_y
context.scene.update()
context.object.dimensions.z = self.first_value_z
context.scene.update()

but it shouldn't be required imo

First part of the bug is fixed in svn47754 (thanks Philipp for pointing the source of the problem).

The multi-assignement bug (which is specific to dimension) I’m not sure about, let’s see what campbell says (when he has some time free from Mango project ;) ). As a workaround, you can use .scale instead for now…

Hi there.
I also point out this: (ob references an Object)

i run:

ob.dimensions[0]+=0.5

works

ob.dimensions[0]+=0.5
ob.dimensions[1]+=0.5

only last works

ob.dimensions[0]+=0.5
ob.dimensions[1]+=0.5
ob.dimensions[2]+=0.5

only very last works.

the weird is that the problem manifests only from text editor. in python console it works all fine.

Thanks!!


The problem is that the in order to modify the dimensions correctly, the object matrix needs to be recalculated, which in general needs a full update of the scene. In simple cases it might be possible to do without but with modifiers, dependencies, it's required and setting the dimensions might not even be exact.

The fact that you either need to update them all at once or need to do a scene update I would not consider a bug. The python console can do a scene update between commands but for scripts this would be much too slow. It's strange but remember this is a convenience function to indirectly edit data, it's more intended as a tool for users than scripters.