[Aj...] Posted September 17 Share Posted September 17 Hello everybody, I am trying to automate a task with GOM using the script editor. I create certain elements with the code and then the deviations are calculated using a certain set of formulas. I encounter the following problem: In the first run the elements are created and the deviation values are calculated correctly. In the second run, the script tries to create the elements again and as these elements are already present, the script throws an error and crashes. My solution: I want to query the name of the elements that are already present in the GOM measurement program such that I can add a check before the evaluation block. If the element needed for calculation is already present, proceed with the calculation, otherwise the element is created. This way the script doesnt try to create the elements again and the program doesnt crash. Thanks in advance! Ajay Link to comment Share on other sites More sharing options...
[Mi...] Posted Thursday at 08:50 AM Share Posted Thursday at 08:50 AM Hi, I think something like this should work for you: name = 'Cylinder 1.Diameter' if len(gom.script.sys.find_elements(text=name, restrict="element")) == 0: print("Create diameter check") gom.script.inspection.inspect_dimension ( name=name, elements=[gom.app.project.inspection['Cylinder 1']], nominal_value_source='from_nominal', tolerance=0.5, type='diameter') else: print("Skip diameter check") 1 Link to comment Share on other sites More sharing options...
[Ra...] Posted Thursday at 07:26 PM Share Posted Thursday at 07:26 PM You could also use "try" and "except", this allows the script to keep running if there is an error try : # Create/calculate code except : pass Link to comment 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