1
$\begingroup$

In the above code, I need to change the location and the dimension of the cube. I remark that only the dimensions along the z-axis is changed. How can I change the name of the cube? I have not been able to find out how to do this in the documentation.

  import bpy
    from mathutils import Matrix
    D = bpy.data
    C = bpy.context
    scene = C.scene

    # ... lots of code omitted for brevity and clarity

    #------------------House-------------

    #Wall1
    bpy.ops.mesh.primitive_cube_add(location=(0.0, 2.0, 1.25))
    bpy.context.object.data.name = "Cube1" #to change the name but it does not work
#here to change the dimensions, but only the z-axis dimension has been changed
    bpy.context.object.dimensions[0] = 4
    bpy.context.object.dimensions[1] = 0.05
    bpy.context.object.dimensions[2] = 2.5
$\endgroup$
1
  • 2
    $\begingroup$ When you assign a string to bpy.context.object.data.name it will overwrite the data name, see: i.sstatic.net/HtmtO.png instead of the object name... Please avoid asking multiple questions. Thanks $\endgroup$
    – p2or
    Commented Jun 24, 2015 at 7:05

2 Answers 2

2
$\begingroup$

When you write

bpy.context.object.data.name = "Cube1" #to change the name but it does not work

you are changing the name of the MESH datablock. To change the name of the OBJECT datablock:

bpy.context.object.name = "Cube1"

I would recommend altering the scale of the object instead of the dimensions.

bpy.context.object.scale = (2, 0.025, 1.25)
$\endgroup$
1
$\begingroup$

to resize (scaling ) the cube, we can use this function

#Wall1
bpy.ops.mesh.primitive_cube_add(location=(0.0, 2.0, 1.25))
#resize the cube
bpy.ops.transform.resize(value=(4, .05, 2.5))

to rename, we can use this instruction

# Get the cube object and rename it.
cube = bpy.context.object
cube.name = 'Wall1'

but I did not understand why this first way did not work

$\endgroup$
1
  • $\begingroup$ Resize function working great $\endgroup$ Commented Dec 6, 2020 at 13:30

You must log in to answer this question.

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