[Da...] Posted July 29, 2025 Share Posted July 29, 2025 Please sign in to view this quote. Link to comment https://qualityforum.zeiss.com/topic/24057-how-to-use-widget-input-to-trigger-specific-measurement-routines-eg-surface-comparison-in-script/ Share on other sites More sharing options...
[De...] Posted August 21, 2025 Share Posted August 21, 2025 There was an App in 2023 to "Create Surface Defect Checks" which would create a deviation label for every deviation island in a surface defect classification. we upgraded to 2025 and then realized this script is no longer compatablee (unless SDCL in legacy mode?) if you're using 2023 These were the parameters I used for the classification formula (basically how far above the 1.5mm tolerance is it) This is the user defined dialog prompt & results: you can patch the original add on to extract other attributes in the SDCL table (max_depth_heigh(3sigma)) pretty easily. I used to use it with kiosk mode to auto label the OOT areas, I believe I copied the code in the add on and added it as an external module so I could access it through the kiosk interface easier.. here was the function I wrote in "Custom Patches" def update_sdcl_labels(self): self.reject = False for p in gom.app.project.parts: if p.part_function == 'used_for_scanning': scanpart = p # ##Delete all existing labels attached to SDCL del_list = [] gom.script.explorer.apply_selection(selection=[]) for point in gom.ElementSelection ({'category': ['key', 'elements', 'part', scanpart, 'explorer_category', 'actual', 'object_family', 'geometrical_element', 'type', 'point']}): gom.script.explorer.apply_selection(selection=[]) gom.script.explorer.apply_selection(selection=[point]) for related in gom.ElementSelection({'category': ['key', 'related']}): print(related, related.type) if related.type == 'inspection_surface_classification' or related.type == 'surface_comparison_actual_mesh': del_list.append(point) print(f'Deleting Elements {del_list}') if len(del_list): gom.script.cad.delete_element ( elements=del_list , with_measuring_principle=True) del_list = [] ###Create New Labels for all SDCLs in Project sdcl_label_dict = {} for sdcl in gom.ElementSelection ({'category': ['key', 'elements', 'part', scanpart, 'explorer_category', 'inspection', 'object_family', 'surface_comparison', 'type', 'inspection_surface_classification']}): gom.script.cad.show_element_exclusively (elements=[sdcl, scanpart.actual]) sdcl_labels = [] if sdcl.number_of_defects is not None and sdcl.number_of_defects != 0: self.reject = True ## Detected a defect (Something Over .500mm ) # export_defect_csv(sdcl) for i in range (sdcl.number_of_defects): # print(i) point, labels = Create_sdcl_labels.create_surface_defect_checks( name="PtIndx", classification=sdcl, one_or_multi="ONE", index=i, show_class=True, max_depth_height=False, avg_depth_height = False, area=False, volume=False, avg_depth_height_3sigma = True, max_depth_height_3sigma = True ) ##Create a list of actual points and associated labels sdcl_labels.append(point) ##Append the "Actual Point 1" for l in labels: sdcl_labels.append(l) ##Append all checks "Actual Point 1.maxdev", "Actual Point 1.avgdev"..etc sdcl_label_dict[sdcl] = sdcl_labels ##save that list to a dict[sdcl] - so you can make visble later ##i.e. make visible sdcl_label_dict[sdcl] (actual point 1 , actual point 1.maxdev, actual poitn 1.avg dev) # ##itterate through the reports, if the report has a SDCL in its page, Restore Page, Make Labels Visible, Overwrite Page. if self.reject: gom.script.explorer.apply_selection(selection=[]) i = 1 for report in gom.app.project.reports: print(report.report_title, ' ', i, ' / ', report.number_of_pages) i +=1 for page in report.pages: for placeholder in page.placeholders: print(f'\t Placeholder: {placeholder}') if '3D' in placeholder.get('name'): gom.script.explorer.apply_selection(selection=[]) gom.script.explorer.apply_selection(selection=placeholder) for element in gom.ElementSelection({'category': ['key', 'related']}): if element.type == 'inspection_surface_classification': print(f'\t\t\tFound SDCL: {element}') if len ( sdcl_label_dict[element]): ## if labels were created for this sdcl (i.e. if sdcl.number_of_defects !=0 ): print(f'\t\t\t\t...Labels Detected - Restoring View: {placeholder}') gom.script.report.restore_3d_view_from_report_page (page=[placeholder]) for e in sdcl_label_dict[element]: ##restore labels associated with this surface defect map gom.script.cad.show_element (elements=e) gom.script.view.set_auto_hide_labels (enable=True) gom.script.sys.switch_to_report_workspace () print(f'\t\t\t\t...Labels Visible - Overwriting Report Page for : {placeholder}') gom.script.report.overwrite_report_page (target=[placeholder]) print('Function: update_sdcl_labels() - self.reject = ', self.reject ) & to export the SDCL defect characteristic table as an excel file: def export_excel(sdcl_path): try: for p in gom.app.project.parts: if p.part_function == 'used_for_scanning': scanpart = p reject = False df_list = [] sdcl_list = gom.ElementSelection ({'category': ['key', 'elements', 'part', scanpart, 'explorer_category', 'inspection', 'object_family', 'surface_comparison', 'type', 'inspection_surface_classification']}) if len(sdcl_list): ## if there are SDCL's in the project for sdcl in sdcl_list: ##Itterate Through the surfaece defect classifications print(f'SDCL: {sdcl}\n Number of Defects: {sdcl.number_of_defects}') if sdcl.number_of_defects is not None and sdcl.number_of_defects > 0: ##If the SDCL has a defect - Set Reject = True (Combine & Export DFs) reject = True defect_dict = {} ## Clear / Create Empty Dict for Dictionary of Values defect_list = [] ## Clear / Create Empty List for Defect Values ##Create the Header with the Attribute Names atributes = [ 'index', 'class_name', 'class_weight', 'formula_result', 'area', 'volume', 'width', 'length', 'tolerance', 'max_depth_height', 'max_depth_height_1sigma', 'max_depth_height_2sigma', 'max_depth_height_3sigma', 'avg_depth_height', 'avg_depth_height_1sigma', 'avg_depth_height_2sigma', 'avg_depth_height_3sigma', 'coordinate', 'coordinate_of_max_depth_height', 'coordinate_of_max_depth_height_1sigma', 'coordinate_of_max_depth_height_2sigma', 'coordinate_of_max_depth_height_3sigma', 'boundary_line_points', 'length_boundary_line', 'length_inner_boundary_line', 'max_depth_height_distance_to_boundary', 'max_depth_height_distance_to_boundary_at_half_depth', 'max_depth_height_1sigma_distance_to_boundary', 'max_depth_height_1sigma_distance_to_boundary_at_half_depth', 'max_depth_height_2sigma_distance_to_boundary', 'max_depth_height_2sigma_distance_to_boundary_at_half_depth', 'max_depth_height_3sigma_distance_to_boundary', 'max_depth_height_3sigma_distance_to_boundary_at_half_depth', 'max_defect_size_of_surface_defect_map', 'number_of_grouped_defects', 'points_out_of_tolerance', 'volume_at_100_of_tolerance_exceedance', 'volume_at_10_of_tolerance_exceedance', 'volume_at_20_of_tolerance_exceedance', 'volume_at_25_of_tolerance_exceedance', 'volume_at_30_of_tolerance_exceedance', 'volume_at_40_of_tolerance_exceedance', 'volume_at_50_of_tolerance_exceedance', 'volume_at_75_of_tolerance_exceedance' ] defect_dict[sdcl.name] = atributes ##Add it to the Dictionary for this SDCL for i in range (sdcl.number_of_defects): ##Itterate Through the Defects & Add the Defect Characteristics to a List defect_list = [] defect_list.append(i) ##Add the Index # for item in atributes: ##Itterate Through the Attributes if item != 'index': ##sdcl.defec_char[i].index is not a valid Attribute, but we want it in the CSV, so skip over it try: defect_list.append( sdcl.get(f'defect_characteristics[{i}].{item}' ) ) ##Add the arguments to a list except: pass defect_dict[i] = defect_list ##Add that list to the dictionary for that index[0] df = pd.DataFrame.from_dict(defect_dict, orient = 'index') ### Create a data frame from that dictioanry df_list.append(df) ## Add that Dataframe to a List of Dataframes. if reject == True: ##If Defect Detected - Combine all DFs and Export - Catch for No Dataframe Created- so pd.concat(df_list) will work. combined_df= pd.concat(df_list) ##Combine The List of DataFrames into 1 combined_df.to_excel(sdcl_path) ##Export it to excel print('Succesfully Exported SDCL Excel File') return [False, 'Exported SDCL and Excel File Succesfully'] ##Return [False, 'No Errors'] else: return [False, 'No Defects in SDCLs - Did not Export Anything'] ##Return False - No Defects in SDCLs else: return [False, 'No SDCL in Project'] ##Return False, No SDCLs in project, and no problem except Exception as Err: excp = traceback.format_exc() print(f"Could Not Export SDCL File\nException = {Err}\nTraceback:\n{excp}") return [True, excp] ##Return True(Error) if you're working outside kiosk mode and just want to create a report with views, ## Make Something exclusive here: gom.script.cad.show_element_exclusively (elements=['colormap / sdcl / labels...etc goes here') ##Set View (sometimes helpful to use local coordinate system for this) gom.script.view.set_xp_yp_zp ( up_axis='Z+', use_animation=True, widget='3d_view') ##Adapt Zoom gom.script.view.adapt_zoom ( use_animation=True, widget='3d_view') ##Create Report gom.script.report.create_report_page ( animated_page=False, animation=['snapshot_frame_0', 'Along line "", 10.0s'], imitate_fit_mode='overwrite', master_name='Divergent_letter', template_name='3D', template_orientation='landscape', template_package={'name': 'some company name here_Report_Style', 'uuid': '3f7326ab-d50d-4002-9f7b-6dbd47b789e2', 'version': '1.0.26'}, title='Isometric View') Seems like all this should be an integrated gom/zeiss inspect function ('create labels and reports for OOT regions of colormap'), but if you need help in the interim, lmk. Link to comment https://qualityforum.zeiss.com/topic/24057-how-to-use-widget-input-to-trigger-specific-measurement-routines-eg-surface-comparison-in-script/#findComment-137219 Share on other sites More sharing options...
Recommended Posts
Please sign in to comment
You will be able to leave a comment after signing in