Skip to main content

About ZOSAPI Error: Object reference not set to an instance of an object


Michael Cheng
Zemax Staff
Forum|alt.badge.img+2

When we see the following error using C# for ZOS API User Extension, the most common reason is we opened a tool and didn't well close it before open it again.



 


For example, in the second built-in sample code, we can see there is a line that calls the funciton close() to close the ray trace tool. The same applies to many other tools like ILocalOptimization, IHammerOptimization, IGlobalOptimization, INSCRayTrace, ITolerancing, IConvertToNSCGroup ... etc.



If we try to open the RayTrace tool again before close the previous one, the error will show.



 


The other similar reason this may happen is we terminate the application, for example using the [x] button, unusually before the tool is closed.



 


Note there is a property called TheSystem.Tools.CurrentTool. It's convenient if we can check it and close if needed when finished the API code like below.


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

0 replies

Be the first to reply!

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