How to extrude - basic question

Hi All:

Please help out a Scripting Novice with Extruding:

I want to extrude the bottom face of the default cube after subdividing it and deleting the left half.

My script (Text Editor: Main) selects the vertices and edges that make up that bottom face.

Now if I run the Extrude script the result it no what I wanted or expected.
I simply wanted the bottom face to be extruded 1 unit down in the Z direction. (Look what it did to the 3D cursor!!!).

Obviously there is much that I am missing here!

Blend file: Extrude Script.blend (472.7 KB)

Thanks for any help.

Isnt this what you are looking for?

Also, in line 8, you use:

bpy.ops.object.editmode_toggle()

but rather should use:

bpy.ops.object.mode_set(mode='EDIT')

Because otherwise, if you where in “Edit Mode” already, it would toggle you out into “Object Mode”.

Thanks for our reply.

From the Stackoverflow post, my takeaway is that the face (not just the vertices) has to be selected.

I tried that and got the result I wanted.

Would someone be kind enough to explain why my original effort produced the result that it did?

Thanks again.

Sry for having been inactive… real life issues…

Dont give too much about what I say, I am not a programmer at all, but the python console spits out:
"File “C.XYZ XXX.blend\Main”, line 11, in "
Line 11 is “bpy.ops.mesh.subdivide()”, whose documentation you can find here:
https://docs.blender.org/api/blender_python_api_2_63_7/bpy.ops.mesh.html

It says: " bpy.ops.mesh.subdivide( number_cuts=1 , smoothness=0.0 , quadtri=False , quadcorner=‘STRAIGHT_CUT’ , fractal=0.0 , fractal_along_normal=0.0 , seed=0 )

Subdivide selected edges"

But at that point in the script, you dont even have anything selected, so there is no context to subdivide on(?).