1
$\begingroup$

2.82 Python api is not executing the resizing with individual origins, like when the same operation is done with the cursor. I change the transform pivot point to individual origins but the script is only scaling the cubes from median centers, so the cubes are moving away. I need them to scale from individual origins so at one poing they merge together. Any idea how to make this work with python api, or if this a bug. It seems like a really basic operation.

The code:

import bpy
bpy.context.scene.tool_settings.transform_pivot_point = 'INDIVIDUAL_ORIGINS'
bpy.ops.mesh.primitive_cube_add(enter_editmode=False, location=(0, 0, 0))
bpy.ops.mesh.primitive_cube_add(enter_editmode=False, location=(3, 0, 0))
bpy.ops.object.select_all(action='SELECT')
bpy.ops.transform.resize(value=(1.77118, 1.77118, 1.77118))

enter image description here

$\endgroup$
4
$\begingroup$

Avoid ops for easy operations.

IMO many ops are a bridge between the user and the UI. For simple operations it is often simpler to set property values directly.

After the op cube has context. cube = context.object .

bpy.ops.mesh.primitive_cube_add()
cube = context.object

To uniformly scale about the origin

cube.scale *= 1.7718

Alternatively can set size in the operator

bpy.ops.mesh.primitive_cube_add(size=2 * 1.7718)

which will "apply" the scale.

Finally: To have the two cubes only touching use 1.5

$\endgroup$
2
  • $\begingroup$ Ok so I am using for obj in bpy.data.objects: obj.scale *= 1.7718 $\endgroup$ – terseason Apr 14 '20 at 9:33
  • $\begingroup$ Thank you, I didn't know how the api worked, and when stop following the info window with python commands. $\endgroup$ – terseason Apr 14 '20 at 9:35

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.