I am writing some python code using PyCharm to generate a non-sequential file from scratch. I’ve used the Zemax API extensively in the past for similar projects which either add or modify lots of rows in sequence, but I haven’t run any of those since before the Ansys merger. Now I’m starting to see some strange behavior as I debug.
I have commands which I know and can verify work, even simple ones like:
TheNCE.AddObject()
While the program is running, it has no issues with these lines. If I save the file and open it, I can see everything is being added, comments are being set, colors are being set, etc. etc. The code works. But once I reach a break point and start debugging, I start getting this error, even when I run these commands that again, I have confirmed work as expected:
System.Runtime.Remoting.RemotingException: Failed to write to an IPC Port: The pipe is being closed.
I did some Googling and while I see some issues relating to server communication, I don’t see any references to Zemax. But, I only see this error when interacting with the Zemax API. I also only see it after I’ve been running for a while. The first ~hour or so after a fresh boot of the PC, it works normally. I can arrive at a break point and start troubleshooting and trying new code and it works as expected. Eventually, it just stops accepting commands, even correct ones, and I start getting this error. The only fix appears to be to reboot the PC again - closing all Zemax instances, restarting the python kernel, nothing else seems to make a difference. My first thought was maybe too many Zemax instances are being “left open” if the program exits before
del zosapi
zosapi = None
can be run, but I’m not sure how to check if any of those instances remain open or how to force them to close.