1

I have a problem. I am writing a Python-Maya script. I'm trying to extrude a list of objects to another list of objects, but I get the following error when I try to do it(the error is not the line where I start the for loop):

 Error: line 1: TypeError: file <maya console> line 45: range() integer end argument expected, got list.
#
def extrude_():
    for i in range(listOfCircles):
        mc.select(listOfCurves[0], all=True)
        mc.select(listOfCircles[0], all=True)
        mc.extrude(listOfCurves[0]+str(i), listOfCircles[0]+str(i), et=2)

        return

listOfCircles and listOfCurves are global variables, so I don't think I need to pass them to the function..

  • 3
    The error tells you what you need to know: the `range()` function expects a integer as it's argument rather than a list. What you probably want is `range(len(listOfCircles))`. – Pit Apr 04 '17 at 11:33
  • I tried to run the code with range(len(listOfCircles)) even before but it gives me this error : # Error: line 1: TypeError: file line 49: can only concatenate list (not "str") to list # – Rossy Kostova Apr 04 '17 at 13:40
  • Inspect the contents of listOfCurves[0] by printing it out in the loop. If it is a list, then you cannot "add" (+) a string with that list. – kartikg3 Apr 04 '17 at 16:06
  • just use for i, curve in enumerate(listOfCircles): ? – Achayan Apr 04 '17 at 18:49
  • @kartikg3 I inspected the list already...the result is: circle_0 circle_1 circle_2 circle_3 circle_4 ... ... ... circle_252 circle_253 circle_254 curve_0 curve_1 curve_2 curve_3 ... ... ... curve_252 curve_253 curve_254 curve_0 Isn't it strange that in the end I have curve_0? ############## I tried for i, curve in enumerate(listOfCircles): as you suggested, but nothing changes. The error is always the same – Rossy Kostova Apr 05 '17 at 18:57
  • However, if I tried to change this line **mc.extrude(listOfCurves[0]+str(i), listOfCircles[0]+str(i), et=2)** in this one: **mc.extrude(listOfCurves[i], listOfCircles[i], et=2)** – Rossy Kostova Apr 05 '17 at 19:07

1 Answers1

0

Based on how I understood what you explained you want to achieve your code could be as following:

def extrude():
    for i in range(len(listOfCircles)):
        mc.extrude(listOfCurves[i], listOfCircles[i], et=2)
rozhabrev
  • 3
  • 4