Extruding a face in Maya with Python

A quick guide on how to create an object, select and then extrude a face by a specified value.

We’ll jump straight in to some commented code:

# Import the Maya commands library
from maya import cmds

# Create a cube
cube = cmds.polyCube()

# Save the object name in a new variable
cubeShape = cube[0]

# Select a face (face 1 for a cube is the top face)
targetFace = cmds.select(cubeShape+'.f[1]')

# Extrude the face by a specified translate Z value
extrude = cmds.polyExtrudeFacet(localTranslateZ=4)

In terms of Python its fairly straight forward, I have a gear creator code which selects every other face of a pipe object and extrudes, you can see this on my GitHub here: https://github.com/johnplayer1982/python_maya/blob/master/gearClassCreator.py