how to extrude wiht bpy.ops?

how do you extrude a plane to a cube?

i tried the following but it crahes?

this is following what we can see in the report window!
so it should work but it does !


 
import bpy, math
from bpy.props import *
from mathutils import *
from math import *  
 
 
bpy.ops.object.select_name(name="Plane",extend=False)
obj = bpy.context.active_object
myMesh = obj.data
print (' obj =',obj)
print (' myMesh obj =',myMesh.name)
 
bpy.ops.object.editmode_toggle()
 
bpy.ops.mesh.select_all(action='TOGGLE')
 
bpy.ops.mesh.extrude_region_move(MESH_OT_extrude={"type":'REGION'}, TRANSFORM_OT_translate={"value":(0, 0, 0), "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), "texture_space":False, "release_confirm":False})
 
bpy.ops.transform.translate(value=(0, 0, -2.76382), constraint_axis=(False, False, True), constraint_orientation='GLOBAL', 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), texture_space=False, release_confirm=True)
 

thanks for any help

i already saw it and not working !

don’t know i can do it manually and it works fine
but when i tried it on somethng else then the plane it crashes with following error

File “C:\Users\RJ\0blend25\0BETA3~1\2.57\scripts\modules\bpy\ops.py”, line 179
, in call
ret = op_call(self.idname_py(), None, kw)
RuntimeError: Operator bpy.ops.object.select_name.poll() failed, context is inco
rrect

why is it working fine with plane but not with the new one ?
i only change the object and i can print the object’s name!

mind you the plane contains one face
but the new object i have is only a iine with no faces!
may be there is another command when there is no faces!

but i can do it manually and i copied the transform command from the report window
so should work but it’s not working!

thanks

ok very well.


import bpy

# with nothing selected, proceed! 
bpy.ops.object.mode_set(mode='OBJECT') # force it, be sure! , toggle is not great.
bpy.ops.object.select_name(name="Plane")

# bpy.ops.mesh.select_all(action='TOGGLE')
bpy.ops.object.mode_set(mode='EDIT') # force it, be sure! 
 
bpy.ops.mesh.extrude_region_move(MESH_OT_extrude={"type":'REGION'}, TRANSFORM_OT_translate={"value":(0, 0, -2), "constraint_axis":(False, False, True), "constraint_orientation":'NORMAL'})

not working !

try with file here

http://cid-348ad7d85dee0c79.photos.live.com/self.aspx/blenderheader1/extrudeplane2.blend

sorry cannot upload files here anymore !

thanks

Ricky, why so complicated? Let us start with forgetting everything [noparse]:)[/noparse]

  • reduce things to the simplest case
  • even simpler than your current scene.
  • empty file with one profile “bolectionnew1”

you have a shape you wish to extrude : bolectionnew1
make sure no verts are selected in the object before running this.


import bpy

# with nothing selected, proceed! 
bpy.ops.object.mode_set(mode='OBJECT') # force it, be sure! , toggle is not great.
bpy.ops.object.select_name(name="bolectionnew1")

bpy.ops.object.mode_set(mode='EDIT') # force it, be sure! 
bpy.ops.mesh.select_all(action='TOGGLE')
 
bpy.ops.mesh.extrude_region_move(MESH_OT_extrude={"type":<b>'VERTS'</b>}, TRANSFORM_OT_translate={"value":(0, 0, -2), "constraint_axis":(False, False, True), "constraint_orientation":'NORMAL'})

the fact that this function is called extrude_region_move is a little unintuitive i think, a better name would be extrude_selected_move

seems to be very sensitive !
and i need this to work all the time in any scene!

tried it at first and did not work then work only if i pre selected it in viewport!

i did some changes and now seems to work all the time!
but don’t know why!


<b>o1=bpy.ops.object.select_name(name="bolectionnew1",extend=False)</b>
print ('o1=',o1)
obj = bpy.context.active_object
myMesh = obj.data
 
 
 
 
 
print (' obj =',obj)
print (' myMesh obj =',myMesh.name)
 
 
# with nothing selected, proceed! 
bpy.ops.object.mode_set(mode='OBJECT') # force it, be sure! , toggle is not great.
bpy.ops.object.select_name(name="bolectionnew1")
 
bpy.ops.object.mode_set(mode='EDIT') # force it, be sure! 
<b>#bpy.ops.mesh.select_all(action='TOGGLE')</b>
 
bb=bpy.ops.mesh.extrude_region_move(MESH_OT_extrude={"type":'VERTS'}, TRANSFORM_OT_translate={"value":(0, 0, -2), "constraint_axis":(False, False, True), "constraint_orientation":'NORMAL'})
 

thanks

ricky, i strongly urge that you remove any whitespace that spans more than 2 lines, it looks ugly and can cause the script to fail (when running from the TextEditor)

that would be very strange!

never heard that one before "more then 2 white lines can cause the script to fail " and never had this problem also!
but i’ll test it !

at least it’s beginning to give some results

have to make new cross section and test this

thanks

I downloaded your blend file from the link you provided. I would like to suggest the followings:

At the beginning of the program:


# Save the mode.
currMode = bpy.context.active_object.mode

At the end of the program:


# Reset the mode to the mode before the operation.
bpy.ops.object.mode_set(mode=currMode)

Based on the way you constructed the shape, you may want to use


bpy.ops.mesh.extrude_region_move(MESH_OT_extrude={"type":'EDGES'} ...

instead of


bpy.ops.mesh.extrude_region_move(MESH_OT_extrude={"type":'VERTS'} ...

This is what I did on mine.

well it finally work but not in a predicatable way
but it seems to extrude well now

so i’m still working on some cross sections then later on this week i’ll try your method

thanks for the feedback

agreed, to use edges is more logical when reading the script, But to use Edges the edit-mode seems to require to be in Edge Select Mode


bpy.ops.wm.context_set_value(data_path="tool_settings.mesh_select_mode", value="(False, True, False)")

because if you are in Vertex Select Mode (which i must have been at the time of responding) then ‘EDGES’ isn’t a valid type.