[Ma...] Posted September 6, 2022 Share Posted September 6, 2022 Goodmorning everyone, I have to change stages order by using python. I have the stages' name ever called in the same way: partnumber_yymmdd_causal_cavitynumber. As shown in the image, I have to put the cavity 2 after the cavity 1, because GOM use the stages name and I have to use the last number to put the stages in the correct (for me) order. I hope I explained myself. I tried, but it doesn't work. Please sign in to view this quote. Someone could help me? Thank you very much in advance! Link to comment Share on other sites More sharing options...
[Dr...] Posted September 7, 2022 Share Posted September 7, 2022 (edited) __ Edited September 7, 2022 Link to comment Share on other sites More sharing options...
[Si...] Posted September 7, 2022 Share Posted September 7, 2022 Try this : # -*- coding: utf-8 -*- import gom num_list = [] num_list_s = [] final_list = [] count = 0 for i in gom.app.project.stages: print(i.name) num_list.append(i.name[-1]) num_list_s = sorted(num_list) for i in num_list_s: for j in gom.app.project.stages: if i in j.name[-1]: final_list.append(j) print(final_list) for i in final_list: count = count + 1 gom.script.sys.change_stage_order( stages=gom.StageSelection(first=i, last=i), target=gom.app.project.stages[count-1]) Link to comment Share on other sites More sharing options...
[Ma...] Posted September 9, 2022 Author Share Posted September 9, 2022 Thank you very much! I finally found a solution similar to yours, but when I begun to use it I noticed that I often have cavity missing and if there are cavity from 1 to 16 and, for example, cavity 10 and cavity 15 are missing, script doesn't work because there are 14 stages and cavity 14 and cavity 16 are greater then count-1 (13). I don't know if it's possible to order stages with cavity missing. Link to comment Share on other sites More sharing options...
[Si...] Posted September 13, 2022 Share Posted September 13, 2022 Here is the new script that will sort based on last number in stage name regardless of missing stage sequence. Try this : # -*- coding: utf-8 -*- import gom import re old_stage =[] stage = [] min_stage = [] master_sorted_list = [] ksi = [] dict_stage = {} count = 0 for G in gom.app.project.stages: old_stage.append(G.name) print(old_stage) for O in old_stage: output = re.findall(r'\d+', O)[-1] stage.append(output) for M in stage: stage_i=int(M) min_stage.append(stage_i) for V in range(len(old_stage)): dict_stage[old_stage[V]]=min_stage[V] dict_stage=(sorted(dict_stage.items(), key=lambda kv: (kv[1], kv[0]))) #print(dict_stage) #print("+++") for Dx in dict_stage: master_sorted_list.append(Dx[0]) #print(master_sorted_list) for i in range(len(master_sorted_list)): count = count + 1 if not master_sorted_list[i] in ksi: ksi.append(master_sorted_list[i]) gom.script.sys.change_stage_order( stages=gom.StageSelection(first=gom.app.project.stages[master_sorted_list[i]], last=gom.app.project.stages[master_sorted_list[i]]), target=gom.app.project.stages[master_sorted_list[-1]]) Link to comment Share on other sites More sharing options...
[Ma...] Posted September 19, 2022 Author Share Posted September 19, 2022 Wonderful, it works perfectly!!! I hope it can be useful for other users, too! Thank you very very very much! Link to comment Share on other sites More sharing options...
Recommended Posts
Please sign in to comment
You will be able to leave a comment after signing in