[Da...] Posted January 17 Share Posted January 17 because it comes with no additional cost, wuhu. But it only seemed like it's going to work for me if the part has the same geometry and size. And I have silghtly different size on each part and the same geometry. So let's solve this with reading .para on start, but when each part is measured, just rewrite the variable values, so it fits the next part. Presettings: // dont know how to multi line comment // wait for seconds wait(1) // read from .para file parafile = getActualInspectionDir() + "\external\" + "input" + ".para" readPCMFile(parafile) Postsettings: // run python with powershell, needs cleanup pws = getActualInspectionDir() + "\external\" + "run_python" + ".ps1" comcal = "powershell.exe -File " + qm() + pws + qm() systemCall(comcal) wait(5) Powershell script is then calling python.exe: run_python.ps1: $filepathvar = $PSScriptRoot . "$filepathvar\python\python.exe" "$filepathvar\python_script\variable.py" "$filepathvar\input.para" python.exe compiles and runs code/script variable.py: # 2023 Original code GPT-3.5 # 2023 Modified by Rok Medic <dm70dm@gmail.com> import sys # Specify the file path file_path = sys.argv[-1] # Read the contents of the file with open(file_path, 'r', encoding='utf-8') as file: lines = file.readlines() # Extract the variables and values from the lines numVars = int(lines[0].split('=')[1]) variables = [] values = [] lines.pop(0) for line in lines: parts = line.split('=') variable = parts[0].strip() value = parts[1].strip() variables.append(variable) values.append(value) # Modify the lines with updated variables and values new_lines = [ f"{variable} = {value}\n" for variable, value in zip(variables, values[numVars:]) ] new_lines.insert(0, "numVars = "+str(numVars)+"\n") # Write the updated lines back to the file with open(file_path, 'w', encoding='utf-8') as file: file.writelines(new_lines) We take var1 into diameter: and var1 and var101 to throw out correctly named reports and .zmp files: In the python folder is extracted from the link -> EDIT: embeddable version not installer https://www.python.org/ftp/python/3.12. ... -amd64.zip Inside input.para, numVars = 2 will replace 2 lines each run: numVars = 2 var1 = 24.999 var101 = 1111 var2 = 72.954 var102 = 2222 var3 = 62.955 var103 = 3333 var4 = 12.956 var104 = 4444 Link to comment Share on other sites More sharing options...
[Da...] Posted January 19 Author Share Posted January 19 EDIT python download link: embeddable version not installer so no need for windows admin to install 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