Batch Processing Raytraces

This article demonstrates how to run a sequence of raytraces using FRED’s COM capability. 

The script below is kept generic by retrieving and executing the code in the Embedded Script of each FRED Document that is opened. The additional FRED Document “run1.frd” provides a simple test case where a raytrace is performed and Irradiance data is saved before the Document is closed.

Sub Main

    'Use the current FRED as an Automation Server
    Set app=CreateObject("FRED.Application")

        'This script becomes associated with the first FRED Document that is opened.
        'Therefore a dummy Document is created for the duration of this script.
        SysNew "Dummy Doc"

        'The full path of each Document should be listed here

    Set app=Nothing                                 'Clean up

End Sub

Sub openAndRun(filename As String)

    Set doc=SysOpen(filename)                       'Open the FRED Document
        esString=doc.GetEmbeddedScript(0)           'Retrieve the Embedded Script
            Set esLib=doc.CompileText(esString)     'Compile the script
                esLib.Main()                        'Run the "Main" subroutine
            Set esLib=Nothing                       'Clean up
        Set doc=Nothing                             'Clean up
    app.SysCloseNoSave filename                     'Close the FRED Document

End Sub<br>

The user needs to call the openAndRun subroutine for each file to be run, providing the full path to the file. Each of these files needs an Embedded Script which is executed in the line esLib.Main().

The Embedded Script in the attached test file is shown below, and simply does a raytrace, calculates the Irradiance using the "Analysis 1" Analysis Surface, and then saves the data file.

Sub Main

    Dim analID As Long
    Dim arnNode As Long
    Dim success As Boolean

    analID = FindFullName( "Analysis Surface(s).Analysis 1" )
    IrradianceToARN(analID, "Irradiance 1", arnNode)

    success = ARNWriteToFile( arnNode, GetDocDir()&"\"&GetTitle()&".fgd", False, False )
End Sub<br>

Associated FRED file: run1.frd

Still need help? Contact Us Contact Us