I'm making a simple script that adds a cube and moves it, and then I want to shift some of the faces, in order to change the cube's width height or depth. When I run it, the cube is created and moved, but altering de cube's dimensions gives an error:
convertViewVec: called in an invalid context
I'm using the code that's shown in the Info window when I select a face and drag it along one of the axes. I'm new to Blender and I can't figure out what's missing here..
import bpy
bpy.ops.mesh.primitive_cube_add()
bpy.ops.transform.translate(value=(0, 6.04281, 0), constraint_axis=(False, True, False), constraint_orientation='GLOBAL', mirror=False, proportional='DISABLED', proportional_edit_falloff='SMOOTH', proportional_size=1, release_confirm=True)
bpy.ops.transform.translate(value=(0, 0, -5.22667), constraint_axis=(False, False, True), constraint_orientation='GLOBAL', mirror=False, proportional='DISABLED', proportional_edit_falloff='SMOOTH', proportional_size=1, release_confirm=True)
bpy.ops.transform.translate(value=(0, 2.9328, 0), constraint_axis=(False, True, False), constraint_orientation='GLOBAL', mirror=False, proportional='DISABLED', proportional_edit_falloff='SMOOTH', proportional_size=1, release_confirm=True)
bpy.ops.object.editmode_toggle()
bpy.ops.transform.translate(value=(0, 1.03954, 0), constraint_axis=(False, True, False), constraint_orientation='GLOBAL', mirror=False, proportional='DISABLED', proportional_edit_falloff='SMOOTH', proportional_size=1, release_confirm=True)
Edit - Solved it by creating a custom geometry, as shown here: How to create a mesh programmatically, without bmesh? (Pointed out by @poor)
The following code now creates a flat cube:
import bpy
verts = [
(2.0, 1.0, -1.0),
(2.0, 0.99, -1.0),
(-1.0, 0.99, -1.0),
(-1.0, 1.0, -1.0),
(2.0, 1.0, 1.0),
(2.0, 0.99, 1.0),
(-1.0, 0.99, 1.0),
(-1.0, 1.0, 1.0)]
faces = [
(0, 1, 2, 3),
(4, 7, 6, 5),
(0, 4, 5, 1),
(1, 5, 6, 2),
(2, 6, 7, 3),
(4, 0, 3, 7)]
mesh_data = bpy.data.meshes.new("cube_mesh_data")
mesh_data.from_pydata(verts, [], faces)
mesh_data.update()
obj = bpy.data.objects.new("My_Object", mesh_data)
scene = bpy.context.scene
scene.objects.link(obj)
obj.select = True