Skip to main content
Solved

ZPL output err


when i use ZPL output to a text file , The output always stops halfway, and Zemax prompts "cannot open text file". Does anyone know why? For example, I plan to output 40,000 lines of data, but it stops at 10,000.

Best answer by MichaelH

Hi Yonghong,

There is nothing inherent about the file size a ZPL macro can output.  I was able to write out 1,000,000 lines to a 25Mb file with the following sample code:

OUTPUT "D:\temp.txt"

FOR i = 1, 1000000, 1
	PRINT i
NEXT

OUTPUT SCREEN

Make sure to address the issues that David mentioned.  Also, as you see above, I use the OUTPUT SCREEN command to close the file buffer.  If you use OUTPUT file$ and OUTPUT SCREEN a lot inside a FOR loop, you could run into system level file lock errors.  If you are opening and closing a file a lot, it’s a good idea to use $TEMPFILENAME() for each new file (OpticStudio will create a new file in the %TEMP% folder, which is always writeable by the logged in user) and then to join all the individual files after you close them all.

If you can post your ZPL code (along with any needed ZMX files), the community can help more.

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

3 replies

David.Nguyen
Luminary
Forum|alt.badge.img+2

@yonghong.Li 

 

I’m not sure, but can you try to write the text file in another location, ideally somewhere on your local computer where you know you have read/write access. Also make sure that no other program is accessing the file while the macro runs (such as an antivirus). Probably stupid suggestion but also make sure there’s enough space to write the file. I’m not aware of a hard cap of 10 000 lines. How big is the file when OS stops?

Take care,


David


MichaelH
Ansys Staff
Forum|alt.badge.img+2
  • Ansys Staff
  • 352 replies
  • Answer
  • April 2, 2025

Hi Yonghong,

There is nothing inherent about the file size a ZPL macro can output.  I was able to write out 1,000,000 lines to a 25Mb file with the following sample code:

OUTPUT "D:\temp.txt"

FOR i = 1, 1000000, 1
	PRINT i
NEXT

OUTPUT SCREEN

Make sure to address the issues that David mentioned.  Also, as you see above, I use the OUTPUT SCREEN command to close the file buffer.  If you use OUTPUT file$ and OUTPUT SCREEN a lot inside a FOR loop, you could run into system level file lock errors.  If you are opening and closing a file a lot, it’s a good idea to use $TEMPFILENAME() for each new file (OpticStudio will create a new file in the %TEMP% folder, which is always writeable by the logged in user) and then to join all the individual files after you close them all.

If you can post your ZPL code (along with any needed ZMX files), the community can help more.


  • Author
  • Infrared
  • 5 replies
  • April 3, 2025

I changed the format of zmx file encoding and txt file encoding in zemax settings from ANSI to Unicode, and ZPL outputted complete data. Thank you very much


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