Jump to content

DEVIATION THRESHOLD IN PYTHON AUTOMATION


---
 Share

Recommended Posts

Hi guys, thanks for keeping the forum updated. 

I have two questions for You: 

1. When I use the "transform measurement series button" (surface best-fit option) manually it will show me the actual deviation of the mating between the two measurement series so that I can see whether the result is under a certain threshold or not. How can I insert the same fuction inside a generic python automation script in order to achieve the same thing automatically?

 

image.png.770c0aecf2cfeb2f4e0ccf00af9d1874.png

 

2. I'd like to implement more or less the same thing (threshold of the deviation) with the script that automates the reports. In this case I'd like to check the alignment deviation between the cad and the measured part.

 

image.png.dc60a549646e51bcdbc4e176ae0e45cf.png

 

 

Thank You very much for Your kind support. 

 

Leonardo Stefanini 

Link to comment
Share on other sites

Hey Leonardo,

 

you can do this by pressing the 'F2' key while you are editing your script. With this you open the 'Script Object' allowing you to access all given information/tokens to the elements or objects in your project. For an alignment it could look like this:

image.thumb.png.ea3ba35a014bcd384daefe8bcd5d4e16.png

When you finish this token selection by hitting OK, you get the command returned to your script. This command contains the element name as string and maybe some additional keywords. Replacing the name string or the keywords with variables is possible, which turns your script from a static to dynamic one. 

 

And as a proof, here the creation dialog of the alignment:

image.png.1674f398ca4308e4ef93af49387235dd.png

 

Hope this helps! Cheers,

Jens

Link to comment
Share on other sites

I'm posting here the measurement series deviation check in the hope it can be useful to whoever may need it: 

import gom
import tkinter as tk
from tkinter import messagebox

# Transform measurement series
gom.script.atos.transform_measurement_series(
    reference_measurement_series=gom.app.project.measurement_series['Scan 1'],
    search_time='long',
    source_measurement_series=gom.app.project.measurement_series['Scan 2'],
    transformation_method='surface_bestfit'
)

# Get the transformation residual
deviation_threshold_1 = gom.app.project.measurement_series['Scan 2'].measurement_series_transformation_residual

# Check if the deviation is over 0.02mm
if deviation_threshold_1 > 0.005:
    # Display warning pop-up window
    root = tk.Tk()
    root.withdraw()  # Hide the main window

    # Show warning message
    message = f"ATTENZIONE!: LA DEVIAZIONE RESIDUA DELLA TRASFORMAZIONE VA OLTRE IL VALORE PREIMPOSTATO DI 0.02mm: \n\n{deviation_threshold_1}mm\n\nTENTARE LA TRASFORMAZIONE INVERTENDO L'ORDINE DELLE MESH?"
    user_response = messagebox.askokcancel("ATTENZIONE", message)

    # Check user response
    if user_response:
        # Execute transformation for Scan 2 to Scan 1
        gom.script.atos.transform_measurement_series(
            reference_measurement_series=gom.app.project.measurement_series['Scan 2'],
            search_time='long',
            source_measurement_series=gom.app.project.measurement_series['Scan 1'],
            transformation_method='surface_bestfit'
        )

        # Check the transformation residual for Scan 1
        deviation_threshold_2 = gom.app.project.measurement_series['Scan 1'].measurement_series_transformation_residual

        # Check if the residual for Scan 1 is still over 0.02mm
        if deviation_threshold_2 > 0.005:
            root = tk.Tk()
            root.withdraw()  # Hide the main window

            # Show warning message
            message = f"ATTENZIONE!: ANCHE IL SECONDO TENTATIVI DI TRASFORMAZIONE VA OLTRE IL VALORE PREIMPOSTATO DI 0.02mm: \n{deviation_threshold_1}mm\n\nLA ROUTINE VERRà INTERROTTA"
            user_response = messagebox.askokcancel("ATTENZIONE", message)
            print("Transformation unsuccessful. Exiting script.")
            exit()
    else:
        print("Transformation aborted by user.")

 

 

Thanks again! 
 

Link to comment
Share on other sites

 Share

×
×
  • Create New...