These examples cover the basic FRED scripting commands involving Surfaces: "Add" - add a Surface or surface attribute, "AuxData" - auxiliary data management, "Delete" - remove a Surface attribute, "Get" - retrieve Surface attributes, "Init" - initialize a Surface structure, "Set" - set Surface attributes.
The following structures are required for specifying Surfaces and their spatial extent:
- Surfaces MUST be added in the Tree under a Custom Element. Failure to do so could lead to erroneous behavior.
- All surfaces require a T_ENTITY structure as part of their definition in order to specify a minimum amount of information such as parentage, name, trace status and basic visualization attributes. An un-initialized T_ENTITY structure will often lead to undesirable surface attributes. Initializing the T_ENTITY structure and providing a unique name is always recommended.
- Upon creation, all surfaces acquire default Trimming, Location/Orientation, Visualization, Material, Coating, and Raytrace control attributes shown below. Unless specified, FRED will also give the new surface the name "Surf n" where n is an automatically incremented integer. The user is responsible for supplying explicit values for these attributes to achieve the desired result.
- There need not be a separate T_ENTITY structure for each new surface. Once declared, a T_ENTITY structure can be reused as often as necessary as long as the desired attributes are updated for each instance of its use.
"Add" a Surface or Surface attribute As a minimum, a T_ENTITY structure must be declared when creating new surfaces. Always initialize this structure to insure predictable results. In the following example, a single T_ENTITY structure is used to create a series of different surfaces. Note that the same structure can be utilized in the creation of the Custom Elements under which these surface reside.
Please make sure that your script is followed by an Update command so that your geometry is properly created on the object tree. Failure to do so will leave the document in an invalid state and may need to be re-loaded.
Adding a Plane or Conic Dim ent As T_ENTITY
ent.name="conic 1.1" Adding a Tube ent.parent=2 Adding a Conic Foci ent.parent=2 Adding an Asphere ent.parent=2 Dim evena(2) As Double evena(0)=1.32e-2: evena(1)=-4.923e-4: evena(2)=7.662e-7 asp1id = AddAsphere( ent, 0.4, -2.038, evena, odda )
Adding a Polynomial Asphere ent.parent=2
ent.parent=c5id 'user defined aspheric coefficients Dim coefp(4) As Double coefp(0)=-1.2e-4: coefp(1)=2.89e-4: coefp(2)=0.4e-5: coefp(3)=6.6e-7: coefp(4)=9.3e-8
pa1id = AddPolynomialAsphere ( ent, -0.25, 1.6, coefp ) '*******************************
Adding a Toroidal Asphere ent.parent=2
Dim tasp As T_TOROIDALASPHERE ent.parent=c6id
'T_TOROIDALASPHERE data goes here
'user defined toroidal asphere coefficients id = AddToroidalAsphere ( ent, tasp, ctasp ) '*******************************
Adding an XY Toroidal Asphere ent.parent=2
Dim xytasp As T_TOROIDALASPHERE ent.parent=c7id
'T_TOROIDALASPHERE data goes here
'user defined XYtoroidal asphere coefficients
id = AddXYToroidalAsphere ( ent, xytasp, cxytasp ) '*******************************
Adding a Zernike Aspheric Surface ent.parent=2
ent.parent=c8id
'use SetZernikeSurfCoefInterpretation, SetZernikeSurfBaseConic, SetZernikeSurfIthAsphCoef
Dim zrn8(4) As Double id = AddZernikeSurf ( ent, 2.5, 2.5, zrn8 ) '*******************************
Adding an Implicit Scripted Surface ent.parent=2
ent.parent=c9id
scrptsurfid=AddImplicitScriptSurf ( ent ) 'use SetImplicitScript to specify script name '*******************************
Adding a NURB Surface (using 1-D points array, see the AddNURBSurf topic for discussion) ent.parent=2
ent.parent=c10id
Dim knotU(3) As Double Dim knotV(3) As Double Dim Npoints(3*4-1) As Double Dim Nweights(3) As Double
knotU(0)=0 : knotU(1)=0 : knotU(2)=1 : knotU(3)=1
NURBid = AddNURBSurf ( ent, 1, 1, 2, 2, knotU, knotV, Npoints, Nweights ) '*******************************
Adding a Revolved Surface ent.parent=2
ent.parent=c11id
Dim rvs As T_REVOLVESURF InitRevolveSurf curvid, rvs 'uses existing curve to create surface of revolution
'T_REVOLVESURF data goes here
rsid = AddRevolveSurf ( ent, rvs ) '*******************************
Adding a Ruled Surface ent.parent=2
ent.parent=c12id
Dim rlds As T_RULEDSURF 'no Init command exists for Ruled Surface so attributes MUST be assigned rlds.curve1=curv1id rlds.curve2=curv2id rlds.crossConnect=True
rld1id = AddRuledSurf ( ent, rlds ) '*******************************
Adding a Spline Surface ent.parent=2
ent.parent=c13id
Dim uBp(1) As Double uBp(0)=0 : uBp5(1)=1 splnid = AddSplineSurf ( ent, 2, 2, uBp, vBp, Spcoef ) '*******************************
Adding a Tabulated Cylinder ent.parent=2
ent.parent=c14id
Dim tc As T_TABULATEDCYLINDER 'no Init command exists for Tabulated Cylinder so attributes MUST be assigned tc.x=0 : tc.y=0 : tc.z=1 'extrusion direction vector tc.curve=crv8id 'identifier of curve to be extruded
tcylid = AddTabulatedCylinder ( ent, tc ) '*******************************
Adding a Trimmed Parametric Surface ent.parent=2
ent.parent=c15id
id = AddTrimmedParametric ( ent, 38, 26, 27 ) '******************************* Update
"AuxData" management
"Delete" a Surface attribute Delete a scatter model from a surface as shown in this example:
id=FindName("Diffuser") scid=FindScatter("White Lambertian") DeleteSurfIthScatter id, scid
"Init" a Surface structure (see "Add" section above)
"Get/Set" Surface attributes Use the "Get" and "Set" commands to retrieve and change Surface parameters. In this example, the 2nd to the last XYToroidal Aspheric coefficient is reduced by 10%:
id=FindName("potato chip optic") n = GetXYToroidalAsphereCoefCount ( id ) cval = GetXYToroidalAsphereIthCoef ( id, n-3 ) cval=cval*0.9 SetXYToroidalAsphereIthCoef id, n-3, cval
In this example, the trimming hole location in a primary mirror is shifted in the +x-direction by 0.2 mm:
Dim tv As T_TRIMVOLUME
id=FindName("Primary") GetTrimVolume id, tv tv.xCenterHole=tv.xCenterHole+0.2 SetTrimVolume id, tv
Material, Scatter model, Coatings and Raytrace controls for a specific surface can be retrieved and changed. Here, all surfaces using a specific Raytrace control have that attribute changed:
For i=0 To GetEntityCount()-1 See Also….
|