Jump to content

Generating individual reports for each mesh in a stage with Python.


Recommended Posts

I'm new to GOM and Python both; however, I needed a way to generate individual reports for each mesh in a stage. Here is the script I came up with that works for me. I would welcome any feedback if anyone, especially the Pyhtonistas, wants to try it or critique it.

 

#--------------------------------------------------------------------------------------
# This script will create individual reports for each mesh in a stage.
# The report name will be the same as the mesh it's genreated from.
#--------------------------------------------------------------------------------------


import gom


gom.script.sys.recalculate_project ()

	
for i in range(len(gom.app.project.stages)):    # Iterates through all meshes in the stage.
	gom.script.sys.show_stage (stage=gom.app.project.stages[i])
	gom.script.sys.set_stage_as_reference (stage=gom.app.project.stages[i])
	gom.script.sys.switch_to_report_workspace ()
	
	report_pages = []    # Creates a list of all report page indexes for selected mesh.
	for t in gom.app.project.reports:
		report_pages.append(t)
		
	gom.script.report.update_report_page (
				pages=report_pages, 
				used_alignments='report', 
				used_digits='report', 
				used_legends='report', 
				used_stages='current', 
				used_units='report')    
		
	gom.script.report.export_pdf (
				export_all_reports=True, 
				file='C:/Users/ZEISS-CMM/Documents/GOM/Reports/'+str(gom.app.project.stage)+'.pdf', 
				jpeg_quality_in_percent=100)    

 

Hi Mark,

Here's what i use. The difference is it only picks up the active stages, and it prompts for a save location. File name comes from the name/title of the first report page, so if you add a stage reference into that then you'll end up with unique names. 

# -*- coding: utf-8 -*-
# Exports reports for acive stages
import gom

RESULT=gom.script.sys.execute_user_defined_dialog (content='<dialog>' \
' <title>Choose Folder</title>' \
' <style></style>' \
' <control id="OkCancel"/>' \
' <position></position>' \
' <embedding></embedding>' \
' <sizemode></sizemode>' \
' <size height="120" width="305"/>' \
' <content columns="1" rows="1">' \
'  <widget row="0" column="0" rowspan="1" columnspan="1" type="input::file">' \
'   <name>folder</name>' \
'   <tooltip></tooltip>' \
'   <type>directory</type>' \
'   <title>Choose Destination</title>' \
'   <default>C:/Users/user/Documents</default>' \
'   <limited>false</limited>' \
'   <file_types/>' \
'   <file_types_default></file_types_default>' \
'  </widget>' \
' </content>' \
'</dialog>')

foldertxt=(RESULT.folder + '/')
print(foldertxt)

for i in range(len(gom.app.project.stages)):
        if (gom.app.project.stages[i].is_active): 
            gom.script.sys.show_stage (stage=gom.app.project.stages[i])
            
            page_list = list(gom.app.project.reports)
            gom.script.report.update_report_page (
                    pages=(page_list), 
                    used_alignments='report', 
                    used_digits='report', 
                    used_legends='report', 
                    used_stages='current', 
                    used_units='report')
    
            filetxt=(gom.app.project.reports[0].name)
    
            gom.script.report.export_pdf (
                    export_all_reports=True, 
                    file=(foldertxt + filetxt + '.pdf'), 
                    jpeg_quality_in_percent=80, 
                    max_dpi=85)

RESULT=gom.script.sys.execute_user_defined_dialog (content='<dialog>' \
' <title>Message</title>' \
' <style></style>' \
' <control id="Close"/>' \
' <position>automatic</position>' \
' <embedding>always_toplevel</embedding>' \
' <sizemode>automatic</sizemode>' \
' <size height="169" width="214"/>' \
' <content columns="1" rows="1">' \
'  <widget row="0" type="display::text" columnspan="1" column="0" rowspan="1">' \
'   <name>text</name>' \
'   <tooltip></tooltip>' \
'   <text>&lt;!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd">' \
'&lt;html>&lt;head>&lt;meta name="qrichtext" content="1" />&lt;style type="text/css">' \
'p, li { white-space: pre-wrap; }' \
'&lt;/style>&lt;/head>&lt;body style="    ">' \
'&lt;p align="center" style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">Report(s) Exported&lt;/p>&lt;/body>&lt;/html></text>' \
'   <wordwrap>false</wordwrap>' \
'  </widget>' \
' </content>' \
'</dialog>')

 

×
×
  • Create New...