[Maya Python] Space Switching. 3 inputs are okay. How about 4?

Ah, I understand. I remember being there.

Hopefully as a bit of clarification, enumerate is a function that is built in to python to give you the number position of every object in the list as well as the object itself.

Let’s say you have a list of objects ['pCube1', 'pCube2', 'pCube3', 'pCube4']
If you loop through that list with an enumerate, here’s what you get:

objectList = ['pCube1', 'pCube2', 'pCube3', 'pCube4']

for idx, obj in enumerate(objectList):
    print idx
    print obj

# ----- output -----
0
pCube1
1
pCube2
2
pCube3
3
pCube4

I was only using it to make setting all of the ‘W1’, ‘W2’, ‘W3’ … parts of the constraint easier since you have to know the number of the object for that. (Same as the last two lines of your original example)

IMO the best way to learn this stuff is to ask yourself a bunch of specific questions, like “how do I combine a list of names into a single string with the names separated by a semicolon?” or “how do I take a list of selected things and split it into two lists?” then use google to find the answer and type it out yourself in the script editor. Once you get comfortable with this type of stuff in python, your code becomes much more powerful. You’re already on the right track by trying to expand your script to work with varying numbers of objects. It just takes time and practice.

1 Like