Jump to content

Help! How do I use Python to control GOM INSPECT, quickly export STL files, import STL files from a folder into a project template, automatically refresh reports, and save PDF and CSV files?


---
 Share

Recommended Posts

Help! How do I use Python to control GOM INSPECT, quickly export STL files, import STL files from a folder into a project template, automatically refresh reports, and save PDF and CSV files?

Link to comment
Share on other sites

Please sign in to view this quote.

Please sign in to view this username.

 Go into the Add-Ons menu, and click on Add-on Editor. You might need to make a template folder, then you will see the scripting area to the right. Record a macro and do all of the things you stated. Then tweak the macro using Python syntax or feed it into GPT.

Link to comment
Share on other sites

https://zeissiqs.github.io/zeiss-inspect-addon-api/2025/howtos/python_api_introduction/python_api_introduction.html

 

Here is the documentation. Depending on how automated of a solution you want will dictate how easy this is to implement. 

Here is a script for importing files, converting them to STEP, and then exporting them. 

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

import gom
from PyQt5.QtWidgets import QApplication, QFileDialog
import sys
import os


app = QApplication(sys.argv)

# Set default folder path
default_folder = r"" 


file_path, _ = QFileDialog.getOpenFileName(None, "Select an STL file", default_folder, "STL Files (*.stl)")


if not file_path:
    print("No file selected. Operation canceled.")
    sys.exit()

try:
    
    gom.script.sys.import_stl(
        bgr_coding=True,
        files=[file_path],
        geometry_based_refining=False,
        import_mode='clipboard',
        length_unit='mm',
        stl_color_bit_set=False,
        target_type='mesh'
    )

    
    gom.script.part.create_new_part(name='Part')

    
    print("Imported Actual Elements:")
    for element in gom.app.project.clipboard.actual_elements:
        print(" -", element)

    
    gom.script.part.add_elements_to_part(
        delete_invisible_elements=True,
        elements=[el for el in gom.app.project.clipboard.actual_elements],
        import_mode='new_elements',
        part=gom.app.project.parts['Part']
    )

    
    gom.script.sys.switch_to_mesh_editing_workspace()

    
    MCAD_ELEMENT = gom.script.mesh.automatic_cad_surface_from_mesh(
        merge=True,
        mesh=gom.app.project.parts['Part'].actual,
        name='CAD group 1',
        number_of_quads=100000,
        preview_type=1
    )

    
    step_folder = r""
    os.makedirs(step_folder, exist_ok=True)

    
    filename = os.path.splitext(os.path.basename(file_path))[0]
    step_export_path = os.path.join(step_folder, f"{filename}.step")

    
    print("Nominal Elements for STEP Export:")
    for el in gom.app.project.clipboard.nominal_elements:
        print(" -", el)

    
    gom.script.sys.export_step(
        elements=[el for el in gom.app.project.clipboard.nominal_elements],
        file=step_export_path
    )

    print(f"STEP file exported to {step_export_path}")

    
    gom.script.cad.delete_element(
        elements=gom.ElementSelection({'category': ['key', 'elements', 'is_element_in_clipboard', 'True',
                                                    'explorer_category', 'nominal', 'object_family', 'cad']}),
        with_measuring_principle=True
    )

    print("Process completed successfully!")

except Exception as e:
    print(f" Error occurred: {e}")

 

Edited
Link to comment
Share on other sites

 Share

×
×
  • Create New...