0

With the default scene with the cube selected, consider this script:

import bpy

bpy.context.active_object.dimensions = (10,10,10) bpy.context.active_object.matrix_world.translation = (1,1,1)

This code should make the sides of the cube 10 meters long, and then move it. However, the dimension change is ignored. If I reverse the order of the statements, it works. Also if I run the statements separately, they work. Is this a bug or is there something more I need to do? I tried to call

bpy.context.collection.objects.update()

between the statements, without any effect. I am creating a plugin where I have to change the dimensions first before moving an object, so reversing the order of the statements is not a feasible fix in my case.

Martin
  • 1
  • 1
  • My guess is same issue as here. https://blender.stackexchange.com/a/234068/15543 Use scale not dimension. Make a translation matrix T and a scale matrix S then T @ S @ matrix_world is the result. – batFINGER Aug 13 '21 at 10:55
  • I see, I guess the trick is to make an semi-atomic update of matrix_world. – Martin Aug 16 '21 at 08:30
  • The edge cases of setting dimension property has always been an issue. (eg setting 3D dim to 2D object as in link) Suggest use scale not dimension. Setting dimension sets scale based on modified unit size https://blender.stackexchange.com/questions/212926/how-to-get-the-base-dimensions-of-an-object-ignoring-all-of-its-modifiers For example could calc scale based on current dimension eg if cube currently dimension (8, 4, 4) -> calc scale to (1.25, 2.5, 2.5) and apply it to matrix world. – batFINGER Aug 16 '21 at 09:00
  • Okey, good spotting! We do something like the suggested above in the code base now. – Martin Aug 16 '21 at 14:40

0 Answers0