[Maya - Python] [start:stop:step] using cmds.polyExtrudeFacet(object.f[....])



Hi guys, I am trying to execute a cmds.polyExtrudeFacet() command on some faces, but the command just accept the format object.f[start:end] without allowing me using a step parameter.
I would like to avoid maya API and know if there is a way to make this.

Another solution I found is to extrude every face in a loop, but this lead me to a separate construction history per face, and that’s not so cool.

Thanks :slight_smile:

Solved it, I didn’t know that using cmds.polyExtrudeFacet() without faces parameters uses the faces in selection!


So with pymel, you can actually pass a tuple to the objects component iterator.

import pymel.core as pm

obj = pm.polySphere()[0]
pm.polyExtrude(obj.f[1,3,5,7,9,11, 13:25], ltz=5)

with cmds, you’d need to pass a string for each separate face or group of faces.

from maya import cmds

obj = cmds.polySphere()[0]
cmds.polyExtrudeFacet(obj + '.f[1]', obj + '.f[13:25]', ltz=5)

Both of these will create just one single extrude node in the history.


Thank you R.White, I found that use of cmds.polyExtrudeFacet() with active selection on the faces I want to extrude is the better solution at the moment!

extFaceStart = self.subdvAx * 2
extFaceEnd = (self.subdvAx * 3)

        for i in range(extFaceStart, extFaceEnd, 2):
            cmds.select("%s.f[%d]" %(self.sceneObject, i), add = True)
        cmds.polyExtrudeFacet(kft = False, ltz = self.teethLength, ls = self.teethScale)


Yeah, that works as well. If you don’t want to lose the active selection, you can use a bit from both examples.

extFaceStart = self.subdvAx * 2 
extFaceEnd = self.subdvAx * 3

faces = []
for i in range(extFaceStart, extFaceEnd, 2):
    faces.append("%s.f[%d]" % (self.sceneObject, i))

cmds.polyExtrudeFacet(faces, kft = False, ltz = self.teethLength, ls = self.teethScale)

My personal preference is to not rely on dancing around the active selection, but both are perfectly valid options.