Assignments not working properly for Object.dimensions #31760

Closed
opened 2012-06-09 01:06:53 +02:00 by CodeManX · 7 comments
Member

%%%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%%%

%%%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%%%
Author
Member

Changed status to: 'Open'

Changed status to: 'Open'
Member

%%%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...%%%

%%%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...%%%
Author
Member

%%%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%%%

%%%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…%%%

%%%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- [x]+=0.5

works

ob.dimensions- [x]+=0.5
ob.dimensions- [x]+=0.5

only last works

ob.dimensions- [x]+=0.5
ob.dimensions- [x]+=0.5
ob.dimensions- [x]+=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!!

%%%

%%%Hi there. I also point out this: (ob references an Object) i run: ob.dimensions- [x]+=0.5 works ob.dimensions- [x]+=0.5 ob.dimensions- [x]+=0.5 only last works ob.dimensions- [x]+=0.5 ob.dimensions- [x]+=0.5 ob.dimensions- [x]+=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.%%%

%%%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.%%%

Changed status from 'Open' to: 'Archived'

Changed status from 'Open' to: 'Archived'
Sign in to join this conversation.
No Milestone
No project
No Assignees
5 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: blender/blender-addons#31760
No description provided.