Stair Creator Extrude Problem - NEED HELP


#1

I’m writing a Staircase Creator python script…

First, here is a diagram of how I would like to create this stair case.


I have achieved the correct shape with my script but it wasn’t constructed the way I need it like in the above diagram.

Here is the stair case after running my script


This is exactly how I want it to look, the only problem is each face is extruding separately creating massive backface mess.

This is bad for a host of reasons but what I basically need it to do is select faces and extrude as a group as opposed to one at a time, so that there is no blackface mess to clean up.

Here is what my code currently looks like…

class Stair(object):

# init sets up default vales
def __init__(self):
    self.transform = None
    self.extrude = None
    self.constructor = None

def createStair(self, steps=20, height=1):

    self.transform, self.constructor = cmds.polyPlane(subdivisionsHeight=steps, subdivisionsWidth=1, width=10, height=24)

    # selecting -------------------------------------------------------
    frontFaces = range(steps)
    print frontFaces
    cmds.select(clear=True)
    # extrudeing - --------------------------------------------------
    for face in frontFaces:
        cmds.select('%s.f[%s]' % (self.transform, face), add=True)
        self.extrude = cmds.polyExtrudeFacet(localTranslateZ=height)[0]

All helped is appreciated, thanks!


#2

Just to further point out exactly where the problem is as I copied and pasted a little to much.
where it says:

for face in frontFaces:
    cmds.select('%s.f[%s]' % (self.transform, face), add=True)
    self.extrude = cmds.polyExtrudeFacet(localTranslateZ=height)[0]

each face gets extruded one at a time, as opposed to the whole group.
So if I re-right it like this.

for face in frontFaces:
    cmds.select('%s.f[%s]' % (self.transform, face), add=True)
self.extrude = cmds.polyExtrudeFacet(localTranslateZ=height)[0]

The whole group is extruded correctly but now it’s out of the loop so it doesn’t extrude the next selection like it needs to.


#3

I don’t see how you will avoid getting extra faces building it that way. You could use mel’s range notation to make selections like this:

def stairs(steps=20, height=1):
    transform, constructor = cmds.polyPlane(subdivisionsHeight=steps, subdivisionsWidth=1, width=10, height=24)
    faces = transform + '.f[{}:' + str(steps-1) + ']'
    
    for i in xrange(steps):
        cmds.select(faces.format(i), r=True)
        cmds.polyExtrudeFacet(localTranslateZ=height)
    
    
if __name__ == '__main__':
    stairs()

And wow, this clownass editor reminded me why I don’t post on this site anymore ಠ_ಠ


#4

THANK YOU GOOD SIR, you are a scholar and a gent. That worked like a charm.