# Problems with assigning dimensions through python script

I don't know how to put this, as a bug or error in code. Anyway here is my code,

bpy.ops.mesh.primitive_circle_add(vertices=5, radius=1, location=(0, 0, 0))
bpy.ops.object.mode_set(mode = 'EDIT')
bpy.ops.mesh.select_mode(type="VERT")
bpy.ops.mesh.extrude_region_move(MESH_OT_extrude_region={"mirror":False},
TRANSFORM_OT_translate={"value":(0, 0, 30)})
bpy.ops.object.mode_set(mode = 'OBJECT')
bpy.context.object.dimensions[0] = 0.7  // Does not work
bpy.context.object.dimensions[1] = 0.7


The code as you can see creates a mesh circle and extrudes its vertices and then set its dimensions for X and Y axis as 0.7. Well the code executes fine, but the dimension for X does not change. It remains at some 1.902.. . I need help in rectifying this problem.

Note: I am using Blender 2.75.

• Do you see any unwanted messages in the Console Window? convertViewVec: called in an invalid context Jan 5 '16 at 7:21
• No unwanted messages. I don't think print statements are needed, as the values are reflected in Number panel( " N ").But, as far as I can see the value for dimensions[0] i.e X remains 1.902. In other words, the statement "bpy.context.dimension[0] = 0.7" has no effect on my object. But the next statement "bpy.context.dimension[1] = 0.7" works i.e the value of X dimension refuses to change using python script. Jan 5 '16 at 9:06

The core of this question is

import bpy

# this doesn't produce expected results
bpy.context.object.dimensions[0] = 0.7
bpy.context.object.dimensions[1] = 0.7


versus

import bpy

# this does
dims = bpy.context.object.dimensions
bpy.context.object.dimensions = 0.7, 0.7, dims[2]


import bpy

obj = bpy.context.object  # might need it later

bpy.ops.object.mode_set(mode = 'EDIT')
bpy.ops.mesh.select_mode(type="VERT")
bpy.ops.mesh.extrude_region_move(MESH_OT_extrude_region={"mirror":False},
TRANSFORM_OT_translate={"value":(0, 0, 30)})
bpy.ops.object.mode_set(mode = 'OBJECT')

current_x, current_y, current_z =  obj.dimensions
obj.dimensions = [0.7, 0.7, current_z]


### Why?

There is a bug report about it here https://developer.blender.org/T31760

it's a known error/limitation, and down to the property being intended to be used on the UI only.

For now either use obj.scale (with some extra manual calculation) or set the obj.dimensions all three at once (as shown).

• This wasn't what I wanted. I wanted to change the dimension value and not scale value. Your code changes only the scale value. Jan 5 '16 at 8:52
• Thanks, It works. I tried the second solution. But I didn't get any Invalid Context Error. Anyway thanks. Any Idea why, my own code didn't work? Jan 6 '16 at 3:08
• your example code did print messages into the output of Terminal / Command Prompt, but they are not caused by the setting of obj.dimensions. Jan 6 '16 at 10:48