Applying Importance Sampling Specifications in Script

This knowledge base article describes a method of applying importance sampling specifications to a group of surfaces at once using FRED’s scripting language.  Unlike sources, surfaces, coatings, materials, scatter models, ARN’s and raytrace control sets, scatter importance sampling specifications have no reference node on FRED’s object tree.  Typically, one might use FRED’s object tree to apply a surface property to a group of surfaces by drag and drop at the parent level.  For example, if all child surfaces of a subassembly called “Optics” are desired to have a transmitting coating, it is a simple matter to drag and drop the “Transmit” coating from the Coatings folder on the object tree to the “Optics” subassembly in the Geometry folder.  As scatter importance sampling specifications have no node on the object tree, there is no method to “drag and drop” them for surface assignment.  The embedded scripts in the attached FRED file show a simple method for assigning these importance sampling specifications.

In the attached FRED file there are four embedded scripts:

  1. assignImportanceSample: Loops over surfaces in a user-defined parent node and assigns each qualifying surface the same scatter importance sampling specification.
  2. deleteAllImportanceSample: Loops over surfaces in a user-defined parent node and deletes all importance sampling specifications from the surfaces.
  3. deleteAllScatter: Loops over surfaces in a user-defined parent node and deletes all surface scatter model assignments.
  4. assignScatterModel: Loops over surfaces in a user-defined parent node and assigns all surfaces the same scatter model.

The pseudocode for each embedded script is the following:

  1. Loop over entities in the document and check each to see if it is a surface node.
  2. Qualify the surface as an optical surface by checking its Description for a particular string.  In this example, surfaces that should have scatter models or importance sample specifications assigned/removed are pre-designated to have the description “Optical Surface”.  This can be done either in the GUI or by script.
  3. Modify the desired surface property and print information to the output window.

The full script for the assignImportanceSample embedded script is shown below:

Sub Main

Dim ii As Long, impSamp As Long

ClearOutputWindow

‘PSEUDOCODE STEP 1: Loop over entities and see if they are surfaces

For ii = 0 To GetEntityCount()-1

If IsSurface( ii ) Then

‘PSEUDOCODE STEP 2: Qualify the surface as an optical surface using a user-specified descriptor.  All surfaces to be modified should already have this description applied.

If InStr( GetDescription( ii ), “Optical Surface” ) > 0 Then

Print “Surface ” & GetFullName( ii ) & ” is being modified.”

‘PSEUDOCODE STEP 3 Add an importance sample specification to the qualifying surface.

impSamp = ImpSampAddSpecular( ii, “20 deg. specular”, 10 )

End If

End If

Next ii

End Sub
Download the FRED file: setImportanceSampling2.frd