1
$\begingroup$

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.

$\endgroup$
2
  • $\begingroup$ Do you see any unwanted messages in the Console Window? convertViewVec: called in an invalid context $\endgroup$ Jan 5 '16 at 7:21
  • $\begingroup$ 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. $\endgroup$
    – Gabriel
    Jan 5 '16 at 9:06
3
$\begingroup$

The core of this question is

import bpy

bpy.ops.mesh.primitive_circle_add(vertices=5, radius=1, location=(0, 0, 0))

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

versus

import bpy

bpy.ops.mesh.primitive_circle_add(vertices=5, radius=1, location=(0, 0, 0))
# this does
dims = bpy.context.object.dimensions
bpy.context.object.dimensions = 0.7, 0.7, dims[2]

Plugged into your sample code:

import bpy

bpy.ops.mesh.primitive_circle_add(vertices=5, radius=1, location=(0, 0, 0))
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]

enter image description here

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).

$\endgroup$
3
  • $\begingroup$ This wasn't what I wanted. I wanted to change the dimension value and not scale value. Your code changes only the scale value. $\endgroup$
    – Gabriel
    Jan 5 '16 at 8:52
  • $\begingroup$ 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? $\endgroup$
    – Gabriel
    Jan 6 '16 at 3:08
  • $\begingroup$ your example code did print messages into the output of Terminal / Command Prompt, but they are not caused by the setting of obj.dimensions. $\endgroup$
    – zeffii
    Jan 6 '16 at 10:48

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.