Create ARNs from all FGD files in a directory
A common analysis task in FRED is to perform some calculation(s) over a range of different configurations, which would typically involve the use of a script to configure the model and perform the raytrace and analysis inside of a loop. The analyses resulting from such a loop may also be written to output files on disk using FRED's proprietary FRED Grid Data file format (*.fgd file extension). The purpose of this KB article is to show how to use the script language to search a directory on disk for all *.fgd files and then load the *.fgd files into the FRED document as Analysis Results Nodes (ARNs).
There are three embedded scripts in the example file provided. For the purposes of this KB article, we are interested in the script called "Load FGD directory". Double click on this embedded script to open it in the script editor.
The script begins execution in its Main subroutine. The first task that the script performs is to remove any currently existing analysis results nodes (ARNs) from the Analysis Results folder. The second task that the script performs is to designate a directory path on disk that will be searched for *.fgd files.
Sub Main 'Delete any ARNs from the model ARNDeleteAllNodes() 'Directory that will be searched for FGD files Dim inDir As String inDir = "C:\temp\fred\support\fgd_data"
The next task that the script performs is to leverage a custom function called "GetFiles" that performs the directory search. The specific details of the GetFiles function are not particularly insightful from a FRED perspective; the user can refer to the WinWrap BASIC Help by navigating to Help > Scripting Help > BASIC Language Reference for information on the specific implementation. What is important, however, is the interpretation of the three arguments being passed into the GetFiles function call.
- inDir - this argument is a string defining the directory path that will be searched.
- "fgd" - this argument is the extension of the files being searched for.
- fileList() - this argument is a String array that gets passed into the function call uninitialized. After the GetFiles function completes its execution, this array now contains the full file path of all the *.fgd files found in the designated directory.
'Search the directory and populate the list of FGD files Dim fileList() As String GetFiles( inDir, "fgd", fileList() )
The last task of the Main subroutine is to take the initialized fileList() array and pass it into another custom function that creates one Analysis Result Node (ARN) for each of the *.fgd files that was found. The details of the LoadFgd function call won't be discussed here, other than to say that the ARNCreateFromFile() command is, ultimately, used to load each *.fgd file into the FRED document as an ARN.
'Load the FGD files into the model as Analysis Results Nodes (ARNs) LoadFgd( fileList() ) End Sub
After this script finishes executing, the Analysis Results folder will be populated with one ARN for each of the *.fgd files that was found in the designated search directory.
Example FRED file: fgd_processing.frd