You are using x inside of makespiralstairs function but not defining it or passing it in
def makeSpiralStairs(x): Then passing x in when you call it On Wed, Sep 13, 2017 at 10:16 AM jettam <[email protected]> wrote: > Could someone help me with this code. This function is supposed to build a > spiral staircase then distribute it randomly X amount of times. I have been > able to make it work with another object creation but I cant seem to figure > this one out. > Here is the error I am getting. And bellow is my code. > # Error: local variable 'x' referenced before assignment > # Traceback (most recent call last): > # File "<maya console>", line 42, in <module> > # File "<maya console>", line 39, in makeRobot > # File "<maya console>", line 9, in makeSpiralStairs > # UnboundLocalError: local variable 'x' referenced before assignment # > > import maya.cmds as mc > > import random > > > ''' Build a spiral staircase and distribute it randomly X amount of > times.''' > > > def makeRobot(numRobots=10): > > def makeSpiralStairs () : > inc = str(x +1) > > > steps = {'name':'Step','slide':5,'rotations':10,'spacing':1, > 'stepDepth':2,'stepHeight':.75} > stepName=steps.get('name') > > > groupAllSteps = mc.group(name="Group"+stepName+"s"+inc, empty=True > ) > > > for x in range (numRobots): > > > stepObj = mc.polyCube(name=stepName+inc, w=5, h=steps.get( > 'stepHeight'), d=steps.get('stepDepth'), ch=0) > > > stepGrp = mc.group(empty=True, name=stepName+inc) > > > mc.parent(stepObj, stepGrp) > > > mc.xform(stepGrp, ro=(0,(steps.get('rotations')*x),0)) > > > mc.xform(stepObj[0], t=(steps.get('slide'),steps.get( > 'stepHeight')*steps.get('spacing')*x,0)) > > > > mc.parent(stepObj, groupAllSteps) > > > mc.delete(stepGrp) > return groupAllSteps > > > > for x in range(numRobots): > AAA = random.uniform(-20,20) > BBB = random.uniform(-20,20) > CCC = random.uniform(-20,20) > Grp2 = makeSpiralStairs() > mc.setAttr(Grp2[0] + ".translate", AAA,BBB,CCC, type="double3") > > > > makeRobot(10) > > > > -- > You received this message because you are subscribed to the Google Groups > "Python Programming for Autodesk Maya" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected]. > To view this discussion on the web visit > https://groups.google.com/d/msgid/python_inside_maya/548d7be6-b3fc-4785-8a95-cd0df7ea3ae7%40googlegroups.com > <https://groups.google.com/d/msgid/python_inside_maya/548d7be6-b3fc-4785-8a95-cd0df7ea3ae7%40googlegroups.com?utm_medium=email&utm_source=footer> > . > For more options, visit https://groups.google.com/d/optout. > -- You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAM9RXoLw4JO72OEZvnHO8QiWXFKM6iz%3DO72nS0WjqnofomVR4g%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.
