7
$\begingroup$

So I've very new to Blender coding. Here's what I'm trying to do:

cubeobject = bpy.ops.mesh.primitive_cube_add
cubeobject.scale = (-2.2,0,0)

I can't get this to work. I've tried SizeX settings and other translate functions, but nothing seems to work. I'm sure that reference method is wrong, but I've combed the forums for 20 mins with no progress.

$\endgroup$

2 Answers 2

10
$\begingroup$

What to do

You need to play around with the python console for this stuff.

Here is probably what you want (sets the value directly in the properties panel, absolute method):

bpy.ops.mesh.primitive_cube_add()
bpy.context.scene.objects.active.scale = (-2.2, 0, 0)

You may also want to scale like this (scales object the same way as pressing S in the 3D view, relative method):

bpy.ops.mesh.primitive_cube_add()
bpy.ops.transform.resize(value=(-2.2, 0, 0))

When an object is created, it is selected and set active so my examples will work in a simple case like this without a reference to the object.

Why your script won't work

  1. bpy.ops.mesh.primitive_cube_add doesn't do anything useful (it won't create an object)
  2. bpy.ops.mesh.primitive_cube_add() only returns {'FINISHED'} not a reference to the new object.
$\endgroup$
3
$\begingroup$

I think what you need is transform.resize. It's not scale :)

https://www.blender.org/api/blender_python_api_2_77_3/bpy.ops.transform.html?highlight=size#bpy.ops.transform.resize

$\endgroup$
1
  • $\begingroup$ What's the easiest method of examining the class tree maps? As in one path is used to create an object, and another path is used to modify that object. I see great docs on individual commands, but no master tree diagram. Still searching. $\endgroup$
    – Dr Tyrell
    Aug 29, 2016 at 21:27

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .