Is there a way to copy rows from an editor in one file and paste to another file through the API?

  • 2 July 2020
  • 4 replies

Userlevel 1

Yes, you can copy rows from an editor in one file and paste them into the editor of another file through the API.

As an example, I will paste the Multi-Configuration Editor operands from one file to a blank Multi-Configuration Editor in another file using the Matlab ZOS-API. Note that this can be done with all types of editors and also in python/C#/C++.

The trick here is defining both the PrimarySystem and also the second system TheSystem2.

TheSystem = TheApplication.PrimarySystem;

TheSystem2 = TheApplication.CreateNewSystem(ZOSAPI.SystemType.Sequential);

Next you will need to load up the file you want to copy from and define both Multi-Configuartion Editors.

sampleDir = TheApplication.SamplesDir;

testFile = System.String.Concat(sampleDir, '\API\Matlab\MCE file 1.zmx');


TheMCE = TheSystem.MCE;

TheMCE2 = TheSystem2.MCE;

Note that I am opening a file named 'MCE file 1.zmx' that I already have saved in my samples folder under \API\Matlab. 

Now for us to be able to copy over the MCE specifically there must be the same amount of configurations in each file. 

for i = 1:TheMCE.NumberOfConfigurations-1



And finally we can copy all the operands over to the new file and save a new file named 'MCE file 2.zmx'.


testFile2 = System.String.Concat(sampleDir, '\API\Matlab\MCE file 2.zmx');


If we wanted to this with the Lens Data Editor we would define TheLDE  and use CopySurfacesFrom instead of CopyOperandsFrom. Similar changes can be made depending on the editor you are copying from.

4 replies

Badge +1

Hi! Is there a way to copy and paste rows from an existing file to another existing file while keeping the content of both files? In other words, I would like to do this not by creating a new empty system, but loading two different existing systems at the same time. Basically I need to insert a lens into another lens system.

I am trying to open the two systems in Matlab using TheSystem.LoadFile function, but once I load the second system, the first system updates too and becomes a copy of the second system with a different variable name. 

Userlevel 5
Badge +2

Hi Maria,

I’m not sure what you mean about “a different variable name”, but when you’re loading the second system, are you using TheSystem2.LoadFile()TheSystem will be the original file and any operations (including loading and copying rows from the LDE) on the second file will have to be done with TheSystem2 variable.


Badge +1

Hi Michael,

Thank you for the reply. By “different variable name” I did mean that I used two variable names for two different systems loaded from different files:

TheSystem1.LoadFile('file1', false);
TheSystem2.LoadFile('file2', false);

After the execution of the first row, TheSystem1 was the system from file1, however, after the execution of the second row, TheSystem1  and TheSystem2 became equal and they both were systems from file2

But actually I already found a solution (not sure if this is the correct way, but it worked for me). Instead of using TheSystem2.LoadFile in the second row I used 

TheSystem2 = TheApplication.LoadNewSystem('file2');

- Mariia

Userlevel 5
Badge +2

Hi Maria,

I am glad you found a solution using TheSystem2 = TheApplication.LoadNewSystem(‘file2’); but I want to provide complete python code that shows using LoadFile() will also work:

import zosapi, os

# create a new standalone application

zos = zosapi.App()

TheSystem = zos.TheSystem

TheApplication = zos.TheApplication


# create a second system

TheSystem2 = TheApplication.CreateNewSystem(ZOSAPI.SystemType.Sequential)

# load the double gauss on System1

TheSystem.LoadFile(os.path.join(TheApplication.SamplesDir, r'Sequential\Objectives\Double Gauss 28 degree field.zmx'), False)

# load the cooke triplet on System2

TheSystem2.LoadFile(os.path.join(TheApplication.SamplesDir, r'Sequential\Objectives\Cooke 40 degree field.zmx'), False)

# check the number of sequential surfaces

print('LDE Surfaces for System 1: %i' % TheSystem.LDE.NumberOfSurfaces)

print('LDE Surfaces for System 2: %i' % TheSystem2.LDE.NumberOfSurfaces)

The output will be:

LDE Surfaces for System 1: 13

LDE Surfaces for System 2: 8