Combining Creo and Zemax
- March 9, 2016
- 0 replies
- 2629 views
This will show You, how You can easily import coordinate systems from Zemax to Creo. All code is attached to this blog entry as a zip-file.
The zipfile includes code from these sources:
- JQuery Copyright (c) 2011 John Resig, http://jquery.com/
- JQuery UI Copyright (c) 2011 Paul Bakaus, http://jqueryui.com/
- DataTable Copyright (c) 2008-2011, Allan Jardine, http://www.datatables.net/
- JMetro by Thomas Ingwersen (http://www.jquit.com/builder)
- "Computing Euler angles from a rotation matrix" by Gregory G. Slabaugh
In Zemax - an optics simulation software - optical elements can be located by their local coordinate systems. This is very helpful if the components of an optical system are not placed in a straight line but dirstributed in xyz directions.
The following scripts uses a text file, which was exported by zemax and is structured like:
<optical_component_name>,<translation in x>,<translation in y>,<translation in z>,<rotation around x>,<rotation around y>,<rotation around z>
e.g. this could be the content of a simple system (see "zemax_csys-export.txt").
! DD.MM.YYYY automatically generated by Zemax
! Generated from Zemax-file: Lensfilename.zmx
SRF_0_base,0.0000000000,0.0000000000,0.0000000000,0.0000000000,0.0000000000,0.0000000000
SRF_1_dummy,0.0000000000,0.0000000000,5.0000000000,0.0000000000,0.0000000000,0.0000000000
SRF_2_lens1,0.0000000000,0.0000000000,6.0000000000,20.0000000000,0.0000000000,0.0000000000
SRF_3_lens2,0.0000000000,0.0000000000,8.0000000000,20.0000000000,0.0000000000,0.0000000000
SRF_4_aperture,0.0000000000,0.0000000000,12.0000000000,0.0000000000,0.0000000000,0.0000000000
SRF_5_dummy,0.0000000000,0.0000000000,14.0000000000,0.0000000000,0.0000000000,0.0000000000
SRF_6_image,0.0000000000,0.0000000000,20.0000000000,0.0000000000,0.0000000000,0.0000000000
This text files was generated by the zemax macro "Export Creo CS text file.zpl".
In Creo Parametric run "zemax_app.html" in Your embedded browser. Make sure ActiveX is activated.
The page will ask you to point to the zemax transfer text file, which contains the coordinate system information.

Then the page will read the file's content by using
var active_file = fso.OpenTextFile(filepath, 1, false);
var active_file_string = active_file.readAll();
active_file.Close();
Then the information of the file gets structured in serveral arrays and displayed in a table.

After pressing "Create Csys" the script will create the coordinate systems by using the function "create_csys_from_file()", which was described in https://www.ptcusercommunity.com/people/Mat/blog/2016/02/26/create-coordinate-system-via-weblink .
Hint: It is mandatory, that there is a coordinate system in Your part, which is named "CS_0". This would be the starting point for this import.
At last, all coordinate systems are created and renamed.

Enjoy!
This thread is inactive and closed by the PTC Community Management Team. If you would like to provide a reply and re-open this thread, please notify the moderator and reference the thread. You may also use "Start a topic" button to ask a new question. Please be sure to include what version of the PTC product you are using so another community member knowledgeable about your version may be able to assist.

