- Home
- Programming ZEMAX
- Extensions
- How Do I Write an Extension in C?
How Do I Write an Extension in C?
- By Mark Nicholson
- Published 4 April 2006
- Extensions
-
Rating:




Tricks and Gotchas

The other common error is to forget that the extension sees a copy of the file loaded in the editor, and that there is no reason to be restricted to only the currently loaded file: the LoadFile data item can be used to load any file irrespective of what is being edited in the user interface. In fact, any number of DDE clients can be talking to ZEMAX at any time, while a user is using ZEMAX from the normal keyboad and mouse graphical user interface. Its only when you want to see the results of the Extension program in the user interface that you need to issue the PushLens command.
One often overlooked capability of Extensions is the ability to create text and graphic data files from analysis already supported by ZEMAX by using a single call to zclient. For example, to generate a text listing of the spot diagram, use the command

The spot diagram data will be placed in the text file "OUTPUT.TXT" in the specified directory. For more information, see “GetTextFile” and “GetMetaFile” in the Extensions chapter of the manual. However, there is no way of knowing a priori how long such a calculation will take. As stated earlier, DDE is modeled on a conversation, and if the server does not respond to a client's request within a certain time, known as the timeout period, the DDE communication is assumed to have failed. Within ZCLIENT, the timeout value is set by default to 5000 milliseconds, on line 32:
#define DDE_TIMEOUT 5000This can be easily modified to any desired value, and then recompiled.
Related Articles
Attachments
5 Responses to "How Do I Write an Extension in C?" 
|
said this on 11 Apr 2006 4:40:28 PM PDT
Excellent article. I wish I had read it four years ago. It could have saved me a lot of time.
But I have a suggestion to use C language when writing extensions. Much more power, like your own genetic algorithms for optimization.
|
|
said this on 12 Jun 2006 4:21:15 AM PDT
Very useful article, even for a FORTRAN programmer like myself. I use Compaq Visual Fortran. It is great that ZEMAX have made ZCLIENT.C available, as it has permitted me much easier access to the C-code than would otherwise have been the case, so that I have been able to make changes to the main function declarators to make the functions readily accessible from FORTRAN. The modified ZCLIENT code was then compiled using the Microsoft Visual C compiler and the .OBJ file then included into a FORTRAN project. I have written a FORTRAN module containing INTERFACE blocks for the main C-functions PostRequestMessage, PostArrayTraceMessage and GetString, along with a module defining the DDERAYDATA type so that I can call all the above functions from FORTRAN. It all appears to work fine. If anyone is interested in programming ZEMAX extensions in FORTRAN, just e-mail me.
|
|
said this on 23 Jun 2006 8:41:33 AM PDT
Anthony Richard's article on programming Extensions from FORTRAN is now available at http://www.zemax.com/kb/articles/111/1/How-To-Write-ZEMAX-Extensions-in-FORTRAN, or see the link in 'Related Articles' above.
|
|
said this on 18 Jan 2007 5:33:14 AM PDT
easy to understand! easy to learn! very good article!thanks a lot!
|
|
said this on 19 Mar 2008 4:29:19 PM PDT
I like it .So good !But I need more . Thank you !
|
Author)