0
$\begingroup$

I'm studying scripting in blender, I am pretty much taking notes of the actions I do in the blender interface and creating the same in a separated script.

One thing I can accomplish in the Blender UI that I can't in the script is extrude the base of a cone in edit mode, see script below:

import bpy

bpy.ops.mesh.primitive_cone_add(location=(0,0,0))
bpy.ops.transform.translate(value=(0, 0, 1.94102), constraint_axis=(False, False, True), constraint_orientation='GLOBAL', mirror=False, proportional='DISABLED', proportional_edit_falloff='SMOOTH', proportional_size=1, release_confirm=True)
bpy.ops.object.editmode_toggle()
bpy.ops.mesh.select_mode(use_extend=False, use_expand=False, type='FACE')
bpy.ops.mesh.select_all(action='TOGGLE')
bpy.ops.mesh.extrude_region_move(MESH_OT_extrude_region={"mirror":False}, TRANSFORM_OT_translate={"value":(-1.97143e-009, 3.68831e-009, 0.447236), "constraint_axis":(False, False, True), "constraint_orientation":'NORMAL', "mirror":False, "proportional":'DISABLED', "proportional_edit_falloff":'SMOOTH', "proportional_size":1, "snap":False, "snap_target":'CLOSEST', "snap_point":(0, 0, 0), "snap_align":False, "snap_normal":(0, 0, 0), "gpencil_strokes":False, "texture_space":False, "remove_on_cancel":False, "release_confirm":False})

what am I missing?

$\endgroup$
2
  • $\begingroup$ Adding a mesh starts with the whole mesh selected. You then have select_all(action='TOGGLE') which will deselect everything so there is no selection to extrude. You want to get the one bottom face selected. $\endgroup$
    – sambler
    Oct 15, 2017 at 8:58
  • 1
    $\begingroup$ IMO the key to blender scripting is avoiding operators. Not at all costs, yeah use the primitive add op once, after running the new prim is prim = context.object another is prim.copy() transform translate in the context above is same as prim.location.z += 1.94 .. can expand into answer. How attached to using only listedf operators in your script? $\endgroup$
    – batFINGER
    Oct 16, 2017 at 11:22

1 Answer 1

0
$\begingroup$

A Command, select_face_by_sides, can be used.
However, this does not work when the bottom face is a triangle.

import bpy

bpy.ops.mesh.primitive_cone_add(location=(0,0,0))
bpy.ops.transform.translate(value=(0, 0, 1.94102), constraint_axis=(False, False, True), constraint_orientation='GLOBAL', mirror=False, proportional='DISABLED', proportional_edit_falloff='SMOOTH', proportional_size=1, release_confirm=True)
bpy.ops.object.editmode_toggle()

bpy.ops.mesh.select_face_by_sides(
        number=3, 
        type='GREATER', 
        extend=False
    )

bpy.ops.mesh.extrude_region_move(MESH_OT_extrude_region={"mirror":False}, TRANSFORM_OT_translate={"value":(-1.97143e-009, 3.68831e-009, 0.447236), "constraint_axis":(False, False, True), "constraint_orientation":'NORMAL', "mirror":False, "proportional":'DISABLED', "proportional_edit_falloff":'SMOOTH', "proportional_size":1, "snap":False, "snap_target":'CLOSEST', "snap_point":(0, 0, 0), "snap_align":False, "snap_normal":(0, 0, 0), "gpencil_strokes":False, "texture_space":False, "remove_on_cancel":False, "release_confirm":False})
$\endgroup$

You must log in to answer this question.

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