0
ctrlList = [box_1_ctrl, box_2_ctrl, box_3_ctrl, box_4_ctrl, box_5_ctrl, box_6_ctrl, box_7_ctrl, box_8_ctrl];
ctrl1 = ctrlList.index(ctrlList[0]);
ctrl2 = ctrlList.index(ctrlList[1]);
ctrl3 = ctrlList.index(ctrlList[2]);
ctrl4 = ctrlList.index(ctrlList[3]);
ctrl5 = ctrlList.index(ctrlList[4]);
ctrl6 = ctrlList.index(ctrlList[5]);
ctrl7 = ctrlList.index(ctrlList[6]);
ctrl8 = ctrlList.index(ctrlList[7]);
ctrlIndex = (ctrl1, ctrl2, ctrl3, ctrl4, ctrl5, ctrl6, ctrl7, ctrl8); *first index list
shapes = (shape1, shape2, shape3, shape4, shape5, shape6, shape7, shape8);

ctrlIndex and shapes are 2 indexed lists. i want the output to look like:

Before:

print ctrlIndex
(0,1,2,3,4,5,6,7)

print shapes
(0,4,5,3,2,1,6,7)

After:

print ctrlIndex
(0,4,5,3,2,1,6,7)

and also this list changes the order of ctrlList according to ctrlIndex. can someone please help me solve this? i am beginner and am stuck at this step. have tried using for loop,

for m in ctrlList:
    for n in shapes:
        ctrlList = ctrlList[m]
        shapes = shapes[n]
    if ctrlList != shapes:
       ctrlList.remove(m)
       ctrlList.insert(n)
       result.append()
Quentin Pradet
  • 4,691
  • 2
  • 29
  • 41
  • Please format your question and your code... This is unreadable – Riccardo Bucco Dec 10 '19 at 08:29
  • sorry, its my first time posting here, done. – Tsumugi Kotobuki Dec 10 '19 at 08:30
  • Can you please post a code sample that let's us reproduce your question? – adamkgray Dec 10 '19 at 08:50
  • What are you actually trying to do in Maya? And can this work with the current selection instead of hard-coding the names? – Green Cell Dec 10 '19 at 09:48
  • i am trying to create a rubiks cube. i cannot select everything because every cube has unique values and when i unparent them the values change. i thought it was better to use object names directly. or if there are any other techniques with which you are familiar with please do share thanks a lot @GreenCell :) – Tsumugi Kotobuki Dec 10 '19 at 11:07

2 Answers2

0

Is this what you want? I changed the ctrlList to strings since I don't know the variables.

ctrlList = ['box_1_ctrl', 'box_2_ctrl', 'box_3_ctrl', 'box_4_ctrl', 'box_5_ctrl', 'box_6_ctrl', 'box_7_ctrl', 'box_8_ctrl']
shapes =[0,4,5,3,2,1,6,7]
newlist = []
for shape in shapes:
    newlist.append(ctrlList[shape])
print(newlist)  
newindex = []
for item in newlist:
    newindex.append(ctrlList.index(item))
print(newindex)   

This code will output the contents of ctrlList in the order of the shapes.

timedacorn
  • 519
  • 4
  • 16
0

you can use list comprehension. No need for you to generate a ctrlIndex.

ctrlList = ['box_1_ctrl', 'box_2_ctrl', 'box_3_ctrl', 'box_4_ctrl', 'box_5_ctrl', 'box_6_ctrl', 'box_7_ctrl', 'box_8_ctrl'];
shape = (0,4,5,3,2,1,6,7)
print [y for x in shape for y in ctrlList if ctrlList.index(y) == x] # for python 2


>>>['box_1_ctrl', 'box_5_ctrl', 'box_6_ctrl', 'box_4_ctrl', 'box_3_ctrl', 'box_2_ctrl', 'box_7_ctrl', 'box_8_ctrl']

Shijith
  • 4,602
  • 2
  • 20
  • 34
  • Wow thanks a lot! i didnt know you can write it like that too.! yes exactly i was looking for this . might sound silly of me(since i am a beginner) what does the first 'y' inside print do? thanks a lot for helping me! – Tsumugi Kotobuki Dec 10 '19 at 11:10
  • `for y in ctrlList`, means for each item in `ctrlList` – Shijith Dec 10 '19 at 11:12
  • no not for y in ctrlList, the first line "y for x" i am familiar with x in shape thanks :) – Tsumugi Kotobuki Dec 10 '19 at 11:15
  • here you have two for loops inside list comprehension , for each `x` in `shape` , iterate through `ctrlList` for each item `y` in `ctrlList` and if the given condition `if ctrlList.index(y) == x` (index of y == x), then select that `y`. The `y` at the beginning is selecting those `y`'s which satisfies the condition – Shijith Dec 10 '19 at 11:20