These examples cover the FRED Element scripting commands: "Add" - add an element, "Convert" - convert to Custom Element, "Get" - retrieve element parameters, "Init" - initialize an element or structure, "IsElementEdge" - query edge properties, "Set" - set element parameters.
The structures listed below contain parameters required for Element commands:
FRED Elements come in four types: Lens, Mirror, Prism or Custom. The Subassembly is a convenient form for organizing collections of elements. However, elements are not FRED objects. Elements contain FRED objects, surfaces, mirrors, lens, prism, etc.
"Add" Elements To create a new Custom Element, first declare a T_ENTITY structure and initialize (see "Init" section below). Give the new Custom Element a name and set any other parameters as required. This element is now ready to be assigned as a New Curve or New Surface. Note that Subassembly creation follows essentially the same set of steps.
Dim ent As T_ENTITY
To add a Lens Element, first declare T_ENTITY and T_LENS structures then Initialize. Set the desired parameters for the lens then issue the AddLens command:
Dim ent As T_ENTITY InitEntity ent ent.name="my new lens" lid = AddLens ( ent, lenz )
Adding a Catalog lens requires only two lines:
id = AddCatalogLens ( 2, "LFS025", "Melles Griot" ) Update
"Convert" an Element The ConvertToCustomElement command turns a Lens, Mirror or Prism into its constituent surfaces. This command gives the user complete access to the attributes of the individual surfaces and curves making up an the Element.
success = ConvertToCustomElement ( id )
"Get" Element properties The "Get" commands retrieve information from Elements.
Add the GetFocalLength command to a Lens Element defined in terms of radii or curvature to find its focal length:
: : lid = AddLens ( ent, lenz ) fl = GetLensFocalLen ( lid ) Print "Focal length=",fl
"Init" an Element The "Init" commands initialize parameters for Lenses, Mirrors, and Custom Prisms. See T_LENS, T_MIRROR and T_PRISMCUSTOM.
Dim ent As T_ENTITY InitEntity ent
"IsElelemtEdge" queries The "IsElementEdge" commands query elements as to the type of edge used: None, Tube, Rectangle, or Bevels.
Print "Element 4 has a tubular edge-", IsElementEdgeTube(4)
"Set" Element properties The "Set" commands allow the user to alter the properties of Elements.
Let us assume that the lens created in the above AddLens example exists in a FRED document either by definition in the GUI or by another script. This example illustrates the proper method of altering the radii from a different script. Once again, T_ENTITY and T_LENS structures must be defined. "Get" commands are first issed to retrieve the lens element information. To change the radii, the parameter type "Radii" must again be declared to notify FRED that the values param1 and param2 are expressed once again in radii. FRED does not remember that the original lens definition was done in "Radii". The new radii are are then set and the SetLens command issued.
Dim ent As T_ENTITY lenz.paramType="Radii"
See Also….
|