Jump to content

Script in a Report page


---
 Share

Recommended Posts

I have a multi stage report and I want to generate a list of stages included in the report.

Previously we have inserted screen shots to show this list but this is manual, can easily be forgotten and is not elegant!

I want to insert a script to generate a list of active stages such as the below:

>import gom

>for i in range(len(gom.app.project.stages)):

>>  if (gom.app.project.stages[i].is_active):

>>      filetxt=(gom.app.project.stages[i].name)

>>     print(filetxt)

 

Any thoughts how i can achieve this?

Link to comment
Share on other sites

You have to use Python. This is what I understand you have to do: create a txt file in a specific directory and print inside it the number of the stages. This is the simple code I have done for your usage:

import gom

stages=(len(gom.app.project.stages))

f = open("F:\Coacarqb\Marco\File.txt", "w")
f.write (str(stages))
f.close()

Is that useful for you?

Link to comment
Share on other sites

Keith, 

This will give you a list of the stage names, as they are set to active, and save it to a text file. I hope this helps.

 

import gom

active_stages = []

for i in range(len(gom.app.project.stages)):
	gom.script.sys.show_stage (stage=gom.app.project.stages[i])
	gom.script.sys.set_stage_as_reference (stage=gom.app.project.stages[i])
	active_stages.append(gom.app.project.stage)
	

textfile = open("C:/Users/ZEISS/Documents/GOM/Results/stages.txt", "w")
for stage in active_stages:
	textfile.write(stage + "\n")
textfile.close()

 

Link to comment
Share on other sites

Thank you both, however I cannot get either code to work "(unicode error) 'unicodeescape' codec cannot decode bytes in position 2-3: truncated \UXXXXXXXX escape " 

I added "r" to the string to make them raw and then

Please sign in to view this username.

's code counts the number of stages, and

Please sign in to view this username.

's fails because a disabled stage cannot be made active.

I've modified the code as below:

Please sign in to view this quote.

to give me a list in the text file.

I'm looking for a Table of Contents style of finished page, so do you know of a way to get the information from the text file into the GOM Report (without manual copy/paste)?

Link to comment
Share on other sites

Hello Keith,

Please sign in to view this quote.

One solution is to pass the text into a user defined Keyword. The Keyword can be placed as usual in a report page.

Link to comment
Share on other sites

Hi Nanno,

Please sign in to view this quote.

When I create a new Keyword, I see an option for text, date, or number. I assume I would set it to text, but how would I direct it to the text file?

Edited
added a word for clarity
Link to comment
Share on other sites

Hi Mark,

the text can be directly assigned to the keyword without a text file. Record the creation of a keyword and you can switch the string for a variable, which would be the name of a stage for example.

Regards,
Nanno

Link to comment
Share on other sites

 Share

×
×
  • Create New...