Scripting User Defined Tools

FRED's WinWrap Script capability can be used to define arbitrary custom user tools leveraging Visual Basic style dialog boxes for data entry and/or selection. Once created these scripts can be linked to toolbar buttons and used in any subsequent FRED model.

Graphically creating and editing dialog boxes in WinWrap scripts is invoked via the r-click menu within the script:

The r-click menu option to create / edit a UserDialog. When the UserDialog option is called whilst the cursor is within a block of code defining a dialog box (shown selected) then the existing dialog will be edited, otherwise a new dlalog can be created.

And the following UserDialog editor is invoked where new items can be dragged and dropped onto the dialog (don't forget to save and close after your edits):

Example of the UserDialog Editor

Often the most challenging stage when writing a script leveraging user dialogs is knowing where to start, and so three example FRED scripts are provided below showing dialog boxes being used to create the following user tools.

ARN Smoothing and Rescaling

ARN Smooth & Rescale.frs

The chart functionality of FRED includes the ability to smooth and rescale the data displayed in the charts, however these operations only apply to the copy of the data in the chart window. When using ARN's it can be common to wish to apply similar smoothing and rescaling operations and to save the results back to the ARN folder. The script below defines a user tool to allow the selection of an ARN from a list and apply the related smoothing/rescaling options based on user selections:

User defined script tool to smooth and/or rescale ARN's

Fast Trace and Render

Fast Trace & Render.frs

This example scripted tool helps to speed up tracing and rendering rays by first calling the standard trace (without render) command, which is multithreaded and therefore faster to trace, saving the ray set, then subsequently looping over the saved ray set to render out a user defined number of rays to the 3D view. Saving the ray set incurs a small overhead but overall can be much faster than the existing single threaded "trace and render" option:

User defined script tool to perform a multithreaded trace followed by a render of rays

Gaussian Beam Calculator

Gaussian Beam Calculator.frs

GaussianBeamWaist_RevNB4.bmp

This example scripted tool is a handy calculator of unknown Gaussian Beam quantities from the known quantities, the script uses Select/Case logic and a DialogFunction call to control the output boxes displayed:

Note that this tool also specifies a link to an image - and so to see the image in the tool on your machine you'll need to save the image to your machine and update the reference on line 61 of the script to point at it. The image to copy is linked to above.

Still need help? Contact Us Contact Us