Solved

ZOS API: opening a ZAR file

  • 16 January 2021
  • 3 replies
  • 224 views

Userlevel 2

I'm using the ZOS API to work with ZAR files our engineers produce. We're using ZAR files since there are CAD files associated with the ZMX file. I want to open a ZAR file. There aren't any examples of how to do this, and `TheSystem.Tools.OpenRestoreZAR` isn't well documented; for example, `get_ArchiveFile` isn't in the docs.



Here is my code so far:



zos = PythonStandaloneApplication()
zos_api = zos.ZOSAPI
zos_system = zos.TheSystem
zos_system.MakeNonSequential()
zos_system.SystemData.MaterialCatalogs.AddCatalog('SCHOTT')
non_sequential_component_editor = zos_system.NCE
zar_path = os.path.join('..', 'data', config['filename'])
if not os.path.exists(zar_path):
print(f'ZAR file does not exist at {zar_path}.')
zar_restorer = zos_system.Tools.OpenRestoreZAR()
status_code = zar_restorer.SetFileName(zar_path)
print(status_code)

`SetFileName` doesn't work even if I know there is a ZAR file at that location. Where do I go from here? I want to open the ZAR file and run a ray trace with `zos_system.Tools.OpenNSCRayTrace()`.


 

icon

Best answer by Csilla Timar-Fulep 18 January 2021, 12:48

View original

3 replies

Userlevel 2

For now, I can ask them to send me a zip file. I'd prefer to use ZAR so that it's easier for them.

Userlevel 2

Even though Python can recognize that a file exists there, the ZOS API doesn't work if you use relative paths. This problem also exists for opening ZMX files. Changing it to an absolute path worked. :(



Help is welcome if anyone has an example of working with a ZAR file.

Userlevel 5
Badge +2

Hi Chris,


Thanks for posting here on the forums!


In order to open a ZAR file from the API, you need to to run the Restore Archive tool. You may find more information about the member functions and properties of the ZOSAPI.Tools.General.IRestoreArchive Interface Reference in the ZOS-API Syntax Help:



After opening the tool and adjusting its settings, you will need to run it. Please find the python code below:



zar_restorer = TheSystem.Tools.OpenRestoreZAR()
status_code = zar_restorer.SetFileName(ZARfilePath)
zar_restorer.RunAndWaitForCompletion()
zar_restorer.Close()

When running the code you will need to provide the full path name, including the file name and its extension.


I hope this helps!

If you have further questions, please let us know and we will be happy to help!


Best,


Csilla

Reply