2
$\begingroup$

The default command when creating a cube at the origin is the following:

bpy.ops.mesh.primitive_cube_add(view_align=False, enter_editmode=False, location=(0.0, 0.0, 0.0), rotation=(0, 0, 0), layers=(True, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False))

since I am not bothered about rotations and layers I can keep only the location like so:

bpy.ops.mesh.primitive_cube_add(location=(0.0, 0.0, 0.0))

This creates a UNIT cube at the origin (0,0,0).

My question is: Is there a way to add the dimensions of the cube I want, within that line somehow?

I am not asking about using a scale command after creating it... but rather creating it in the desired size straight away...?

$\endgroup$
  • $\begingroup$ May I ask you a question as someone new to scripting? Why would you script out the addition of a small/large cube? Is it faster? Is it simply more fun to script? I can understand using scripting for more complex operations but just wondering why someone would type out all of that code for what seems like an otherwise quick operation? Add > S > (numerical value) John $\endgroup$ – John Nov 8 '19 at 21:35
  • $\begingroup$ @John You would use a script whenever you have to do something procedurally (model/build/representation), not when you are manually modelling something... then the shortcuts and UI are much more practical :) $\endgroup$ – G.Rassovsky Nov 11 '19 at 10:49
3
$\begingroup$

Yes, you can use radius

bpy.ops.mesh.primitive_cube_add(location=(0.0, 0.0, 0.0), radius=2)

See the documentation for more details.

radius in this case is the half of the cubes edge length, so

bpy.ops.mesh.primitive_cube_add(location=(0.0, 0.0, 0.0), radius=edgelen/2)

would build a cube with edge length of edgelen.

Answer uses the Python API of Blender 2.72

| improve this answer | |
$\endgroup$
  • 1
    $\begingroup$ I get: TypeError: Converting py args to operator properties: : keyword "radius" unrecognized but I think this might be due to the fact that I am still using the 2.66 release. What I needed was a way of specifying exact dimensions, not a scale rate, but I guess this is still something. Thank you. $\endgroup$ – G.Rassovsky Oct 10 '14 at 13:38
  • $\begingroup$ So you want a cuboid instead of a cube? Yes my answer was for 2.72. $\endgroup$ – user2859 Oct 10 '14 at 13:41
  • $\begingroup$ Well the script I need would ultimately have to handle cuboids too, however in the general case it would just be cubes of different sizes, that I need to create. $\endgroup$ – G.Rassovsky Oct 10 '14 at 13:43
  • $\begingroup$ For a cube with specific edge length you would just need to devide by 2. radius=edgelen/2. $\endgroup$ – user2859 Oct 10 '14 at 13:50
3
$\begingroup$

In Blender 2.8 you must use size, the radius is not more a parameter :

bpy.ops.mesh.primitive_cube_add(location=(x,y,z),size=10)

If you try to use radius you will have:

TypeError: Converting py args to operator properties: : keyword "radius" unrecognized

More on the docs.

| improve this answer | |
$\endgroup$

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.