Create and return a cube using a python script 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
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)