These examples cover the basic FRED scripting commands involving entity information: "Delete" - remove an entity array, "Get" - retrieve entity attributes, "Init" - initialize an entity or entity array, "Is" - query entities, "Set" - set entity attributes.
The following structures are required for entities:
"Delete" an entity array The array properties of an entity can be deleted without deleting the base entity itself.
arrayid=FindName("lenslet array")
"Get" entity data The standard attributes of an entity can be retrieved using the "Get" commands. These include parent, name, description, traceable, neverTraceable, and axesDrawable and limitsDrawable. While individual commands exist for each attribute, the GetEntity command retrieves the full complement of standard attributes (See T_ENTITY) as shown in this example:
Dim entatrib As T_ENTITY id=FindName("lens front") GetEntity id, entatrib
Array parameters can be accessed in essentially the same manner:
Dim arrayatrib As T_ENTITYARRAY id=FindName("tiles") GetEntity id, arrayatrib
The individual commands can be used to identify entities with specific properties:
tcount=0 For i=0 To GetEntityCount()-1 If GetTraceable(i) Then tcount=tcount+1 End If Next i
"Init" entity or array The FRED structures T_ENTITY and T_ENTITYARRAY should be initialized to insure valid values exist for each structure element. FRED loads the default values into the declared structure.
Dim en As T_ENTITY InitEntity en
or
Dim ar As T_ENTITYARRAY InitEntityArray ar
"Is" query The query commands serve to confirm entity type. Use these commands as a tool for checking whether specific operations should be imposed. In this example, only descriptions of curves are examined in an effort to find a specific string.
qal="dog"
"Set" entity data When structures are involved, use "Get" commands in concert with "Set" commands to insure only the specified changes are made. This example adds an extra element in both dimensions to an existing array:
Dim elm As T_ENTITYARRAY arid=FindName("mirror array") GetEntityArray arid, elm elm.aMaxIndex=elm.aMaxIndex+1 elm.bMaxIndex=elm.bMaxIndex+1 SetEntityArray arid, elm
The SetTraceable command can be used to control whether an entity traceable or not. This example loops over entities and makes only prisms not traceable:
For j = 0 To GetEntityCount()-1 If IsPrism(i) Then SetTraceable i, False End If Next i
See Also….
|