Navigation: Scripting Reference Manual > Script Examples > Examples - Elements

 

Examples - Elements

 

Contact Us: fredsupport@photonengr.com

 

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:

T_LENS

T_EDGEBEVELS

T_MIRROR

T_PRISMCUSTOM

 

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
InitEntity ent
ent.name="my new custom element"
id = AddCustomElement ( ent )

 

 

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
Dim lenz As T_LENS
 

InitEntity ent
InitLens lenz
 

ent.name="my new lens"
lenz.thickness=7.21
lenz.wavelength=0.6328
lenz.semiApe=15.6
lenz.paramType="Radii"
lenz.param1=38.3
lenz.param2=-46.84
lenz.glassName="F2"    'this material must already be in the Material Folder
 

lid = AddLens ( ent, lenz )
Update

 

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 )
Update

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
Dim lenz As T_LENS
 

InitEntity ent
InitLens lenz


 

"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
Dim lenz As T_LENS

lid=FindName("my new lens")
GetEntity lid, ent
GetLens lid, ent, lenz
 

lenz.paramType="Radii"
lenz.param1=38
lenz.param2=-50
SetLens lid, ent, lenz
Update


 

See Also….

Advanced Raytrace

Basic Raytrace

Coatings

Curves

Entity Info

General Ray Data

Gratings

Importance Sampling

Linear Transforms

Materials

Ray Buffer Handling

Ray Data Get/Set

Ray Path

Raytrace Control

Scatter

Sources

Surfaces

 

 

 

 

 

Copyright © Photon Engineering, LLC