SetTraceable vs SetEntity

To set/toggle an object's "Traceable" state in a script, you may use either of the following subroutines: 

  • SetTraceable
  • SetEntity

However, as shown in the the examples below, the results may be slightly different. 

Using SetTraceable

    Dim i As Long
    For i = 0 To GetEntityCount() - 1
        If IsLens(i) Then
            SetTraceable i, False
        End If
    Next i
    Update

The above script loops over all entities in the model (the contents of the Optical Sources, Geometry, and Analysis Surfaces folders) and uses SetTraceable to set the traceable state to be false for all lenses.

Even though this script sets the lenses to be Not Traceable (as indicated by the gray icon and the red X), they remain visible in the Visualization View, because this subroutine does not affect an object's children. As shown, you can expand the parent node to see that they are still traceable. Important Note: These surfaces are indeed ignored because of their parent's untraceable state.  

Using SetEntity

    Dim i As Long, ent As T_ENTITY
    For i = 0 To GetEntityCount() - 1
        If IsLens(i) Then
            GetEntity i, ent
                ent.traceable = False
            SetEntity i, ent
        End If
    Next i
    Update

The above code is similar to the previous but uses the T_ENTITY structure and the SetEntity/GetEntity pair of routines to set the lens' traceable state to false. This sets it for both the parent and the children resulting in a less ambiguous configuration.

Associated FRED file: SetTraceableSetEntityExample.frd

Still need help? Contact Us Contact Us