Skip to main content

ZOS API Python create and run ZPL Macro Solve for Multi Configuration Editor

  • June 22, 2022
  • 1 reply
  • 607 views

Sahil
Forum|alt.badge.img+1

We can use ZOS API Python to create and run the ZPL Macro Solve. 

Let’s have an example of ZPL Macro Solve. Applying ZPL Macro Solve in Multi Configuration Editor. 

 Now we create this Test_config.ZPL from Python program and run in for loop for all 3 configuration.

We can use ZPL Command as string in Python Program and write in the text file. Then save the file as ZPL in ZPL Macro folder. If we use forloop then we can create and run multiple ZPL Macro solve. As in Multi-configuration, for each configuration need seperate ZPL Macro Solve file.  

Python Code :

NumberOfConfigurations = list(range(TheMCE.NumberOfConfigurations))

# print(NumberOfConfigurations)

ZPLFolder=r"C:\Users\s.rajan\OneDrive - Zemax LLC\Documents\Zemax\Macros"

data=[]

files=[]

fg=[]

for i in range(len(NumberOfConfigurations)):

    filename="Test_config"+format(i+1)+".ZPL" 

    fg.append("Test_config"+format(i+1))

    file= open(os.path.join(ZPLFolder, filename), 'w')  # Create ZPL file

    data.append(str("x_APMN=MCOP(1,")+ format(NumberOfConfigurations[i]+1)+")\n"

                +"x_APMN=MCOP(2,"+ format(NumberOfConfigurations[i]+1)+")\n"

                +"X=SQRT(x_APMN * x_APMN+ x_APMX * x_APMX)\n"

                +"SOLVERETURN X")

    print(data[i])

    file.write(data[i])

    files.append(filename)

    print(fg[i])

    file.close()

    macroSolve = MCOperand3.GetOperandCell(i+1).CreateSolveType(ZOSAPI.Editors.SolveType.ZPLMacro)

    macroSolve._S_ZPLMacro.Macro = fg[i]

    MCOperand3.GetOperandCell(i+1).SetSolveData(macroSolve)

Did this topic help you find an answer to your question?

1 reply

Thomas Magnac
Zemax Staff
Forum|alt.badge.img+2

That a great way to work around the fact that the ZPL macro language is not '’aware'’ of which configuration it is in.
And it is not convenient to manually have to create one macro for each config. 

That's what the API code is doing, great stuff!

Thank you for sharing, Sahil!


Reply


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings