Jump to content

How to change stages order using Python?


Recommended Posts

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

Try this :

# -*- coding: utf-8 -*-

import gom

num_list = []
num_list_s = []
final_list = []
count = 0

for i in gom.app.project.stages:
    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]:

for i in final_list:
    count = count + 1
        stages=gom.StageSelection(first=i, last=i), 


Link to comment
Share on other sites

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

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:

for O in old_stage:
	output = re.findall(r'\d+', O)[-1]

for M in stage:

for V in range(len(old_stage)):

dict_stage=(sorted(dict_stage.items(), key=lambda kv:
					(kv[1], kv[0])))


for Dx in dict_stage:


for i in range(len(master_sorted_list)):
	count = count + 1
	if not master_sorted_list[i] in ksi:
			stages=gom.StageSelection(first=gom.app.project.stages[master_sorted_list[i]], last=gom.app.project.stages[master_sorted_list[i]]),


Link to comment
Share on other sites


  • Create New...