In the following post, I learned how to create cubes of the size I want.
how to set a custom scale size for an object once shortcut button is pressed?
def draw(self, context):
object = context.object
layout = self.layout
row = layout.row()
row.operator("mesh.primitive_cube_add").scale=(1, 1, 1)
I used this code to add an additional location and rotation value. However, it does not work
I want to add position, scale and rotation values to the row.operator("mesh.primitive_cube_add") code.
Here's the code:
def draw(self, context):
object = context.object
layout = self.layout
row = layout.row()
row.operator("mesh.primitive_cube_add").location=(0, 0, 5), rotation=(0, 0, 10), scale=(1, 1, 1)
======================== Add ===========================
How to pass multiple operator properties via UI layout?
brockmann's answer in the next post is the way I want it to be.
I write it down as below, and all functions work fine.
I want to write the rotation value in one line like location or scale, but I do not know how to write it, so I wrote it in 3 lines.
Thank you brockmann!
import bpy
import math
.
.
.
def draw(self, context):
object = context.object
layout = self.layout
row = layout.row()
props = row.operator("mesh.primitive_cube_add")
props.enter_editmode=False
props.location = (0, 0, 5)
props.rotation[0] = math.radians(0)
props.rotation[1] = math.radians(0)
props.rotation[2] = math.radians(10)
props.scale = (1, 1, 1)
props.rotation = (math.radians(0), math.radians(1), math.radians(2))should do the trick, see: https://docs.blender.org/api/current/bpy.ops.mesh.html?highlight=primitive_cube_add#bpy.ops.mesh.primitive_cube_add ((float array of 3 items in [-inf, inf], (optional))) – brockmann Oct 01 '21 at 06:21primitive_cube_add(), answer is no (click here). Otherwise you'd have to use the Bmesh module: https://docs.blender.org/api/current/bmesh.html?highlight=bmesh#module-bmesh How to create a cube using Bmesh has already been explained over here -> https://blender.stackexchange.com/questions/63546/create-a-cube-in-blender-from-python and there are a lot of high quality Q&A's, just search for it: https://blender.stackexchange.com/search?tab=votes&q=bmesh – brockmann Oct 01 '21 at 07:12