27 - Using Expressions and Variables
27 - Using Expressions and Variables
ID ............................................................................................................................. 6
Extension ................................................................................................................. 6
Description Area....................................................................................................... 9
i
Table of Contents
Literals ................................................................................................................... 11
References............................................................................................................. 12
Variables ................................................................................................................ 19
Structures............................................................................................................... 23
Pointers .................................................................................................................. 25
Arrays..................................................................................................................... 27
Precedence ............................................................................................................ 38
Functions ............................................................................................................... 38
ID Expressions ....................................................................................................... 84
ii
Using Expressions and
Variables
Using Expressions and Variables:
Introduction
An expression is a user-defined condition used with PC-DMIS's flow control commands.
Using flow control statements, you can test these conditions in your measurement
routine. If the condition is met or not, you can determine what action PC-DMIS takes.
Expressions are important to making PC-DMIS accomplish your specific tasks. When
you use expressions in conjunction with flow control commands, you can unleash even
more of PC-DMIS's powerful functionality.
This chapter explains how to create and use expressions inside the PC-DMIS Edit
window. When you work with expressions, you should place the Edit window into
Command mode. This allows you to view the Edit window code directly.
1
Using Expressions and Variables
The box of an auto feature that specifies the type of the auto feature, such as
a Surface point, Auto Circle, Auto Round Slot, and so on, does not allow expressions.
The subtopics under this topic offer a complete reference to available expressions.
2
Creating Expressions with the Expression Builder
Suppose you type the expression " `1/7 " in a numeric field. The expression is
immediately solved and only the value (0.143) is placed in the field.
PC-DMIS allows you to create and add expressions into the Edit window by typing them
or using the interface of the Expression Builder dialog box. The Edit | Expression
menu option displays the Expression Builder dialog box.
3
Using Expressions and Variables
This dialog box allows you to create an expression and insert it into an editable field.
Pressing the F2 key while the cursor is on a field that allows expressions also displays
the Expression Builder dialog box.
The Expressions Builder dialog lists all of the types of operators and functions that are
available for expressions.
To enter an expression by using the Expression Builder dialog box (Edit | Expression):
4
Creating Expressions with the Expression Builder
5. Select the expression element type from the first drop-down list. Depending on
your selection, other combination boxes appear.
6. Select the desired ID from the ID drop-down list.
7. Select an extension from the Extension drop-down list.
8. Select another extension from the Second Extension drop-down list. If the
expression is usable, the Add button becomes available.
9. Click the Add button. The expression appears in an edit box.
10. Click the OK button. The expression now appears where your cursor is in the
Edit window.
You can also open the Expression Builder dialog box from these other dialog
boxes:
Once the expression is created, PC-DMIS automatically inserts the expression at the
next legal position in the Edit window.
Since the test of expression correctness occurs at the time you leave a field, a field that
turned red due to a reference of a nonexistent object, (ex. CIRCLE1.X) will remain red
even if the new object (for example, CIRCLE1) is added. The field remains red until the
expression is retested for correctness.
5
Using Expressions and Variables
• Functions
• Operators
• Alignments
• Comments
• Dimensions
• Features
• Variables
ID
The ID drop-down list in the Expression Builder dialog box (Edit | Expression) lists
the set of items available based on the expression element type selected in the
Expression Element Type drop-down list.
Extension
The Extension drop-down list in the Expression Builder dialog box (Edit |
Expression) becomes available when the item chosen in the ID drop-down list requires
the addition of an extension in order to form a usable expression element. The
Extension drop-down list displays available extensions based on the item selected in
the ID drop-down list.
6
Creating Expressions with the Expression Builder
Suppose you select a feature from the ID drop-down list. The list of possible
extensions that can be used to reference data of that feature (such as "X", "Y", "Z",
"Diam", "Length", etc.) are then listed in the Extension drop-down list.
Measured
• All – All the values of the feature are assigned to the variable. See the example
below.
• X – Measured X values of the hits
• Y – Measured Y values of the hits
• Z – Measured Z values of the hits
• XYZ – Measured XYZ values of the hits
• I – Measured I values of the hits
• J – Measured J values of the hits
• K – Measured K values of the hits
• IJK – Measured IJK values of the hits
Theoretical
F1=GENERIC/POINT,DEPENDENT,CARTESIAN,$
NOM/XYZ,<8,9,10>,$
MEAS/XYZ,<7.98,8.98,9.98>,$
NOM/IJK,<1,0,0>,$
MEAS/IJK,<1,0,0>
7
Using Expressions and Variables
ASSIGN/MYFEATURE=F1.ALL
ASSIGN/V1=MYFEATURE.X
ASSIGN/V2=MYFEATURE.TX
Second Extension
The Second Extension drop-down list becomes available only if the item chosen in the
Extension drop-down list requires the addition of a second extension in order to form a
usable expression element.
Suppose you are referencing the nominal value of the X location axis of a
dimension named "D1". You would:
Add Button
Whenever you select a usable or complete expression element using the drop-down
lists, the Add button becomes available. This button displays the text to be added to the
expression.
Then the Add button becomes enabled and would have the following text: Add
D1.X.NOM.
8
Using Variables with Expressions
Upon clicking the Add button, the text then appears in the edit box at the bottom of the
dialog box.
When you click the OK button, the text from the edit box is added to the Edit
window, to the expression field where your cursor is. If you select an item from the Edit
window's expression field, and the text to be added contains parenthesis, then the
selected item would be placed inside of the parenthesis of the added text.
Edit Box
At the bottom of the Expression Builder dialog box (Edit | Expression) is an edit box
that shows the current expression. You can type the expression directly into this box, or
you can use the Add button.
Description Area
The Expression Builder dialog box (Edit | Expression) also contains a Description
area that gives information about items selected from the drop-down lists. A field next to
the Add button also shows the current value of the expression.
For example, the statement ASSIGN/V1=2 creates a variable with a name of V1 and a
value of 2. ASSIGN/V2=V1+2 accesses the value of V1. If V1 still had a value of 2
when this assign statement was executed, V2 would then have a value of 4.
9
Using Expressions and Variables
The Insert | Assignment menu option displays the Assignment dialog box. Use this
dialog box to assign a value to a variable or data element of a measurement routine
feature, dimension, or alignment. Use of the assignment command requires a basic
understanding of PC-DMIS expressions.
Assign To button - This button designates the variable that is receiving the value
calculated in the Assign From box. Information chosen using the Assign To
button is placed in the Assign To box. This value can be the name of a variable or
a reference to a data element of a feature, dimension, or alignment.
The result of solving the mathematical expression for a value is what is meant by the term
"evaluated".
Assign From button - This button places the value being assigned into the
Assign From box. If this box contains an expression, the expression is evaluated
at execution time and the result or value of the calculation is assigned to the
object specified in the Assign To box.
Insert button - This button inserts an assignment command into the measurement
routine while keeping the Assignment dialog box open. A series of assignment
commands can be inserted without closing the dialog box.
• Integers
• Real Numbers
• Strings
10
Understanding Expression Components
• Points
• Feature Pointers
• Arrays
• Functions
Operand Types
The operands may exist in the form of:
• Literals
• References
• Variables
• Structures
• Pointers
• Arrays
Literals
*Integers: 1, -6, 209
Points: A literal representation is not available for points. However, points can be made
from other literals using the MPOINT function: For example,
MPOINT(0,0,1), MPOINT(2.2,3.1,4.0).
Arrays: A literal representation is not available for arrays. However, arrays can be
created from other literals using the ARRAY function: For example, ARRAY(3,5,6),
ARRAY("Hello",2.3,9). These functions create 3 element arrays with the integer
elements 3, 5, and 6 in the first example and the string element "Hello", double element
2.3, and integer element 9 in the second example.
Functions: A literal representation is not available for functions. Functions are defined
using the FUNCTION keyword and accessed via variable ids. For example,
11
Using Expressions and Variables
References
References refer to data members of other objects in a measurement routine.
References use the ID of an object in the measurement routine followed by a dot and an
extension that refers to the data member of the object.
12
Understanding Expression Components
FEAT1.TYP The type of the feature (i.e. circle, slot, cone). This can be used to change
the type of a generic feature (ASSIGN/Gen1.TYP=Feat1.TYP).
FEAT1.ALL Refers to all elements of the feature. This is valuable for copying
information to a generic feature. (ASSIGN/Gen1.ALL=Feat1.ALL)
Surface Vector
EDGE.SURFI
EDGE.SURFJ
EDGE.SURFK
EDGE.TSURFI
EDGE.TSURFJ
EDGE.TSURFK
13
Using Expressions and Variables
Angle Vector
CIR.ANGI
CIR.ANGJ
CIR.ANGK
CIR.TANGI
CIR.TANGJ
CIR.TANGK
Radius
CIRCLE1.R
CIRCLE1.TR
CIRCLE1.RAD
CIRCLE1.TRAD
CIRCLE1.RADIUS
Diameter
CIRCLE1.D
CIRCLE1.TD
CIRCLE1.DIAM
CIRCLE1.TDIAM
CIRCLE1.DIAMETER
14
Understanding Expression Components
Angle
CONE.A
CONE.TA
CONE.ANG
CONE.TANG
CONE.ANGLE
CONE.TANGLE
CONE.TPA – Theoretical Polar Angle (Only the first characters are significant)
Length
LINE.L
LINE.TL
LINE.LEN
LINE.TLEN
LINE.LENGTH
Height
15
Using Expressions and Variables
Area
Currently, only the Blob feature works with these area extensions. For information on
the Blob feature, see the "Vision Blob" topic in the "PC-DMIS Vision" documentation.
DIM1.X.PTOL The Plus Tolerance Value for the X Axis Location of DIM1
DIM1.X.MTOL The Minus Tolerance Value for the X Axis Location of DIM1
DIM3.PA.MEAS The Measured Value for the Polar Angle Location of DIM3
The Plus Tolerance Value for the M Axis of DIM4 (See *Note
DIM4.PTOL
under "Valid Axes " below).
16
Understanding Expression Components
Valid Axes:
17
Using Expressions and Variables
18
Understanding Expression Components
YES/NO comment types set the input to the appropriate yes or no string based on the
current language of PC-DMIS. In the English version of PC-DMIS, if the operator
presses the yes button, the string is set to "YES". If the operator presses the no button,
the string is set to "NO". When comparing strings to test for "YES" or "NO", the
comparison is case sensitive. Thus, comparing against "yes" or "no" always fails even if
the YES/NO comment input is set to "YES" or "NO".
Variables
Variables can be of any of the seven operand types: integer, real, string, point, feature
pointer, array, and function. Variables come into existence and receive their value and
type via the ASSIGN statement. The variable ID can be any alphanumeric string that
does not begin with a numeric character. Underscores can also be used in the variable
id provided that the underscore is not the first character.
Variable values are saved between execution runs. This means if routine execution
stops and re-starts, the values the variables have when execution stops will be the
same values when execution starts again.
19
Using Expressions and Variables
If the Edit window is active, PC-DMIS indicates the current value of the
variable whenever the cursor is placed in the field. During execution, variable values
change based on execution flow. Position the mouse pointer over the desired variable
to find out its current value.
ASSIGN/V1=2.2+2
Variable V1 is a real number with the value of 4.2
ASSIGN/VAR1=CIRCLE1.X
Variable VAR1 is a real number with a value equal to the measured value of
CIRCLE1.X at the time of assignment.
ASSIGN/MYVAR=LINE1.XYZ
Variable MYVAR is a point with the same value of the measured centroid of LINE1
at the time of assignment.
ASSIGN/SVAR="Hello World"
Variable SVAR is a string with the value "Hello World"
In these examples, variables are being assigned values. Once a variable has been
assigned a value, you can use the variable as an operand in any expression field.
Here, V1 is used in a numeric field. It is used as the prehit value of the prehit
command:
ASSIGN/V1=1/3PREHIT/V1
The components of variables of type point can be referred to individually using the dot
extension notation used for references.
ASSIGN/V1=MPOINT(3,4,5)
V1 is of type point with value of 3, 4, 5
ASSIGN/XVAR=V1.X
XVAR is of type double with the value of 3
20
Understanding Expression Components
ASSIGN/YVAR=V1.Y
YVAR is of type double with the value of 4
ASSIGN/IVAR=V1.I
IVAR is of type double with the value of 3
ASSIGN/REDUNVAR=V1.XYZ
REDUNVAR is of type point with the value of 3, 4, 5
The following extensions are equivalent to each other. Both are provided to clarify the
meaning of an expression in a measurement routine.
If a variable of type string has a string value equal to the name of the id of a feature,
dimension, or alignment, the variable can be used as a reference object:
ASSIGN/V1="CIRCLE1"
The following operands are possible and valid provided a feature with the name
CIRCLE1 exists.
This type of indirection available on string variables is only available to one level of
indirection. The following will not work.
ASSIGN/V1="CIRCLE1"
ASSIGN/V2="V1"
21
Using Expressions and Variables
The reference V2.X will not be flagged as an error with red text even
though an expression above it sets its type to a string. The reason it cannot be
flagged as an error is because the flow of execution of the measurement routine is
not known until execute time.
ASSIGN/V1={CIRCLE1}
ASSIGN/V2={V1}
ASSIGN/V1="CIRCLE1"
ASSIGN/V2="V1"
IF/CIRCLE1.X>CIRCLE1.TX,GOTO,L2
L1=LABEL/
ASSIGN/V3=V2.X
GOTO/LABEL,L3
L2=LABEL /
ASSIGN/V2=MPOINT(2,5,7)
GOTO/LABEL,L1
L3=LABEL/
If during routine execution the value of CIRCLE1.X is greater than the value of
CIRCLE1.TX, then the expression V2.X will be valid and will evaluate to 2. Otherwise,
the expression V2.X will evaluate to 0 since the value of V2 at the time of the ASSIGN
for V3 is the string "V1". It is the responsibility of the part programmer to ensure that
expressions will do as expected in these cases.
22
Understanding Expression Components
Almost all of the feature references can be used on the left-hand side of the
ASSIGN statement to put a value into a measured or theoretical data member of a
feature. The only exception is the single I, J, K components of vectors. To assign to
vectors, the complete vector must be assigned at once using an expression that
evaluates to a point. Vector data is normalized as it is input into the feature’s vector data
members.
ASSIGN/CIRCLE1.I=2-illegal
ASSIGN/CIRCLE1.IJK=MPOINT(2,0,0)-legal(vector is normalized to
1,0,0)
For information on using variables within dimensions, see the "Dimensioning Variables"
topic in the "Using Legacy Dimensions" chapter.
Structures
You can use a variable type called structures to place extensions on a variable to
identify a sub-element of that variable. Consider this example:
ASSIGN/V1.HEIGHT=6
ASSIGN/V1.WIDTH=4.3
ASSIGN/V1.MODE="CIRCULAR"
ASSIGN/V1.POINT=MPOINT(100.3,37.5,63.1)
In this example:
• V1 is the structure.
• HEIGHT, WIDTH, MODE, and POINT are sub-elements of the structure.
23
Using Expressions and Variables
o Integer
o Double
o Point
o Feature Pointer
o Function
o Array
o Structure
For example, it is possible to have structure elements that are arrays and array
elements that are structures. This makes the following example expressions valid:
ASSIGN/CAR.LEFTSIDE.DOOR[2].QUADRANT[3].JOINT[5].HIT[4]=MP
OINT(558.89,910.12,42.45)
COMMENT/OPER,"Current Z Position:
"+CAR.LEFTSIDE.DOOR[2].QUADRANT[3].JOINT[5].HIT[4].Z
ASSIGN/CURRENTJOINT=LEFTSIDE.DOOR[2].QUADRANT[3].JOINT[5]
COMMENT/OPER,"Next Hit: "+CURRENTJOINT.HIT[4]
ASSIGN/V1.X="Some string"
ASSIGN/V1.Y=ARRAY(1,3,5,9,7)
ASSIGN/V1.Z=MPOINT(3,5,7)
24
Understanding Expression Components
ASSIGN/DYNAMICSTRUCT=FUNCTION((X,Y),X.Y)
C1=COMMENT/INPUT,Please enter in item
ASSIGN/TESTSTR=C1.INPUT
ASSIGN/FRONT=LEFT(TESTSTR,INDEX(TESTSTR,".")-1)
ASSIGN/BACK=MID(TESTSTR,INDEX(TESTSTR,"."))
ASSIGN/RESULT=DYNAMICSTRUCT(FRONT,BACK)
This portion of the example asks you to input a variable reference, splits the
reference at the first '.', and then assigns RESULT to be equal to that reference by using
the function DYNAMICSTRUCT.
So, if from you had typed V1.Y[4] for the C1.INPUT variable, RESULT would end up
with the value of 9 (the fourth element of the array assigned to V1.Y).
The learn time evaluation of expressions has been enhanced to accurately show all
elements of a structure or an array.
Pointers
Pointers are also known as "Feature Pointers ". See the Glossary term "Feature Pointers" for
more information.
Pointers provide a way to reference a feature via a variable or to pass objects using the
call sub command. Pointers are similar to indirection via string names. However, the
advantage of using pointers is with subroutines. Pointers, unlike strings, when passed in
as arguments of a subroutine, allow for direct modification of the object pointed to by the
subroutine. Pointers are not used in complex expressions. If it is used in a complex
expression, the pointer evaluates to zero.
25
Using Expressions and Variables
• ASSIGN/DIST=DOUBLE(V1.XYZ)
You can also put an expression between curly brackets in order to obtain a feature
pointer. Now the following examples are all legal ways to get the pointer to feature
CIR1:
• ASSIGN/FEATCOUNT=1
ASSIGN/V1={"CIR"+FEATCOUNT}
• ASSIGN/V2="CIR1"
ASSIGN/V3={V2}
ASSIGN/V4={C1.INPUT}
This takes the feature name of C1.INPUT and places it into variable, V4.
Subroutine Example:
CS1=CALLSUB/SUB.PRG,CHANGEX,{CIR1}
In the subroutine:
GEN1=GENERIC/FEATURE
SUBROUTINE/CHANGEX,ARG1={GEN1}
ARG1.X=5
26
Understanding Expression Components
END/SUBROUTINE
Arrays
Three types of arrays are available: Feature, hit, and variable.
Feature Arrays
When a feature is measured more than once during routine execution, a feature array is
automatically created. The number of elements in the feature array is equal to the
number of times the feature has been executed.
If a measured circle object were located in a while loop that executed five
times, then an array of five measured circles would exist. If the id of the measured circle
were "Circle1", then an array expression could be used to access individual instances of
the measured circle object. Square brackets are used to indicate the instance desired.
ASSIGN/V1=Circle1[3].X
V1 is assigned the measured X value of the third instance of Circle1.
27
Using Expressions and Variables
When a feature array exists for a given feature, but array notation is not used
in a reference to that feature, the most recent instance is used. From the above
example, the reference Circle1.X would be the same as Circle1[5].X, since the
fifth instance would be the most recent instance of the object.
ASSIGN/V1=1
While/V1<6
Comment/Rept,"Centroid of instance #"+V1+" of
Circle1: "+Circle1[V1].XYZ
ASSIGN/V1=V1+1
End/While
Arrays also exist on dimensions and alignments that have been executed multiple times
in a given execution run. Thus, Dim1[2].Nom and Align1[4].Origin would be
available given that the Dimension "Dim1" has executed at least twice and the
alignment "Align1" has executed at least four times.
If a feature array reference is out of bounds (for example, the user asks for
Circle1[2.5] or > Circle1["Hello, World"]) the upper or lower bound item is
returned. If Circle1 had 3 instances then Circle1[4] and above would return the
value for Circle1[3] and Circle[0] and below would return the value for
Circle1[1]. All expressions between square brackets are coerced to integer, thus 2.5
would become 2 and "Hello World" would become 0.
28
Understanding Expression Components
The array indices object allows you to specify upper and lower bounds for multiple array
dimensions.
• By setting the upper and lower bounds of the first dimension a two dimensional
array is created where the first dimension is bound and the second dimension is
unbound.
• By setting the upper and lower bounds of the first two dimensions of an array, a
three dimensional array is created. The last dimension is always unbound.
29
Using Expressions and Variables
Feature F1 is located inside a nested WHILE loop. The inner WHILE loop
executes five times and the outer WHILE loop executes three times. At completion of
execution, F1 has been executed 15 times and so 15 instances of F1 exist.
ARRAY_INDICES/1..5,..
ASSIGN/V1=1
WHILE/V1<=3
ASSIGN/V2=1
WHILE/V2<=5
F1=FEAT/POINT,RECT
THEO/V2,V1,0,0,0,1
ACTL/1,1,0,0,0,1
MEAS/POINT,1
HIT/BASIC,V2,V1,0,0,0,1,1,1,0
ENDMEAS/
ASSIGN/V2=V2+1
COMMENT/REPT,"Location of F1["+V2+","+V1+"] :"+F1[V2,V1].XYZ
END_WHILE/
ASSIGN/V1=V1+1
END_WHILE/
The array indices command has limited the first dimension of the feature array to be
between 1 and 5 inclusively. Thus on the inspection report, instead of appearing as
F1[1] – F1[15], the objects will appear as F1[1, 1] – F1[5, 3], more consistent with the
layout of the features. Notice that the comment also refers to the feature array using a
two dimensional array syntax.
1. Using the keyboard, type "Array" on an empty line in the Edit window.
2. Press the Tab key on your keyboard.
30
Understanding Expression Components
If the Display Brackets for Feature Arrays check box has been cleared, the
feature will not appear with the bracketed name. See "Display Brackets for Feature
Arrays" in the "Setting Your Preferences" chapter.
Hit Arrays
The hits of a given feature are available as an array and can be accessed via
expressions using array syntax of the form <FeatID>.Hit[<Array
Expression>].<Extension> or the form <FeatID>.RawHit[<Array
Expression>].<Extension>. Hit returns probe compensated data when probe
compensation is on. RawHit always return uncompensated data. Valid extensions are
X, Y, Z, I, J, K, TX, TY, TZ, TI, TJ, TK, XYZ, TXYZ, IJK, and TIJK
Circle1.Hit[1].XYZ
The measured centroid (probe compensated) of hit 1 of "Circle1".
Circle1.Hit[2].IJK
The measured vector of hit 2 of "Circle1"
Hit data is available for all objects that have hits, whether the actual hits are displayed in
the Edit window or not. Thus, hits can be obtained for scans and auto features.
The following topics describe some additional array functions that are useful for finding
the minimum or maximum points in a scan:
You can also assign a range of hits to an array by using this syntax:
<Feature Id>.<Hittype>[<Startnum>..<Endnum>].<Extension>
where
<Hittype> can be either the word "HIT" for compensated data or "RAWHIT" for
uncompensated data. If probe compensation if turned off, the returns values are
always uncompensated.
<Startnum> is an expression that identifies the first index value of the range of
hits.
31
Using Expressions and Variables
<Endnum> is an expression that identifies the second index value of the range of
hits.
Measured
Theoretical
For example:
ASSIGN/V1=SCAN1.HIT[1..10].X
V1 is assigned to an array of 10 values, which are the measured X values from
the first 10 hits of SCAN1.
ASSIGN/V2=SCAN1.HIT[1..SCAN1.NUMHITS].XYZ
V2 is assigned to an array of points from each of the centroids of the hits in the
scan.
Sorting Arrays
PC-DMIS allows you to sort arrays in either ascending or descending order. The
following two expressions take an array and return a sorted array:
32
Understanding Expression Components
For example:
ASSIGN/V1=ARRAY(5,8,3,9,2,6,1,7)
V1 is assigned the array of "5,8,3,9,2,6,1,7".
ASSIGN/V2=SORTUP(V1)
V2 will hold the array values sorted in ascending order: "1,2,3,5,6,7,8,9".
ASSIGN/V3=SORTDOWN(V1)
V3 will hold the array values sorted in descending order: "9,8,7,6,5,3,2,1".
You can input an array into a function and return the index number of the element that
has the greatest or the least value by using these functions:
To return the index value of the element with the greatest value, use:
MAXINDEX(<array>)
To return the index value of the element with the least value, use:
MININDEX(<array>)
For example,
ASSIGN/V1=ARRAY(5,8,3,9,2,6,1,7)
V1 is assigned the array of "5,8,3,9,2,6,1,7".
ASSIGN/V2=MAXINDEX(V1)
V2 will hold the array's index value of 4. The actual value of that array element is
9.
ASSIGN/V3=MININDEX(V1)
V3 will hold the array's index value of 7. The actual value of that array element is
1.
You can then use returned index values to get the actual array element value.
33
Using Expressions and Variables
You can input an array into a function, sort the array's values in ascending or
descending order, and then return the index values by using these functions:
To return the array's index positions in order of their values sorted from greatest to
least use:
MAXINDICES(<array>)
To return the array's index positions in order of their values sorted from least to
greatest use:
MININDICES(<array>)
For example:
ASSIGN/V1=ARRAY(4,8,2,9,5,7)
V1 is assigned the array of "4,8,2,9,5,7".
ASSIGN/V2=MAXINDICES(V1)
V2 will hold an array with these values: "4,2,6,5,1,3".
ASSIGN/V3=MININDICES(V1)
V3 will hold an array with these values: "3,1,5,6,2,4".
The main purpose of the hit array functions discussed above is to give you an easy way
to find the minimum and maximum points in a scan.
To dimension the point from SCAN1 that has the greatest measured X value, you could
use this expression:
ASSIGN/MAXPTINDEX=MAXINDEX(SCAN1.HIT[1..SCAN1.NUMHITS].X)
D1=LOCATION OF FEATURE SCAN1.HIT[MAXPTINDEX]
To find the three highest points in the Z axis of SCAN2, you could use this expression:
ASSIGN/MI=MAXINDICES(SCAN2.HIT[1..SCAN2.NUMHITS].Z)
ASSIGN/THREEPOINTS=ARRAY(SCAN2.HIT[MI[1]].XYZ,SCAN2.HIT[MI[2]].X
YZ,SCAN2.HIT[MI[3]].XYZ)
34
Understanding Expression Components
Variable Arrays
Variable arrays do not need to be declared. Variable arrays come into existence via the
assign statement when the expression on the right hand side of the assign statement
evaluates to an array or when the left hand side of the assign statement refers to an
element in a variable array.
ASSIGN/V1=Array(3,4,5,6,7)
Creates 5 element array and assigns it to V1.
ASSIGN/V2=V1[3]
Assigns V2 the value of the third element in array V1: 5.
ASSIGN/V1[4]=23
Assigns 4th element of array V1 to 23.
Arrays are created and allocated dynamically. Thus an array can be created by using an
array reference on the left hand side of an assign statement.
ASSIGN/V3[5]=8
Dynamically creates array with 5th element set equal to 8.
When referencing an array element that has never received a value, the array
expression will evaluate to 0.
ASSIGN/V3[5]=8
ASSIGN/V4=V3[5]
V4 is set equal to the value 8.
ASSIGN/V5=V3[6]
If the sixth element of V3 has never been set, V5 is set equal to 0.
Like other array types, expressions can be used within the square brackets.
ASSIGN/V3[5]=8
ASSIGN/V4=V3[2+3]
V4 is set equal to the value 8.
ASSIGN/V6=Array(Array(4,7,2),Array(9,2,6))
V6 is set to a 2 by 3 dimensional array where V6[1, 1] equals 4, V6[1, 2] equals 7,
V6[1, 3] equals 2, V6[2, 1] equals 9, V6[2,2] equals 2, and V6[2,3] equals 6.
35
Using Expressions and Variables
ASSIGN/V7=V6[2,1]
V7 is set to the value 9.
ASSIGN/V8[-3]=5
The –3rd index of array V8 is set to 5.
ASSIGN/V8="Hello"
The variable V8 is equal to the string "Hello"
ASSIGN/V8[2]=5
V8 is no longer of type string, but of type array, the second element of which has a
value of 5.
ASSIGN/V8=9
V8 is no longer an array, but an integer of value 9.
ASSIGN/V9=Array("Hello",3,2.9,{FEAT1})
Creates array V9 with four elements. The first element is a string, the second
element is an integer, the third element is a real number, and the fourth element is
a pointer to FEAT1.
ASSIGN/V10=ARRAY(3,1,5)
ASSIGN/V10[LEN(V1)+1]=7
The first statement creates an initial array V10 with three elements (3,1, and 5).
The second statement then grows the array in V10 by one element and gives the
final element a value of 7.
36
Understanding Expression Components
37
Using Expressions and Variables
() Parenthesis: ( <Expression> )
Gives evaluation to precedence to expression inside of parenthesis.
Precedence
Expressions are evaluated with the precedence shown below (listed from highest
precedence to lowest precedence).
Highest Precedence
• Operands
• (unary minus), !, (), functions (such as ABS, COS, STR, LEN, CROSS, and so
on.)
• ^
• *, /, %
• +, -
• ==, <>, <, <=, >, >=
• AND
• OR
Lowest Precedence
Functions
Functions are PC-DMIS specific expressions or user-defined expressions that usually
take parameters and then return results. The parameters are substituted into the
expression before the expression is evaluated.
Functions List
The following alphabetical list contains all the functions available to PC-DMIS's
expression language.
• ABS (mathematical)
38
Understanding Expression Components
• ACOS (mathematical)
• ANGLEBETWEEN (point)
• ARCSEGMENTENDINDEX (miscellaneous)
• ARCSEGMENTSTARTINDEX (miscellaneous)
• ARRAY (array)
• ASIN (mathematical)
• ATAN (mathematical)
• CHR (string)
• COS (mathematical)
• CROSS (point)
• DEG2RAD (mathematical)
• DELTA (point)
• DIST2D (pointer)
• DIST3D (pointer)
• DOT (point)
• ELEMENT (string)
• EOF (miscellaneous)
• EOL (miscellaneous)
• EQUAL (array)
• EQUAL (string)
• EXP (mathematical)
• FORMAT (string)
• FUNCTION (function)
• GETCOMMAND (pointer)
• GETPROGRAMINFO (string)
• GETROTABDATA (miscellaneous)
• GETSETTING (string)
• GETTEXT (string)
• GETTRACEVALUE (string)
• IF (miscellaneous)
• INDEX (string)
• ISIOCHANNELSET (miscellaneous)
• LEFT (string)
• LEN (array)
• LEN (pointer)
• LEN (string)
• LINESEGMENTENDINDEX (miscellaneous)
• LINESEGMENTSTARTINDEX (miscellaneous)
• LN (mathematical)
• LOG (mathematical)
39
Using Expressions and Variables
• LOWERCASE (string)
• MAX (array)
• MID (string)
• MIN (array)
• MPOINT (point)
• ORD (string)
• PCDMISAPPLICATIONPATH (string)
• PCDMISUSERHIDDENDATAPATH (string)
• PCDMISUSERVISIBLEDATAPATH (string)
• PCDMISSYSTEMHIDDENDATAPATH (string)
• PCDMISSYSTEMVISIBLEDATAPATH (string)
• PCDMISSYSTEMREPORTINGPATH (string)
• PROBEDATA (miscellaneous)
• QUALTOOLDATA (miscellaneous)
• RAD2DEG (mathematical)
• RIGHT (string)
• ROUND (mathematical)
• SETROTABDATA (miscellaneous)
• SIN (mathematical)
• SQRT (mathematical)
• SYSTEMDATE (string)
• SYSTEMTIME (string)
• SYSTIME (string)
• TAN (mathematical)
• TUTORELEMENT (miscellaneous)
• UNIT (point)
• UPPERCASE (string)
String Functions
The following functions are used with text strings.
CHR
This function returns a string, which consists of the character corresponding to the
ASCII decimal value.
40
Understanding Expression Components
ELAPSEDEXECUTIONTIME
This function returns the time that has elapsed since the measurement routine or
mini routine started to execute. The elapsed execution time is the time spent
during the DCC portion of the execution; it does not track time for pauses due to
attention required by the user. (These include things like execution pauses during
comment execution or PC-DMIS messages. Also, errors messages may stop the
execution altogether.) The time is returned in "hh:mm:ss" format.
You can record the elapsed execution time at any point in the measurement
routine or mini routine by assigning the function to a variable, such as:
ASSIGN/V1=ELAPSEDEXECUTIONTIME()
ELEMENT
This function returns the nth substring (element) from string2 using string1 as the
delimiting text that divides the elements in string2.
Suppose string2 is "6, 12, 8, 4, 5" and string1 is a comma character ",".
The five elements that can be individually retrieved with the element command are
"6", "12", "8", "4", and "5".
EQUAL
This function compares two strings (ignoring the case) to determine if they are
identical. It returns an integer set to 1 if the strings are the same, and 0 if they are
not.
FORMAT
This function takes two expressions and returns a formatted string similar to using
the sprintf function inside C++.
41
Using Expressions and Variables
The format specifier should have the same syntax as a format specifier used in
the sprintf function used in the C++ programming language.
A format specifier consists of optional and required fields and has the following
syntax:
Each field of the format specifier is either a single character or a number that
signifies a particular format option. The simplest format specifier uses only the
percent sign and a type character (for example, %d). If a percent sign is followed
by a character that has no meaning as a format field, the character is copied to
STDOUT. For example, to print a percent-sign character, use %%.
The optional flag, width, and precision fields, which appear before the type
character, control other aspects of the formatting. These are described below:
flags
These optional characters control output justification and the printing of signs,
blanks, decimal points, and octal or hexadecimal prefixes. More than one flag
can appear in a format specifier.
42
Understanding Expression Components
Meaning 2: When used with the e, E, or f type, the # flag forces the output
value to contain a decimal point in all cases.
Default 2: Decimal point appears only if digits follow it.
Meaning 3: When used with the g or G format, the # flag forces the output
value to contain a decimal point in all cases and prevents the truncation of
trailing zeros.
Default 3: Decimal point appears only if digits follow it. Trailing zeros are
truncated. This is ignored when used with d, i, or u.
width
This second optional field, or argument, controls the minimum number of
characters printed. It is a non-negative decimal integer.
precision
This third optional field, or argument, specifies the number of characters to be
printed, the number of decimal places, or the number of significant digits.
Unlike the width specification, the precision specification can cause either
truncation of the output value or rounding of a floating-point value. It is a non-
negative decimal integer preceded by a period (.).
43
Using Expressions and Variables
type
This required character determines whether the associated argument is an
integer, a double, or a point. The list of available types includes:
FORMAT Example
This example shows several statements using the FORMAT function inside a
measurement routine:
44
Understanding Expression Components
GETSETTING
This function allows you to return various settings of PC-DMIS based on the string
parameter inserted.
GETSETTING(<String>)
45
Using Expressions and Variables
If the value you use is a positive number, PC-DMIS pulls the string from its
resource.dll file. If you use a negative number, PC-DMIS pulls the string
from its strings.dll file (the strings table).
• "Extended Sheet Metal" – Returns a 1 if the Show Extended Sheet Metal
Options check box is selected inside the Setup Options dialog box, 0
otherwise.
• "LastHitMove(X)" – Returns the X value of the most recent HIT /BASIC or
MOVE/POINT command. PC-DMIS must be in DCC mode for this to work.
• "LastHitMove(Y)" – Returns the Y value of the most recent HIT/BASIC or
MOVE/POINT command. PC-DMIS must be in DCC mode for this
parameter to work.
• "LastHitMove(Z)" – Returns the Z value of the most recent HIT/BASIC or
MOVE/POINT command. PC-DMIS must be in DCC mode for this
parameter to work.
46
Understanding Expression Components
ASSIGN/WORKPLANE_ID=GETSETTING("Current Workplane") -
This gives the variable WORKPLANE_ID the string value of the current workplane
(ZPLUS, ZMINUS etc.).
GETTEXT
This function returns the current text from the specified data field:
GETTEXT(<String or Integer>,<Integer>,<Pointer>)
The first field can be either a string description of the data field, indicated by item
(A) in the image below or the data field number, indicated in item (C) in the image
below.
47
Using Expressions and Variables
Item (B) in the image below is not used in this function, but is sometimes
used in automation or in report expressions.
Sample Data Type Information Showing (A) Type Description, (B) Type String
Identifier, (C) Type Number, and (D) Type Index
The second field is the type index, indicated as (D) in the above image. This field
is usually zero unless you have more instances of the same type of field in the
same command, such as multiple DIRECTORY fields shown in the above image.
The correct value for this field can be obtained in the same manner as described
for the first field.
48
Understanding Expression Components
The third field is a command pointer. It points to the command containing the field
from which the text is being obtained. This field can be specified either by using
command pointer notation (i.e., {F15}) or by using the GETCOMMAND expression
as shown in this example.
GETPROGRAMINFO
This function has at most two strings as parameters. For most items, you only
need the first parameter. The string fields are not case sensitive.
First Field—String
49
Using Expressions and Variables
SEQNUM - Like STATSCOUNT, this string also returns the current stats
count number
ELAPSEDTIME - Returns the time that has passed since the beginning of
the execution
CADMODELNAME - Returns the full path to the file name of the CAD model
that you imported into the measurement routine.
CADMODELFILENAME - Returns the name of only the CAD model (not the
path) that you imported into the measurement routine.
TEMP - Returns the temperature for the optional second input string. See
"Second Field—Optional String" below.
50
Understanding Expression Components
The second field is an optional string input. It's only needed if TEMP is used in the
in the first input field. The possible strings below come from the Temperature
Compensation command. For more information, see "Compensating For
Temperature" in the "Setting Your Preferences" chapter.
Example
GETTRACEVALUE
51
Using Expressions and Variables
This function takes a single string parameter. It returns a value from a TRACEFIELD
command in the measurement routine.
<string> represents a case-sensitive string of the trace name whose value you want to
return.
If you have multiple trace fields with the same trace name, this function returns the
value for most recent trace field above this function. If a trace field doesn't contain a
value, this function returns a value of 0.
ASSIGN/V2=GETTRACEVALUE("Operator")
INDEX
This function returns the location of the second string within the first string. The
first letter of string is 1. A return value of zero indicates that the sub string is not
found in the string.
For an example of this function, see the "Sample Code for Read Line" topic in the
"Using File Input / Output" chapter.
LASTEXECUTIONTIME
This function returns the last execution time that PC-DMIS recorded and stored in
the <name of measurement routine>.MiniRoutines.xml file. The last execution time
appears in the Execution dialog box. The time is returned in "hh:mm:ss" format.
LEFT
The first expression (String) is coerced to type string. The second expression (n)
is coerced to type integer.
52
Understanding Expression Components
For an example of this function, see the "Sample Code for Read Line" topic in the
"Using File Input / Output" chapter.
LEN
LOWERCASE
This function returns a string that is the lowercase equivalent of the expression
string.
MID
This function returns a substring consisting of the characters of the string specified
in the first parameter starting at the position specified by the second parameter for
a length of n characters as specified by the third parameter. If the third parameter
is not supplied, the rest of the string is returned.
For an example of this function, see the "Sample Code for Read Line" topic in the
"Using File Input / Output" chapter.
ORD
This function returns the integer ASCII value of first letter of the string (0-255).
PCDMISAPPLICATIONPATH
This function returns the string value containing the full path to the application
directory where PC-DMIS is installed. This directory contains the main executable
and other necessary program files to run PC-DMIS.
PCDMISUSERHIDDENDATAPATH
53
Using Expressions and Variables
This function returns the string value containing the full path of the hidden user
data directory used by PC-DMIS. See "Understanding File Locations" for the files
contained in this directory.
PCDMISUSERVISIBLEDATAPATH
This function returns the string value containing the full path of the visible user
data directory used by PC-DMIS. See "Understanding File Locations" for the files
contained in this directory.
PCDMISSYSTEMHIDDENDATAPATH
This function returns the string value containing the full path of the hidden system
data directory used by PC-DMIS. See "Understanding File Locations" for the files
contained in this directory.
PCDMISSYSTEMVISIBLEDATAPATH
This function returns the string value containing the full path of the visible system
data directory used by PC-DMIS. See "Understanding File Locations" for the files
contained in this directory.
PCDMISSYSTEMREPORTINGPATH
This function returns the string value containing the full path to the Reporting
directory used by PC-DMIS. This directory contains the report and label templates
used by the Report window.
RIGHT
SYSTEMDATE
54
Understanding Expression Components
This function returns the date-formatted string with the current date details filled in.
For example, the command SYSTEMDATE("MM’/’dd’/’yy") returns the string
"02/12/14" if the current date is February 12, 2014.
Use the following string elements to create the date string. Elements must be in
the same case as shown below (MM instead of mm). Non-date characters (such
as spaces) that appear between date format string elements appear in the output
string in the same location as the input string. Characters in the input string
delimited by single quotes appear in the same location in the output string without
the single quotes.
dd - Day of the month as digits. Leading zero used for single-digit dates.
SYSTEMTIME
This function returns the time-formatted string with the current time details filled in.
For example, the command SYSTEMTIME("hh:mm:ss tt") returns the time in a
formatted string, like this "11:29:40 PM".
Use the following string elements to create the time string. Elements must be in
the same case as shown below (tt instead of TT). Non-time characters (such as
spaces) appearing between time format string elements will appear in the output
string in the same location as the input string. Characters in the input string
55
Using Expressions and Variables
delimited by single quotes will appear in the same location in the output string
without the single quotes.
SYSTIME
This function returns a string with the current system time. This function differs
from the SYSTEMTIME function described above. It automatically returns the day,
date, and time, followed by the year.
The returned string, showing the current system time, is adjusted to local
time zone settings.
UPPERCASE
56
Understanding Expression Components
Mathematical Functions
ABS
EXP
Exponential: EXP(<Double>)
Returns the exponential of the expression.
LOG
LN
ROUND
Rounding: ROUND(<Double>)
Returns the input rounded to the nearest integer.
SQRT
Trigonometry Functions
By default, each of the trigonometry functions takes and returns radians. If you want
values in degrees, use the RAD2DEG function described below.
ACOS
ArcCosine: ACOS(<Double>)
Returns the arc cosine of the expression. For example, ACOS(5.0) returns 0. In general,
ACOS(<expression>) returns the arc cosine of the value of the expression.
57
Using Expressions and Variables
ASIN
ArcSine: ASIN(<Double>)
Returns the arc sine of the input.
ATAN
ArcTangent: ATAN(<Double>)
Returns the arc tangent of the input.
COS
Cosine: COS(<Double>)
Returns the cosine of the input.
DEG2RAD
RAD2DEG
SIN
Sine: SIN(<Double> )
Returns the sine of the input.
TAN
Tangent: TAN(<Double>)
Returns the tangent of the input.
Functions where the input is out of range (like ACOS, ASIN, LOG, LN, SQRT
and so on, that would cause the computer to crash) return 0.
58
Understanding Expression Components
Point Functions
ANGLEBETWEEN
Returns the angle between the two vectors in degrees. The two parameters must be
expressions that evaluate to a vector type. To get the vector from a feature, for
example, you will need to use the feature ID followed by the .IJK extension. See the
example below:
F1 =GENERIC/POINT,DEPENDENT,CARTESIAN,$
NOM/XYZ,<3,3,3>,$
MEAS/XYZ,<3,3,3>,$
NOM/IJK,<1,0,0>,$
MEAS/IJK,<1,0,0>
F2 =GENERIC/POINT,DEPENDENT,CARTESIAN,$
NOM/XYZ,<10,10,10>,$
MEAS/XYZ,<10,10,10>,$
NOM/IJK,<0,0,1>,$
MEAS/IJK,<0,0,1>
ASSIGN/V1=F1.IJK
ASSIGN/V2=F2.IJK
ASSIGN/V3=ANGLEBETWEEN(V1,V2)
COMMENT/OPER,NO,FULL SCREEN=NO,AUTO-CONTINUE=NO,
"The angle between "+V1+" and "+V2+" is: "+V3
CROSS
Return value is of type point and is the cross product of first and second expressions .
DELTA
The function takes the first expression (point) and calculates a new point in the direction
of the second expression (vector) at an offset of the third expression. For example,
DELTA(MPOINT(0,0,0),MPOINT(1,0,0),10) returns the point 10,0,0.
59
Using Expressions and Variables
DOT
UNIT
Returns the point divided by its length. For example, UNIT(MPOINT(0,0,0)) returns
the point 0,0,1.
MPOINT
ASSIGN/V1=MPOINT(2.5,3.6,4)
Pointer Functions
DIST2D
This calculates the distance between the first two arguments in the command (Feat1
and Feat2), perpendicular to the third argument (Feat3).
60
Understanding Expression Components
• If the third argument is a plane, the distance between the first two
arguments is calculated perpendicular to the plane.
• If the third argument is a line or cylinder, the distance between the first two
arguments is calculated perpendicular to the third argument in the active
workplane.
For example, if you have the XY plane as your third argument, it will have a Z+ vector
(0,0,1) and the distance reported will only be in the Z axis.
Example
ASSIGN/V3=DIST2D({CIR1},{CIR2},{PLN1})
COMMENT/OPER,NO,FULL SCREEN=NO,AUTO-CONTINUE=NO,
V3
DIST3D
Example
ASSIGN/V3=DIST3D({CIR1},{CIR2})
COMMENT/OPER,NO,FULL SCREEN=NO,AUTO-CONTINUE=NO,
V3
GETCOMMAND
The first parameter is the command info field. It specifies the command type for
which to search. The following can be passed in:
61
Using Expressions and Variables
If the unique id of the command is passed in, no other arguments are necessary.
To obtain the command description string, the command type number, and the
command’s unique number identifier:
Value Description
This value signifies the search should start at the current command and
UP
proceed upwards
This value signifies the search should start at the current command and
DOWN
proceed downwards.
This value signifies that the search should begin at the beginning of the
TOP
measurement routine in a downwards direction
This value signifies that the search should begin with the last object in
BOTTOM
the measurement routine in an upwards direction
The third parameter indicates which instance of the command should be found if
multiple instances of the same command are in the measurement routine.
62
Understanding Expression Components
ASSIGN/V1=GETCOMMAND("Statistics","TOP",2)
The GETCOMMAND function can be used to supply the third parameter to the
GETTEXT string function. See "String Functions" for information on GETTEXT.
LEN
Returns the number of times a pointer has been in a loop. For example, if feature CIR1
is in a loop that iterates 10 times, you can store how many times CIR1 has been
measured in a variable, by using an ASSIGN statement like this:
ASSIGN/V1=LEN({CIR1})
Array Functions
ARRAY
AVERAGE
EQUAL
63
Using Expressions and Variables
LEN
MAX
MIN
SUM
Miscellaneous Functions
ARCSEGMENTENDINDEX
This function returns the index number of the ending point of a specified arc segment
from a scan: ARCSEGMENTENDINDEX(<ID>, <index>,<tol1>,<tol2>)
<ID> - The first parameter is a string value of the ID of the scan on which this function
pulls out the index number of the ending point for the arc. This parameter can either be
the ID in quotation marks or any expression that when coerced to type string ends up
being the ID of a scan.
<index> - The second parameter is the index number for the arc from which you want to
get the ending point number. This is a one-based value. For example, the arc index
number would be 3 if you want the ending point number for the third arc in the scan.
<tol1> - The third parameter is the general feature tolerance. It is a maximum form error
used to break up the scan into lines and arcs.
64
Understanding Expression Components
<tol2> - The fourth parameter is the refine tolerance. Generally, this tighter tolerance is
used to drop points from either end of the feature until the form error of the segment is
within this tolerance.
Once you have the Start and End indices for an arc, you can use these points inside a
constructed feature to construct a separate arc feature. For a similar example, see
"Example of a Line Feature Created from a Scan Segment".
ARCSEGMENTSTARTINDEX
This function returns the index number of the starting point of a specified arc segment
from a scan: ARCSEGMENTSTARTINDEX(<ID>, <index>,<tol1>,<tol2>).
<ID> - The first parameter is a string value of the ID of the scan on which this function
pulls out the index number of the start point for the arc. This parameter can either be the
ID in quotation marks or any expression that when coerced to type string ends up being
the ID of a scan.
<index> - The second parameter is the index number for the arc from which you want to
get the start point number. This is a one-based value. For example, the arc index
number would be 3 if you want the start point number for the third arc in the scan.
<tol1> - The third parameter is the general feature tolerance. It is a maximum form error
used to break up the scan into lines and arcs.
<tol2> - The fourth parameter is the refine tolerance. Generally, this tighter tolerance is
used to drop points from either end of the feature until the form error of the segment is
within this tolerance.
There are two additional parameters, which control whether an identified arc segment in
a scan is acceptable. These can only be changed with the PC-DMIS Settings Editor.
Any arc segment with a radius less than the value for the
MinimumArcSegmentRadiusInMM registry entry is rejected. The default value for this
parameter is 2 mm. Similarly, any arc segment with a radius greater than the value for
the MaximumArcSegmentRadiusInMM registry entry is rejected. The default value for
this parameter is 2000 mm (it should not be necessary to change this value).
Once you have the Start and End indices for an arc, you can use these points inside a
constructed feature to construct a separate arc feature. For a similar example, see
"Example of a Line Feature Created from a Scan Segment".
For information on these functions, see "Checking for the End of a File or the End of a
Line" in the "Using File Input / Output" chapter.
65
Using Expressions and Variables
FUNCTION
Creates a function that takes the number of parameters indicated by the parameter list
and substitutes those parameters into the expression.
• The first item when using the FUNCTION keyword is the parameter list.
• This list consists of parameter names separated by commas.
• The parameter list is also surrounded by parenthesis.
• The second item is the expression.
• The expression contains the parameter names where the parameters
should be substituted when the function is called.
GETROTABDATA
This function returns the center, angular position, and vector values for the specified
rotary table.
GETROTABDATA(<PARAMETER>[,<TABLE>])
The data that the function returns matches the data in the Rotary Table Setup dialog
box (Edit | Preferences | Rotary Table Setup). For more information about this dialog
box, see "Defining the Rotary Table".
CENTER
Examples:
66
Understanding Expression Components
ANGULAR POSITION
Examples:
VECTOR
Examples:
67
Using Expressions and Variables
PC-DMIS has two internal table definitions to accommodate dual-table and stacked-
table configurations. For a single-table configuration, the second table definition is not
actually used. Because it does exist internally, an error will not occur if you specify table
V in a single-table configuration; however, this is not recommended. The values that the
function returns are not generally useful because the table does not actually exist.
IF
If expression1 evaluates to true (non-zero), then this function returns the value of
expression2; otherwise, this function returns the value of expression3.
ISIOCHANNELSET
This expression takes two parameters. The first parameter indicates which I/O channel
will be checked (the range of numbers that is available is based on the machine being
used). The second parameter determines whether the software will query the Arm1 or
Arm2 machine. If the second parameter is set to 1 (one), it will query the Arm2
controller. If the second parameter is not present (or is set to zero), then the IO Channel
will query the Arm1 controller. The Arm1 controller is your only option if you are not in
multiple arm mode.
68
Understanding Expression Components
If an invalid probe data type, tip id, probe file name, or channel number
is supplied, the expression evaluates to 0.
Example:
LINESEGMENTENDINDEX
This function returns the index number of the ending point of a specified line segment
from a scan: LINESEGMENTENDINDEX(<ID>, <index>,<tol1>,<tol2>).
<ID> - The first parameter is a string value of the ID of the scan on which this function
pulls out the index number of the ending point for the line segment. This parameter can
either be the ID in quotation marks or any expression that when coerced to type string
ends up being the ID of a scan.
<index> - The second parameter is the index number for the line segment from which
you want to get the end point number. This is a one-based value. For example, the line
segment index number would be 3 if you want the end point number for the third line in
the scan.
<tol1> - The third parameter is the general feature tolerance. It is a maximum form error
used to break up the scan into lines and arcs.
<tol2> - The fourth parameter is the refine tolerance. Generally, this tighter tolerance is
used to drop points from either end of the feature until the form error of the segment is
within this tolerance.
Once you have the Start and End indices for a line segment, you can use these points
inside a constructed feature to construct a separate line feature. For an example, see
"Example of a Line Feature Created from a Scan Segment".
LINESEGMENTSTARTINDEX
This returns the index number of the starting point of a specified line segment from a
scan: LINESEGMENTSTARTINDEX(<ID>, <index>,<tol1>,<tol2>).
69
Using Expressions and Variables
<ID> - The first parameter is a string value of the ID of the scan on which this function
pulls out the index number of the start point for the line segment. This can either be the
ID in quotation marks or any expression that when coerced to type string ends up being
the ID of a scan.
<index> - The second parameter is the index number for the line segment from which
you want to get the start point number. This is a one-based value. For example, the line
segment index number would be 3 if you want the start point number for the third line in
the scan.
<tol1> - The third parameter is the general feature tolerance. It is a maximum form error
used to break up the scan into lines and arcs.
<tol2> - The fourth parameter is the refine tolerance. Generally, this tighter tolerance is
used to drop points from either end of the feature until the form error of the segment is
within this tolerance.
Once you have the Start and End indices for a line segment, you can use these points
inside a constructed feature to construct a separate line feature. See "Example of a Line
Feature Created from a Scan Segment" for an example.
PROBEDATA
This function takes up to three optional parameters. You only need to provide commas
between the parameters if you use more than one parameter. You do not need to use
commas between empty parameters. For example, to obtain the current probe's
diameter you would use ASSIGN/V1=PROBEDATA("DIAM").
70
Understanding Expression Components
"Diam" or "Diameter" - Measured tip diameter. The first four letters are
required "Diam", but could include more letters up to the full name of
"Diameter". Returns type double.
"Thick" or "Thickness" - Measured tip thickness. The first five letters are
required "Thick", but could include more letters up to the full name of
"Thickness". Returns type double.
"Date" - Date the tip was last qualified. Returns type string.
"Time" - Time the tip was last qualified. Returns type string.
"C" - The C angle of a CW43 light probe head. Returns type integer.
OPTTIPID - This optional parameter specifies the tip to be used when obtaining the
probe data specified in the first expression. If not supplied, the current tip is used. This
parameter should be type string.
Examples:
V1 is set to
ASSIGN/V1=PROBEDATA() current tip id (i.e.
"T1A0B0")
71
Using Expressions and Variables
V2 is set to the
ASSIGN/V2=PROBEDATA("TOFFSET","T1A45B0") theoretical probe
offset for the tip
T1A45B0
V3 is set to a
string
representing the
ASSIGN/V3=PROBEDATA("Date","T1A90B90","MYPROB") date tip
T1A90B90of the
probe file
MYPROB was
last qualified.
SETROTABDATA
This function sets the center or vector to the new input value:
SETROTABDATA(<PARAMETER>,<NewValue>[,<TABLE>])
This function works in the following configurations:
CENTER
• "CENTER",<NewValue> - Sets the rotary table's XYZ center to the new value.
• "CENTER",<NewValue>,"V" - Sets the XYZ center for rotary table V in a dual-
table or stacked-table configuration to the new value.
• "CENTER",<NewValue>,"W" - Sets the XYZ center for rotary table W in a dual-
table or stacked-table configuration to the new value.
Examples:
V1 is a return code
ASSIGN/V1=SETROTABDATA("CENTER",NewValue) (1=success,
0=failure).
V1 is a return code
ASSIGN/V1=SETROTABDATA("CENTER",NewValue,"V") (1=success,
0=failure).
72
Understanding Expression Components
V1 is a return code
ASSIGN/V1=SETROTABDATA("CENTER",NewValue,"W") (1=success,
0=failure).
VECTOR
• "VECTOR",<NewValue> - Sets the rotary table's IJK vector to the new value.
• "VECTOR",<NewValue>,"V" - Sets the IJK vector for rotary table V in a dual-
table or stacked-table configuration to the new value.
• "VECTOR",<NewValue>,"W" - Sets the IJK vector for rotary table W a dual-table
or stacked-table configuration to the new value.
Examples:
V2 is a return code
ASSIGN/V2=SETROTABDATA("VECTOR",NewValue) (1=success,
0=failure).
V2 is a return code
ASSIGN/V2=SETROTABDATA("VECTOR",NewValue,"V") (1=success,
0=failure).
V2 is a return code
ASSIGN/V2=SETROTABDATA("VECTOR",NewValue,"W") (1=success,
0=failure).
73
Using Expressions and Variables
PC-DMIS has two internal table definitions to accommodate dual-table and stacked-
table configurations. For a single-table configuration, the second table definition is not
actually used. Because it does exist internally, an error will not occur if you specify table
V in a single-table configuration; however, this is not recommended. The values that the
function sets are not generally useful because the table does not actually exist.
TUTORELEMENT
This function takes one parameter, either a number or a string (a string would be the ID
of a feature).
TUTORELEMENT(<PARAMETER>)
This function works with the variable type, Structures. For explanations of structure and
sub-elements, see "Structures".
Examples:
Sub-Element Description
74
Understanding Expression Components
QUALTOOLDATA
This function returns data about the current or specified calibration tool. It has this
syntax:
This function takes up to three parameters. It needs at least one parameter to return
any data:
The first parameter, <TOOLINFO>, is a string that specifies the type of information
to return about the calibration tool. If you don't pass this parameter, this function
returns the name of the current or specified calibration tool.
75
Using Expressions and Variables
The second parameter, <TOOLID>, is a string that specifies the name for the
calibration tool for which you would like to receive information. If you don't pass this
parameter, PC-DMIS assumes you want information from the current calibration tool.
The string is not case sensitive.
The third parameter, <FACENUMBER>, is a parameter that you only need when you
work with a polyhedral calibration tool and only when the first parameter is
"POLYXYZ", "POLYIJK", or "POLYDIAM". This is an integer value that specifies the
face of the polyhedral tool to use in order to obtain data.
Examples:
76
Understanding Expression Components
POLYDIAM","POLYTEST",3) POLYTEST.
Function Examples
Below are some different examples of functions that may help you in creating and using
your own functions:
ASSIGN/MYFUNC=FUNCTION((X,Y,Z),X*3+Y*2+Z)
Creates a user-defined function and assigns it to the variable MYFUNC. The function
takes three parameters, X,Y, and Z.
X is multiplied by 3.
Y is multiplied by 2.
The total of X + Y + Z is what gets returned when values are passed into the function,
as shown here:
ASSIGN/V1=MYFUNC(7,2,5)
This assigns V1 the value 30 by evaluating the parameters passed into the function
MYFUNC(7,2,5). 7 is the parameter and is substituted where X occurs in the expression
portion of the function definition. Thus, X*3 becomes 7*3, or 21.
77
Using Expressions and Variables
The values are then all added together (21 + 4 + 5) and passed to V1.
Functions can be passed as variables. The following example builds on the Generic
Function Example above:
ASSIGN/NEWFUNC=MYFUNC
Sets the variable NEWFUNC to have the same function that MYFUNC has.
ASSIGN/V3=NEWFUNC(12,2,3)
Assigns V3 to have the value 43 from the evaluated expressions within the function (36
+ 4 + 3).
ASSIGN/ADDANDDOUBLE=FUNCTION((A,B),2*(A+B))
Creates a function and assigns it to the function ADDANDDOUBLE. The function takes
two parameters, adds them together and then multiplies the result by 2.
ASSIGN/V2=ADDANDDOUBLE(4,5)
Assigns V2 the value 18. The parameters 4 and 5 are substituted into the expression
portion of the function, thus becoming 2*(4+5).
ASSIGN/COMPOSE=FUNCTION((F,G),FUNCTION((X),G(F(X))))
Assigns COMPOSE to be a function that takes two functions as parameters and creates
a new function using the two functions.
ASSIGN/ADD2=FUNCTION((X),X+2)
Assigns ADD2 to be a function that adds two to the parameter passed in.
ASSIGN/ADD3=FUNCTION((X),X+3)
Assigns ADD3 to be a function that adds three to the parameter passed in.
ASSIGN/ADD5=COMPOSE(ADD2,ADD3)
Assigns ADD5 to be a function composed of the functions ADD2 and ADD3.
78
Understanding Expression Components
ASSIGN/V5=ADD5(3)
Assigns V5 to have the value V8.
ASSIGN/ANARRAY=ARRAY(3,FACTORIAL,"Hello World",ADD5)
Assigns ANARRAY to be an array of 4 elements : a number (3), a function
(FACTORIAL), a string, ("Hello World"), and a function (Add5).
ASSIGN/V6=ANARRAY[2](4)
The second element of ANARRAY is the function FACTORIAL. The parameter 4 is
passed in to this function and the result of 24 is assigned to V6.
ASSIGN/V7=ANARRAY[2](ANARRAY[4](ANARRAY[1]))
From the inside out: The first element of ANARRAY (3) is passed to the function of the
fourth array element (Add5). The result, 8, is passed to the function of the second array
element (FACTORIAL) and assigned to V7. V7 receives a value of 40320.
Functions can be defined recursively, meaning they can be defined to call themselves.
ASSIGN/FACTORIAL=FUNCTION((X),IF(X<=1,1,X*FACTORIAL(X-1))
Creates a function called factorial that takes one parameter. If the parameter is less
than or equal to 1 it evaluates to 1, otherwise it evaluates to X multiplied by the
FACTORIAL of X-1.
ASSIGN/V4=FACTORIAL(5)
Assigns V4 the value of 120 (5*4*3*2*1).
Suppose your measurement routine has a scan feature named SCN1 that looks like
this:
79
Using Expressions and Variables
SCN1=FEAT/SCAN,LINEAROPEN,SHOW HITS=NO,SHOWALLPARAMS=YES
EXEC MODE=RELEARN, NOMS MODE=FIND NOMS,CLEARPLANE=NO,SINGLE
POINT=NO,THICKNESS=0
FINDNOMS=5,SELECTEDONLY=NO,USEBESTFIT=NO,PROBECOMP=YES,AVOID
ANCE MOVE=NO,DISTANCE=0,CAD Compensation=NO
DIR1=VARIABLE,
HITTYPE=VECTOR
INITVEC=0,-1,0
DIRVEC=1,0,0
CUTVEC=0,0,1
ENDVEC=0,-1,0
PLANEVEC=-1,0,0
POINT1=100,0,-5
POINT2=70,0,-5
MEAS/SCAN
BASICSCAN/LINE,SHOW HITS=NO,SHOWALLPARAMS=YES
<100,0,-5>,<70,0,-5>,CutVec=0,0,1,DirVec=1,0,0
InitVec=0,-1,0,EndVec=0,-1,0,THICKNESS=0
FILTER/NULLFILTER,
EXEC MODE=RELEARN
BOUNDARY/PLANE,<70,0,-5>,PlaneVec=-1,0,0,Crossings=2
HITTYPE/VECTOR
NOMS MODE=FINDNOMS,5
ENDSCAN
ENDMEAS/
To create a line from this scan you will need to use the LINESEGMENTSTARTINDEX
and LINESEGMENTENDINDEX functions to pull out the data, like this:
ASSIGN/LINESTARTINDEX=LINESEGMENTSTARTINDEX("SCN1",1,0.4,0.1
)
ASSIGN/LINEENDINDEX=LINESEGMENTENDINDEX("SCN1",1,0.4, 0.1)
This tells PC-DMIS to go to the scan named "SCN1", and from its first line segment pull
out the starting and ending index values that fall within the defined tolerances. It then
assigns those index values to variables named LINESTARTINDEX and
LINEENDINDEX.
80
Understanding Expression Components
Once you have the start and ending index values for the line segment assigned to
variables, you can use those variables within a constructed line, like this:
LIN4=FEAT/LINE,RECT,UNBND
THEO/100.225,0,-5.011,1,0,0
ACTL/100.225,-0.005,-5.011,1,-0.0000388,0
CONSTR/LINE,BF,2D,SCN1.HIT[LINESTARTINDEX..LINEENDINDEX],,
OUTLIER_REMOVAL/OFF,3
FILTER/OFF,WAVELENGTH=0
Notice that in the highlighted code from the line feature above, PC-DMIS uses the
starting and ending numbers you pulled out of the scan to create the feature:
SCN1.HIT[LINESTARTINDEX..LINEENDINDEX]
Operand Coercion
Operands can be coerced to other types using any of the coercion operators:
Integer Coercion
INT(<Expression>) - Coerces value of expression to type integer.
INT(4) Evaluates to 4
INT(4.5) Evaluates to 4
INT("2") Evaluates to 2
INT("2.2") Evaluates 2
INT("The 3 Blind
Evaluates to 0
Mice")
81
Using Expressions and Variables
Double Coercion
DOUBLE(<Expression>) - Coerces value of expression to type double
Evaluates to
DOUBLE(MPOINT(3,4,5))
7.0711
String Coercion
STR(<Expression>) - Coerces value of expression to type string
82
Understanding Expression Components
Point Coercion
MPOINT(<Expression1>, <Expression2>, <Expression3>) - Coerces values of
expressions to type point after coercing each expression to type double.
"CIR" + 1
Evaluates to "CIR1"
"2" + 2
Evaluates to 4
LINE1.XYZ > 2
Evaluates to 1 if the distance of the centroid of LINE1 from the origin is greater than 2
83
Using Expressions and Variables
LINE1.XYZ = LINE2.XYZ
Evaluates to 1 if the centroids of LINE1 and LINE2 are the same (no coercion occurs in
this case)
DOUBLE(LINE1.XYZ) = DOUBLE(LINE2.XYZ)
Evaluates to 1 if the centroids are the same distance from the origin
11% 3.1
Evaluates to 2 (% is the modulo operator designed to work with integers. It returns the
remainder from discrete division. 11%3 = 2.)
CIRCLE1.HIT [3.2].X
Evaluates to measured X value of third hit of Circle1. The argument 3.2 is automatically
coerced to an integer with a value of 3.
ID Expressions
Many of the PC-DMIS commands use feature IDs as parameters. For example,
constructed features use IDs to indicate which features are to be used as inputs for the
constructed feature. ID expressions allow the user to refer to a specific instance of a
feature, a group of similarly named features, an instance of a feature inside a call to a
subroutine, or a feature in an external measurement routine.
Feature Array ID
Use a feature array id to refer to a specific instance of a feature or to a range of feature
instances. For example, if the feature "Circle1" were located in a while loop that looped
five times, then five instances of the circle would exist upon exiting the loop. To refer to
an individual instance of the five instances of "Circle1", use feature array syntax as
described under "Feature Arrays:" where "Circle1[1]" would refer to the first instance,
"Circle1[2]" would refer to the second instance, etc.
To refer to a range of instances use the .. notation. "Circle1[1..3]" refers to the 1st
through 3rd instances of Circle1. "Circle1[3..5] refers to the 3rd through 5th instances of
Circle1. "Circle1[1..5]" would refer to the 1st through 5th instances of Circle1. When a
range of feature is referred to, the set is treated and behaves as a constructed set.
ID Wild Cards
Use ID Wild Cards to refer to a set of similarly named features. The two wild card
characters are "*" and "?". (See "Selecting Features Using Meta-character matching" in
the "Editing the CAD Display" chapter for additional information.)
84
Understanding Expression Components
The asterisk ‘*’ character refers to 0 or more instances of any character. To refer to the
set of all feature that start with the letters "CIR", use the expression ID "CIR*". This
syntax creates a set of features that include all features with Ids that start with "CIR",
such as "CIRCLE1", "CIRCLE2", "CIR3", or "CIR".
If CIR3 has several executions only the most recent measurement is used. To
get the different instances of the executions, the following expression could be used:
CIR?[1..3]
The question mark ‘?’ character refers to a single instance of any character.
The ID expression "MY???1" would create a set of features that are six
characters long, begin with "MY" and end with "1", such as "MYCIR1", "MYCON1",
"MYLIN1", or "MYFT21".
For example, if a feature named "F1" were located in an external subroutine that was
called from a Call Sub command with the id "CS1", then the ID expression "CS1:F1"
could be used to refer to that feature.
85
Using Expressions and Variables
This example merely illustrates the use of the syntax CS1.F1 and is not
intended to use.
Routine 1: PLUS1.PRG
SUBROUTINE/PLUS1, A1 = 0, A2 = 0, A3 = 0
F1 =FEAT/POINT,RECT
THEO /A1+1,A2+1,A3+1,0,0,1
ACTL/3,1,1,0,0,1
MEAS/POINT,1
HIT /BASIC,A1+1,A2+1,A3+1,0,0,1,0,0,0
ENDMEAS/
ENDSUB/
Routine 2: TEST.PRG
Basic scripts create and delete objects dynamically. Use the syntax "<Basic Script
ID>:<Feat ID>" to refer to a feature created by a basic script. For example, if a basic
script with ID "BS1" creates a feature with ID "F2", use the ID expression "BS1:F2" to
refer to that feature.
You can use the attach command to attach external routines to PC-DMIS. To refer to
features in the attached routine use the following syntax: "<Attach Routine ID>:<Feat
ID>". To refer to feature "F3" in the attached measurement routine with ID "GEAR1",
use the expression, "GEAR1:F3". (See "Attaching an External Measurement Routine" in
the "Adding External Elements" chapter for more information.)
ID Expression Combinations
You can use array ID Expressions, Wild Card ID Expressions, and external subroutine,
basic script, and external measurement routine ID Expressions in combination. For
example, to refer to the third instance of all features that start with the letters "CIR" in an
86
Accessing a Report's Object Properties
external measurement routine attached with the ID "BOLTPAT", use the ID expression
"BOLTPAT:CIR*[3]".
Also, you can use ID Expressions in regular expressions. Thus, the measured centroid
of the above set of features could be assigned to variable with the following expression:
ASSIGN/V1=BOLTPAT:CIR*[3].XYZ
Also, ID Expressions can be used in regular expressions. Thus, the measured centroid
of the above set of features could be assigned to variable with the following expression:
ASSIGN/V1=BOLTPAT:CIR*[3].XYZ
Each object consists of "properties" that define how it appears and what information it
holds. Some of these properties are common to all other objects, some are common to
only related objects, and others are unique to that specific object.
The PC-DMIS Expression Language can query the currently loaded report and store
property values of a particular object in a variable. It can obtain values of type String,
Integer, and Real by using this syntax:
Report is a reference to the currently loaded report. <Object Name> is the object's
unique name. <Property Name> is a valid property name for that object.
87
Using Expressions and Variables
Example
Suppose that your report template has a text object called "Text1" that you
want to use in the final report to display the operator's name. The actual string of
characters that represent the operator's name will be stored in the Text property of the
object. By default, the text property (displayed text) initially has the value of "Text1" (see
the figure below). Because this is a user-assigned property, this will change when you
type in the name during execution.
Properties dialog box that shows a selected object and the property to query
To use the Expression Language code to query this Text object's "Text" property and
obtain the keyed-in data, you would use the following command:
ASSIGN/V1=Report.Text1.Text
In this code:
"Report" tells the code to look at the report loaded in the Report window.
"Text" tells it to look for the "Text" property within that object. The value of the
"Text" property then gets passed into the V1 variable, which you could then
further manipulate or display using the PC-DMIS Expression Language.
Finding Properties
To find the properties that are associated with a particular object, access the Report
template in the Report template editor (File | Reporting | Edit | Report Template),
select the object, and then right-click on the object to display its property sheet.
88
Accessing a Report's Object Properties
The property sheet contains two columns. The left column displays the property name.
The right column displays the current value. Be sure to use the exact property name in
your expression code.
89
Using Expressions and Variables
When you query property values, you may find that some properties return a
seemingly useless numerical value. Generally, this happens when the property has a
set list of available options. PC-DMIS returns an internal value for the selected property
that does not relate to the displayed property.
For example, the Text object has an Orientation property with these values:
• 0 - Horizontal
• 1 - Vertical up
• 2 - Vertical down
However, if you obtain the value using PC-DMIS expression language, the software will
instead return the following:
• 0 (for Horizontal)
• 900 (for Vertical up)
• -900 (for Vertical down)
It may require some trial and error to determine what returned values correspond with
the value displayed on the property sheet.
When you construct a scan minimum circle feature, the circle ultimately uses a vector
(termed the down vector) to contact the scan line. It only contacts the line in two places
called contact points (CONTACTPOINT1 and CONTACTPOINT2). PC-DMIS can then
use these points to determine the angles from the down vector to these contact points
(CONTACTANGLE1 and CONTACTANGLE2). For example, consider this diagram:
90
Accessing Information from a Constructed Scan Minimum Circle
C - The contact point to the left of the Down Vector. It is termed CONTACTPOINT1.
D - The contact point to the right of the Down Vector. It is termed CONTACTPOINT2.
The expressions detailed below will only function with this type of constructed circle
feature. You can also use CONTACTPOINT2 in the syntax below to return the
equivalent information using the second contact point instead.
ASSIGN/V1=CIR1.CONTACTPOINT1.XYZ
Returns the XYZ point information for the circle's first contact point with the line,
CONTACTPOINT1.
ASSIGN/V1=CIR1.CONTACTPOINT1.X
Returns the X information for CONTACTPOINT1.
91
Using Expressions and Variables
ASSIGN/V1=CIR1.CONTACTPOINT1.Y
Returns the Y information for CONTACTPOINT1.
ASSIGN/V1=CIR1.CONTACTPOINT1.Z
Returns the Z information for CONTACTPOINT1.
ASSIGN/V1=CIR1.CONTACTPOINT1.IJK
Returns the IJK vector from CONTACTPOINT1 to the circle's centroid.
ASSIGN/V1=CIR1.CONTACTPOINT1.I
Returns the I value from the above CONTACTPOINT1 IJK vector.
ASSIGN/V1=CIR1.CONTACTPOINT1.J
Returns the J value from the above CONTACTPOINT1 IJK vector.
ASSIGN/V1=CIR1.CONTACTPOINT1.K
Returns the K value from the above CONTACTPOINT1 IJK vector.
ASSIGN/V1=CIR1.CONTACTANGLE1
Returns the angle from the Down Vector to CONTACTPOINT1.
ASSIGN/V1=CIR1.CONTACTANGLE2
Returns the angle from the Down Vector to CONTACTPOINT2.
ASSIGN/V1=CIR1.CONTACTANGLE
Returns the sum of the absolute values of CONTACTANGLE1 and CONTACTANGLE2.
It should be no greater than 180 degrees.
92