Reference: Macro Functions

The following functions are available for use when recording SmartCAM Macros. The Function column displays the function name, as well as the data type of the return value and parameters. See the key for what the various data types are.

The function parameter(s) are often labeled as specific information types; such as an element number or a variable name. In most cases, an Expression can be used instead of the specific value. As long as the expression resolves into the correct data type and range. For example, an element number is an integer between 1 and TOTEL() (total number of elements in data base). So, any expression used must also resolve into an integer value in the valid range of element numbers.

Math Functions

A description of the available math functions, for use in macros, is contained in the Automation/Customization - Macro Development Fundamentals - Fundamentals: Math topic.

Jump to specific section:

Macro Branching/Looping - Element Properties - Geometric Properties - Element Attributes - File Handling - Profile Properties - Exist Functions - Array Functions - String Functions - System Filenames/Paths - Status - Plane Orientation - Utility Functions - Date and Time

Macro Branching, Looping, And Control Statements

Function Description
IF, ELSE, ELSEIF, ENDIF Conditional branching statements, which allow the program to run code only if a certain condition or set of conditions are met. Statement starts with an IF statement, which opens the block, the IF is followed by the condition to be met enclosed in Parens. If the condition is met, all code between the opening IF statement and the closing ENDIF statement is executed.

INTEGER:#A = 1
INTEGER:#B=0

//	Set #B to 1 if #A > 0
IF (#A > 0)
	#B = 1
ENDIF

The IF block can be expanded to include an ELSE block. This block is run if the original test condition is not met.

INTEGER:#A = 0

//	Display Message about whether #A is equal to 0
IF (#A = 0)
	PAUSE[TX="#A Is Equal To Zero"]   
ELSE
	PAUSE[TX="#A Is Not Equal To Zero"]  
ENDIF

The ELSEIF statements allow you test for multiple conditions.

INTEGER:#A=1

//	#A can be set to 1 or 2
IF (#A = 1)
	PAUSE[TX="#A is 1"]  
ELSEIF (#A = 2)
	PAUSE[TX="#A is 2"]  
ELSE
	PAUSE[TX="#A is not correctly set"]  
ENDIF

For a more comprehensive explanation see Conditional Branching.

WHILE, ENDW The WHILE block is for conditional looping. Meaning, running the same block of code at least once but usually multiple times. The block starts with the opening WHILE statement, followed by the test condition; while the test condition is TRUE the block of code will continue to run. Once the code reaches the end of the block, as noted by the closing ENDW command, it will jump back to the top and check the test condition again. If TRUE, it will run the block of statement again. If the condition is no longer true, it jumps down to the ENDW statement and starts on the very next line.

// Draw 50 points in a line, increment in X by 0.01 
INTEGER:#COUNTER=0

WHILE(#COUNTER < 50)
	POINT[XE=(#COUNTER * 0.01), YE=0.0]
	//	Increment # of Points Created Counter
	#COUNTER = #COUNTER + 1
ENDW
						

For a more comprehensive explanation see Conditional Looping.

GOTO, @LABEL The GOTO command is used for unconditional branching. When a GOTO statement is run, it immediately tells SmartCAM to find the named @LABEL and begin running the very next macro statement after it.

INTEGER:#A=1

//	IF #A = 1 jump to Section1
IF (#A = 1)
	GOTO @ONE  
ENDIF
... more commands
// Section One 
@ONE  
//	commands for Section One

For a more comprehensive explanation see Unconditional Branching.

HALT HALT, when encountered, immediately stops the macro execution. It is generally used during macro development, to quickly stop the running macro in order to verify information.

IF (#SERIOUS_ERR = 1)
	HALT
ENDIF

INCLUDE S INCLUDE is used to include one macro file into another. For example, one macro file could include all the variable declarations and could be included in another macro; which uses the variables. Or, perhaps if there is a block of macro code used regularly, you could store it in its own .MCL file and include that MCL where you need the macro code inserted.

The include statement is followed by a quoted literal string which contains the path and filename of the file to include.

INCLUDE "C:\\MACROS\\VARDEFS.MCL"

For a more comprehensive explanation see Including Variable Declarations.

Properties of an Element

Function Description
D=CLR(elmt) Clearance value
I=CCNT(elmt) Returns the number of elements in a container element. Specified element must be a container.
I=DIR(elmt) Direction of an arc, helix, ellipse, or circular hole pattern.
0 = CW
1 = CCW
-1 = Not an arc element or hole pattern
I=EL(S) Given the string element name, returns the database index (element number). If matching name not found, returns 0.
S=EL_NAME(elmt) Returns the name of the element, if there is one, as a string. If the provided element number does not have a name, nothing is returned.
I=HIDDEN(elmt) Is the element hidden?
Values: 0 = Not Hidden, 1 = Hidden
D=INC(elmt) For circular hole patterns, returns the increment angle between holes.
I=IS_LEADIN(elmt) Does the element have a Lead-In attribute?
Values: 0 = False, 1 = True
I=IS_LEADOUT(elmt) Does the element have a Lead-Out attribute?
Values: 0 = False, 1 = True
I=IS_SELECTED(elmt) Is the element part of the active selected group?
Values: 0 = False (not selected), 1 = True (selected)
I=IS_SOLID(elmt) Is the element part of of a solid model? Checks to see if selected surface is part of a solid model or is an unattached surface.
Values: 0 = Not a Member of a Solid Model, 1 = Member of a Solid Model, -1 = Element is not a surface
I=JTOOL(elmt) Tool number (-1 when a layer is assigned)
I=LAY(elmt) Layer number (-1 when a step is assigned)
D=LVL(elmt) Level value
I=MASKED(elmt) Is the element masked?
Values: 0 = Not Masked, 1 = Masked
I=OFS(elmt) Offset setting
-1 = Left
1 = Right
0 = None
I=PECK(elmt) Peck cycle
0 = Off
1 = On
I=PLN(elmt) Workplane index number
0 = XY plane
I=PTCNT(elmt) Returns the number of controls points in a spline or polyline. Returns the number of holes in a hole pattern.
D=PTOP(elmt) Profile top value. For holes or hole patterns, returns the Z-level.
I=STEP(elmt) Access to step number (-1 when layer is assigned)
formerly TOOL(elmt)
I=SUB(elmt) Returns the SUB index value, starting at 0. If element is not a SUB, returns -1.
S=TPLN(elmt) Tool plane name assignment (string)
I=TYP(elmt) Element type:
Point1Line2Arc3
USR4Thread5Ellipse7
Helix9Polyline10Cubic Spline12
Sub Call14Groove15Text16
Poly5x18STL Facet21Hole Pattern22
Region23Hole Feature25Markup Note26
Surface50Hole54Container /
Process
58
I=TYPS(elmt) When the element number of a surface is provided, it returns the simplified surface type. Surface type:
Invalid (not a surface)-1Plane1
Cone2Cylinder3
Torus4Sphere5
Spline6
S=ULABEL(elmt) Returns the "Label Text" string from a user command; data is returned as string. If there is no label, nothing is returned.
S=UTEXT(elmt) Returns the "text" string from a user command, SmartCAM TEXT element, and Markup Note, as a string. When used on non-text elements (such as lines, arcs, points, etc), returns an empty string. If there is no text associated with the user command or TEXT element, returns an empty string.
I=VIS(elmt) Visibility status
0 = Hidden
1 = Shown
S=WKPLN(elmt) Workplane name assignment (string)

Geometric Properties for Elements

Function Description
D=ANG(elmt) Angle value of line, swept value of arc. Returns total (swept) angle for circular hole pattern. Returns text element (dimension) rotation.

If element is a cone surface, will return the cone angle relative to its axis.

D=BANG(elmt) For circular hole patterns, returns the Hole Axis value (b-axis angle) for the hole pattern.
D=CEX(elmt)
D=CEY(elmt)
D=CEZ(elmt)
Center point

If the provided element number is for a surface, will return the top center coordinate position for cones, cylinders, toruses, and spheres.

D=CBX(elmt)
D=CBY(elmt)
D=CBZ(elmt)
Center bottom point of conic surface or helix. Returns specific coordinate for bottom of center axis point for given element.

If the provided element number is a surface, it will return the bottom center coordinate position for cones, cylinders, toruses, and spheres.

D=CPX(elmt, pt)
D=CPY(elmt, pt)
D=CPZ(elmt, pt)
Control point for polylines or splines. Pt is the control point number and starts with 1. For hole patterns, returns the hole position ordinates for each hole. Holes are numbered starting at 1.
D=EANG(elmt) End angle. Returns end angle of circular hole patterns and helices.
D=ENX(elmt)
D=ENY(elmt)
D=ENZ(elmt)
End point. For hole pattens, returns the ordinates for the last (end) hole in the pattern.

If the provided element is a surface, will return the maximum position for that surface. For example, if there was a Cylinder centered at XYZ=0 and had a radius of 1 and a height of 1; then ENX would return 1, ENY=1, and ENZ=1.

D=ERAD(elmt) End radius of arc or helix.
D=ETAN(elmt) Angle (degrees) of curve tangent at end point of curve, in the workplane of the curve. Supports: lines, arcs and helices.
D=LEN(elmt) Length value. When used on a hole or hole pattern, returns the hole depth.
D=LENE(elmt) Path length of element

You cannot use the measure functions LENE() and LENP() on a helix. If you use these in a macro to measure a helix, SmartCAM will display an error message.

Returns the height of a text element (dimension).

D=LENP(elmt) Path length of profile

You cannot use the measure functions LENE() and LENP() on a helix. If you use these in a macro to measure a helix, SmartCAM will display an error message.
D=MDX(elmt)
D=MDY(elmt)
D=MDZ(elmt)
Mid-point of the element.

Returns the mid-point ordinate for lines, arcs, helixes, points, user commands, markup note leaders, and grooves.

D=RAD(elmt) Radius value. For circular hole patterns, returns the radius of the pattern.

If element is a surface will return the primary radius for cones, cylinders, toruses, and spheres. Otherwise returns -1.

D=RAD2(elmt) Secondary radius value. For surface types cone, cylinder, and torus it returns the secondary radius value, otherwise it returns -1.

Note that for Cylinders the primary and secondary radius values are the same.

D=STAN(elmt) Angle (degrees) of curve tangent at start point of curve, in the workplane of the curve. Supports: lines, arcs and helices.
D=STANG(elmt) Start angle. Returns start angle for circular hole patterns and helices.
D=STX(elmt)
D=STY(elmt)
D=STZ(elmt)
Start point. For hole patterns, returns the ordinates for the first (start) hole in the pattern.

If the provided element is a surface, will return the minimum position for that surface. For example, if there was a Cylinder centered at XYZ=0 and had a radius of 1, the STX would return -1, STY=-1, and STZ=0.

Element Attributes

SmartCAM elements can have attribute data associated with them. Attribute data is assigned to a given element, using a given name (the attribute name). The data is not visible in SmartCAM, but can be queried in macros or code generator template files. Once queried the data can be acted upon.

The attribute data can be string, decimal, or integer values. Each attribute is a pair - the attribute name and the attribute data. Attribute names are not case sensitive, so "ATTRIB" and "attrib" are the same. An attribute name can consist of any combination of human-readable characters, there is no restriction on the length of an attribute name, but longer names leave more room for typos and other errors. Attributes can be assigned to any SmartCAM entity; anything you can find in the List View can have a user attribute assigned to it.

As a hypothetical example, suppose a user wrote a macro that added blends onto all profiles in the active group. When creating the arcs to blend the profiles, the macro could assign attribute data to the newly added arc elements. The user could have another custom macro that can modify the blends in some fashion, the macro would check each arc element found to see if a given attribute exists, if it does, it knows this particular arc element was created by the previous macro and can be modified.

There are two types of attributes: user and system. User attributes can be created, modified, and removed by users. System attributes are created by SmartCAM and users cannot modify or remove this data.

See the Element Attributes topic, in the Code Generation section. This lists the System attributes that are currently exposed and available for use.

Function Description
I=DELATTRIB(elmt, S) Used to delete user attributes (not SmartCAM created and maintained system attributes).

The first parameter is the element number to modify, the second parameter is a string containing the name of the user attribute to remove from the element.

Function returns an integer: 0 if attribute not found, or 1 is attribute found and removed.

D=DGET(elmt, S, D) Returns decimal user attribute data from a given element. The first parameter is the element to check. The second parameter is a string that contains the name of the attribute to check for. The final parameter is a decimal value to return, if the attribute cannot be found.
D=DSET(elmt, S, D) Assigns a decimal user attribute to a given element. The first parameter is the element to add (or update). The second parameter is a string that contains the name of the attribute to add. The final parameter is a decimal to assign to the attribute.

If the element attribute is new, DSET returns the value that was assigned to the element - the third parameter. If the attribute already exists, and is being updated, DSET returns the previous attribute value.

D=DSYS(elmt, S, D) Returns a decimal system attribute from a given element. The first parameter is the element to check. The second parameter is a string that contains the name of the attribute to check for. The final parameter is a decimal to return, if the attribute cannot be found.
I=IGET(elmt, S, I) Returns integer user attribute data from a given element. The first parameter is the element to check. The second parameter is a string that contains the name of the attribute to check for. The final parameter is an integer value to return, if the attribute cannot be found.
I=ISET(elmt, S, I) Assigns an user integer attribute to a given element. The first parameter is the element to add (or update). The second parameter is a string that contains the name of the attribute to add. The final parameter is an integer to assign to the attribute.

If the element attribute is new, ISET returns the value that was assigned to the element - the third parameter. If the attribute already exists, and is being updated, ISET returns the previous attribute value.

I=ISYS(elmt, S, I) Returns an integer system attribute from a given element. The first parameter is the element to check. The second parameter is a string that contains the name of the attribute to check for. The final parameter is an integer to return, if the attribute cannot be found.
S=SGET(elmt, S, S) Returns string user attribute data from a given element. The first parameter is the element to check. The second parameter is a string that contains the name of the attribute to check for. The final parameter is a string value to return, if the attribute cannot be found.
S=SSET(elmt, S, S) Assigns a string user attribute to a given element. The first parameter is the element to add (or update). The second parameter is a string that contains the name of the attribute to add. The final parameter is a string to assign to the attribute.

If the element attribute is new, SSET returns the value that was assigned to the element - the third parameter. If the attribute already exists, and is being updated, SSET returns the previous attribute value.

S=SSYS(elmt, S, S) Returns a string system attribute from a given element. The first parameter is the element to check. The second parameter is a string that contains the name of the attribute to check for. The final parameter is a string to return, if the attribute cannot be found.

File Handling

These commands are used when working with external text files. These are used in combination with the following macro functions: F_OPEN[], F_CLOSE[], F_WRITE[], F_WRITE[], F_READ[] and F_DELETE[].

For examples of using the SmartCAM macro file handling functions, see the Text (ACSII) Files section of the Macro Recipes topic.

Function Description
I=F_EOF(path) Reports whether you have reached the end of the file, that you are reading.
Values: 0 = Not End of File, 1 = End of File

You provide the path and filename as the argument to this function. The filename must have already been opened, using the F_OPEN[] macro command.

I=F_ERROR() Reports whether is an error accessing a file. Returns a numeric code which describes the error type.

Return codes are:

  • 0 = Successful operation (F_READ, F_OPEN, F_WRITE, F_CLOSE)
  • 1 = File already open (F_OPEN)
  • 2 = File not found (F_OPEN)
  • 3 = Path not found (F_OPEN)
  • 4 = File is Read/Only - no write or append (F_OPEN)
  • 5 = File not open (F_READ)
  • 6 = File not open for read (F_READ)
  • 7 = End of file reached (F_READ)
  • 8 = File not open for write (F_WRITE)
  • 9 = Too many files already open (F_OPEN)
  • 10 = Bad or missing mode; use A W R (F_WRITE)
  • 11 = Expected variable for formatter missing (F_WRITE, F_READ)
  • 12 = Bad character encountered in variable list (F_WRITE, F_READ)
  • 13 = Variable is not of format type (F_WRITE, F_READ)
  • 14 = Bad formatter (F_WRITE, F_READ)
S=F_ERRSTR() Returns the error description, as a text string, for file errors. Related to F_ERROR().
I=F_EXIST(path) Reports whether a file exists or not.
Values: 0 = File does not Exist, 1 = File Exists

Provide the path and filename, of the file to check, as the argument for this function.

I=F_LINE(path) Returns the line number for the last line read by F_READ[].

Properties for Profiles

Supported profiles can be built from lines, arcs, and polylines.

Function Description
D=AREA(elmt) Calculates the area of a closed profile. The elmt parameter is an element in the profile. Returns the area of the profile. The area is returned as a negative number if the winding direction of the profile is clockwise, and a positive area value is the winding direction is counter-clockwise.

If element number is a surface element, will return the calculated area for that surface.

I=IS_CLOSED(elmt) Reports whether a profile is closed or open. The elmt is a element in the profile.
Values: 0 = Not Closed, 1 = Closed
I=WINDING_DIR(elmt)
Winding direction of a profile. The elmt parameter is a element in the profile.
Values: -1 = CW, 0 = Undetermined (mixed), 1 = CCW

Exist Functions

Function Description
I[]=ALL_LAYERS() Returns an integer array of all the layers defined in the current process model. The layers do not need to be associated with any geometry, but if not assigned to geometry, the layer needs a description; otherwise, this function will not return its number. The array results are sorted into ascending numerical order - same order as displayed in the Layers List View.
I[]=ALL_STEPS() Returns an integer array of all the Steps defined in the current process model, where the value returned is the Step Number. The Steps do not need to be used, they just need to be defined. The array results are returned in the order they would display in the Planner and List View.
I[]=ALL_TOOLS() Returns an integer array of all the Tools defined in the current process model, where the value returned is the Tool Number. The Tools do not need to be used, they just need to be defined. The array results are returned in the order they would display in the Planner and List View. This function is for non-Turning applications: Milling, Fabrication, and EDM.
I[]=ALL_TUR_TOOLS(Turret #) Returns an integer array of all the Tools, on the selected Turret, defined in the current process model, where the value returned is the Tool Number. The Tools do not need to be used, they just need to be defined. The array results are returned in the order they would display in the List View. This function is for Turning applications.
I=GRP_EXIST(Grp Name) Checks to see whether the provided Named Group name exists.
Values: 0 = Does Not Exist, 1 = Exists
I=IS_UNKNOWN_D(Variable) Checks to see whether the provided decimal Variable has been assigned a value. When a variable is created, it is assigned a value of UNKNOWN until an actual value is assigned.
Values: 0 = Any other value, 1 = Is UNKNOWN

You directly pass in the Variable as the argument:
DECIMAL:#A
INTEGER:#RETURN
#RETURN=IS_UNKNOWN_D(#A)

I=IS_UNKNOWN_I(Variable) Checks to see whether the provided integer Variable has been assigned a value. When a variable is created, it is assigned a value of UNKNOWN until an actual value is assigned.
Values: 0 = Any other value, 1 = Is UNKNOWN

You directly pass in the Variable as the argument:
INTEGER:#A
INTEGER:#RETURN
#RETURN=IS_UNKNOWN_I(#A)

I=LAYER_EXIST(laynum) Checks to see whether a Layer officially exists and is persistent. For a layer to exist it must either be used to create geometry or it must have a description.
Values: 0 = Does Not Exist, 1 = Exists
I=LAYER_USED(laynum) Checks to see whether a Layer has been used to create geometry.
Values: 0 = Not Used, 1 = Used
I=STEP_EXIST(stpnum) Checks to see whether a Step exists.
Values: 0 = Not Used, 1 = Used
I=STEP_USED(stpnum) Checks to see whether a Step has been used to create geometry.
Values: 0 = Not Used, 1 = Used
I=TOOL_EXIST(toolnum) Checks to see whether a Tool exists. Non-turning applications only.
Values: 0 = Not Used, 1 = Used
I=TUR_TOOL_EXISTS(turret, toolnum) Checks to see whether a Tool exists. Used in Turning applications only.
Values: 0 = Not Used, 1 = Used
I=TOOL_USED(toolnum) Checks to see whether a Tool has been used to create geometry. Non-turning applications only.
Values: 0 = Not Used, 1 = Used
I=TUR_TOOL_USED(turret, toolnum) Checks to see whether a Tool has been used to create geometry. Used in Turning applications only.
Values: 0 = Not Used, 1 = Used.
I=VAR_EXIST(varname) Checks to see whether a variable exists. A variable exists once you assign data to it, for default variables, or once you define the variable type (i.e., "DECIMAL:#VAR").
Values: 0 = Does Not Exist, 1 = Exists

The parameter is expecting a STRING containing the name of the variable, not the variable itself.

INTEGER:#iVar

IF(VAR_EXIST("iVar")=1)
VAR_REMOVE[VN="iVar"]
ENDIF

The parameter, as shown, is using a literal string for the variable name. It can also use a string variable.

I=VAR_DEFAULT(varname) Checks to see whether a variable is set to the Default value. The default value is the value assigned to the variable when it is created. A variable set to the default value has been created, but has likely not yet been used. The default value depends upon the variable type, they are:
INTEGER = 0
DECIMAL = 1000000.0
STRING = "" (empty string)
Values: 0 - Different From Default, 1 = Same As Default

The parameter is a string representing the variable name, not the variable itself. This can be a literal string or a string variable. See VAR_EXIST() for an example.

I=WKPLN_EXIST(wkpln name) Checks to see whether a Workplane exists, using the workplane name as the function parameter. A workplane exists once it has been defined.
Values: 0 = Does Not Exist, 1 = Exists
I=WKPLN_USED(wkpln name) Checks to see whether a Workplane has been used, using the workplane name as the function parameter. A workplane is used when geometry references it or is created on it.
Values: 0 = Not Used, 1 = Used

Array Functions

Function Description
ARRAY[]=ALLOCATE(I, [S|D|I]) Allocates memory for a STRING, INTEGER, or DECIMAL array variable. First parameter is an integer that specifies the number of array slots to create. The second parameter is the default value for the array slots. The default value must match the type of array - for example, if allocating memory for an integer array, do not use a string default.
INTEGER:#INTARRAY[] = ALLOCATE(5, 0) // allocates 5 array slots, default value is 0
I=REALLOCATE(ARRAY[], I, [S|D|I]) Reallocates memory for an array, can be used to grow or shrink the size of an array. The first parameter is the array variable to reallocate, second is the new size of the array, and the third is the default value for new elements. Function returns an integer containing the new size of the array.
#NEWSIZE=REALLOCATE(#INTARRAY[], 10, 0) // resizes #INTARRAY[] to 10 elements
I=SIZE(ARRAY[]) Returns the size of the array - the number of array elements. Single parameter is the array variable. Returns an integer with the number of elements in the array.

String Manipulation Functions

The Function column displays the function name, as well as the data type of the return value and parameters. See the key for what the various data types are.

Function Description
D=ATOD(S) Returns the decimal value represented by the valid decimal representation at the beginning of the string expression (S). If (S) does not begin with a valid decimal representation it returns 0.
I=ATOI(S) Returns the integer value represented by the valid integer representation at the beginning of the string expression (S). If (S) does not begin with a valid integer representation it returns 0.
S=CAT(S1,S2) Returns the concatenation of the string expression (S2) onto the end of the string expression (S1).

String concatenation can also be handled with the "+" operator. Example:

STRING:#S1
#S1="One and " + "two" // #S1 now contains "One and two"
I=FIND(S1,S2,I)
I=FIND(S1,S2)
Returns the position of string expression (S2) in string expression (S1), optionally ignoring the first (I) characters before attempting to find a match.

This function searches STRING1 for the first instance of STRING2, then returns an INTEGER showing the position within STRING1 where STRING2 begins; its offset in the string. The search will start at the beginning of STRING1, unless you use the optional numeric START_POSITION parameter.

Example:

STRING:#S1  // The string that will be searched
STRING:#S2  // The string to look for
INTEGER:#POSITION  // The index into #S1 where #S2 is found

#S1="SmartCAMcnc"
#S2="CAM"
#POSITION=FIND(#S1, #S2) // #POSITION is equal to 6

#POSITION is set to 6, because the string "CAM" begins at the 6th position in STRING1.

The optional START_POSITION parameter is used to set where FIND will begin to search. Example:

STRING:#S1  // The string that will be searched
STRING:#S2  // The string to look for
INTEGER:#POSITION

#S1="SmartCAMcnc's SmartCAM application"
#S1="SmartCAM"	// You want to find the position of SmartCAM, not SmartCAMcnc
#POSITION=FIND(#S1,#S2,11) // #POSITION is equal to 15

#POSITION is set to 15, because "SmartCAM" begins at position 15 in STRING1. Notice that since you use the START_POSITION parameter to change the location where FIND begins to search, that "SmartCAM" in "SmartCAMcnc" was not matched.

If STRING2 is not found in STRING1, then FIND will return 0.

S=FMT(N,S) Returns the string created by formatting a numeric expression (N), based on the format (S).

Refer to the Numeric Formats topic, in the Code Generation section of Learning SmartCAM, for detailed information on numeric formatting.

Example:

STRING:#S1
DECIMAL:#D1
#D1=1.10012
#S1=FMT(#D1,"D3.4")

#S1 would contain the string "1.1001".

When used with the concatenation operator "+", FMT() should be used instead of the older STRTMP() functionality. Example:

STRING:#S1
DECIMAL:#D1
#D1=1.1

// Older STRTMP method. Should not be used any longer
#S1=STRTMP("D1 is %#D1") // S1 is now "D1 is 1.1"

// Newer FMT method
#S1="D1 is " + FMT(#D1,"D3.4")
S=GET_NAME(path) Returns the filename when it matches the form filename.ext from the end of a full path.
S=GET_PATH(path) Returns the path segment of a full path and filename.
I=ISALNUM(S) Checks the character, passed in as a string to see if it is an alphanumeric character; a letter or a digit [A-Za-z0-9]. If a letter, the case of the letter does not matter.

Returns a zero if the character is not either a letter or number. It returns a value greater than zero if the character is a letter or number. It will return a -1 if you pass an empty string variable to the function.

If the string you pass to the function contains more than 1 character, only the 1st character will be checked. Use the MID(), LEFT(), RIGHT() functions to check other letters in a larger string.

//  See if 2nd character is a letter
STRING:#STR="Ab"
IF (ISALNUM(MID(#STR,2,1)) > 0)
	PAUSE[TX="2nd Character is a Letter or Number"] // This is what will be displayed in this example
ELSE 
	PAUSE[TX="2nd Character is not a Letter or Number"] 
ENDIF
I=ISALPHA(S) Checks the character, passed in as a string, to see if it is an alphabetic character; a case-insensitive letter between A to Z.

Returns a zero if the character is not a letter. It returns a value greater than zero if the character is a letter. It will return a -1 if you pass an empty string variable to the function.

If the string you pass to the function contains more than 1 character, only the 1st character will be checked. Use the MID(), LEFT(), RIGHT() functions to check other letters in a larger string.

//  See if character is a letter
IF (ISALPHA("a") > 0)
	PAUSE[TX="Character is a Letter"] // This is what will be displayed in this example
ELSE 
	PAUSE[TX="Character is not a Letter"] 
ENDIF
I=ISDIGIT(S) Checks the character, passed in as a string, to see if it is a digit; a numeric character [0 to 9].

Returns a zero if the character is not a digit. It returns a value greater than zero if the character is a digit. It will return a -1 if you pass an empty string variable to the function.

If the string you pass to the function contains more than 1 character, only the 1st character will be checked. Use the MID(), LEFT(), RIGHT() functions to check other letters in a larger string.

//  See if character is a digit
IF (ISDIGIT("0") > 0)
	PAUSE[TX="Character is a Digit"] // This is what will be displayed in this example
ELSE 
	PAUSE[TX="Character is not a Digit"] 
ENDIF
I=ISLOWER(S) Checks the character, passed in as a string, to see if it is a lowercase letter.

Returns a zero if the character is either an uppercase letter or not a letter. It returns a value greater than zero if the character is a lowercase letter. It will return a -1 if you pass an empty string variable to the function.

If the string you pass to the function contains more than 1 character, only the 1st character will be checked. Use the MID(), LEFT(), RIGHT() functions to check other letters in a larger string.

//  See if 2nd character is a lowercase letter
STRING:#STR="Ab"
IF (ISLOWER(MID(#STR,2,1)) > 0)
	PAUSE[TX="2nd Character is a Lowercase Letter"] // This is what will be displayed in this example
ELSE 
	PAUSE[TX="2nd Character is not a Lowercase Letter"] 
ENDIF
I=ISPUNCT(S) Checks the character, passed in as a string, to see if it is a punctuation symbol; these symbols include periods, commas, exclamation points, pound signs, quotes, and so forth.

Returns a zero if the character is not punctuation. It returns a value greater than zero if the character is a punctuation symbol. It will return a -1 if you pass an empty string variable to the function.

If the string you pass to the function contains more than 1 character, only the 1st character will be checked. Use the MID(), LEFT(), RIGHT() functions to check other letters in a larger string.

//  See if 2nd character is a punctuation symbol
STRING:#STR="0.1"
IF (ISPUNCT(MID(#STR,2,1)) > 0)
	PAUSE[TX="2nd Character is Punctuation"] // This is what will be displayed in this example
ELSE 
	PAUSE[TX="2nd Character is not Punctuation"] 
ENDIF
I=ISSPACE(S) Checks the character, passed in as a string, to see if it is a space character. Whitespace characters include the spaces and tabs.

Returns a zero if the character is not a space character. It returns a value greater than zero if the character is a whitespace character. It will return a -1 if you pass an empty string variable to the function.

If the string you pass to the function contains more than 1 character, only the 1st character will be checked. Use the MID(), LEFT(), RIGHT() functions to check other letters in a larger string.

//  See if TAB is a whitespace character
IF (ISSPACE("\t") > 0)
	PAUSE[TX="2nd Character is Whitespace"] // This is what will be displayed in this example
ELSE 
	PAUSE[TX="2nd Character is not Whitespace"] 
ENDIF
I=ISUPPER(S) Checks the character, passed in as a string, to see if it is an uppercase letter.

Returns a zero if the character is either a lowercase letter or not a letter. It returns a value greater than zero if the character is an uppercase letter. It will return a -1 if you pass an empty string variable to the function.

If the string you pass to the function contains more than 1 character, only the 1st character will be checked. Use the MID(), LEFT(), RIGHT() functions to check other letters in a larger string.

//  See if 2nd character is an uppercase letter
STRING:#STR="aB"
IF (ISUPPER(MID(#STR,2,1)) > 0)
	PAUSE[TX="2nd Character is an Uppercase Letter"] // This is what will be displayed in this example
ELSE 
	PAUSE[TX="2nd Character is not an Uppercase Letter"] 
ENDIF
S=ITOA(I) Returns a string representation of the integer expression (I).
S=LEFT(S,I) Returns (I) number of characters from the left side of the string expression (S). Example:
STRING:#S1
STRING:#S2
#S1="SmartCAMcnc"
#S2=LEFT(#S1,5) // #S2 is equal to "Smart"
S=LTRIM(S) Returns a string with all white-space characters trimmed from the left side of the string expression (S). White-Space characters are spaces, tabs, and line-feeds. For example:
STRING:#S1  // Original string
STRING:#S2  // returned string

#S1="   Left Trim   "
#S2=LTRIM(#S1) // S2 now contains "Left Trim   "

Notice the white-space characters on the right side of the string still exist.

S=MID(S,I1,I2) Returns the next (I2) number of characters from the string expression (S) starting from the (I1) position in the string expression. Example:
STRING:#S1
STRING:#S2
#S1="SmartCAMcnc"
#S2=MID(#S1,6,3) // #S2 is equal to "CAM"
S=REPLACE(S,S1,S2) Finds string expression (S1) in string expression (S) and replaces it with string expression (S2).
I=RFIND(S1,S2,I)
I=RFIND(S1,S2)
Returns the position of string expression (S2) in string expression (S1) beginning the search from the end of (S1), optionally ignoring the last (I) characters before attempting to find a match.

This function searches STRING1 for the first instance of STRING2, then returns an INTEGER showing the position within STRING1 where STRING2 begins; its offset in the string. The search will start at the end of STRING1, unless you use the optional START_POSITION parameter, and search backwards through the string. The INTEGER position returned by this function is always based on the start of the string. Example:

STRING:#S1  // The string that will be searched
STRING:#S2  // The string to look for
INTEGER:#POSITION  // The index into #S1 where #S2 is found

#S1="SmartCAMcnc CAM"
#S2="CAM"
#POSITION=RFIND(#S1, #S2) // #POSITION is equal to 13

#POSITION is set to 13, because when searching backwards through the string, the first "CAM" substring begins at the 13th position in STRING1.

The optional START_POSITION parameter is used to set where RFIND will begin to search. The START_POSITION is based on the beginning of the string, not the end. Example:

STRING:#S1  // The string that will be searched
STRING:#S2  // The string to look for
INTEGER:#POSITION

#S1="SmartCAM's CAM application"
#S1="CAM"	// Skip over 'CAM application' when searching
#POSITION=RFIND(#S1,#S2,11) // #POSITION is equal to 6

#POSITION is set to 6, because when searching backwards from position 11, the substring "CAM application" is not searched, so the first "CAM" substring starts at position 6 in STRING1.

If STRING2 is not found in STRING1, then RFIND will return 0.

S=RIGHT(S,I) Returns (I) number of characters from the right side of the string expression (S). Example:
STRING:#S1
STRING:#S2
#S1="SmartCAMcnc"
#S2=RIGHT(#S1,3) // #S2 is equal to "cnc"
S=RTRIM(S) Returns a string with all white-space trimmed from the right side of the string expression (S).White-Space characters are spaces, tabs, and line-feeds. For example:
STRING:#S1  // Original string
STRING:#S2  // returned string

#S1="   Right Trim   "
#S2=RTRIM(#S1) // S2 now contains "   Right Trim"

Notice the white-space characters on the left side of the string still exist.

S[]=SPLIT_STR(S1,S2) Explodes contents of string (S1) by breaking apart the string when any character in delimiters list (S2) is encountered. Results are returned in a String Array.

SPLIT_STR() starts checking each character in S1; looking for a match with any character in string S2. If a match is found, the section of S1 to the left of the matching delimiter is added to the return array. The matching delimiter character is discarded and matching continues from where it left off. When the entire S1 string has been checked, the function returns the String Array containing the split up string.

//	Separate string by comma and periods
STRING:#Array[] 	//	array to hold results
STRING:#Src = "One,Two,Three & Four. Plus Five.Done"
//	Split #Src by commas and periods
#Array[] = SPLIT_STR(#Src, ",.")

After running this code fragment, the #Array string array contains:

#Array[0] = "One"
#Array[1] = "Two"
#Array[2] = "Three & Four"
#Array[3] = " Plus Five"
#Array[4] = "Done"

Functions of this nature are very helpful when working with lists of data, perhaps a line from a Spreadsheet's CSV text format files.

I=STREQUAL(S1,S2) Returns 1 if the results of the string expressions (S1) and (S2) are identical, 0 if not.

This allows string equivalence to be tested by the IF statement in a macro. See the string comparison information in the Fundamentals of Branching and Looping topic.

S=STRIP_EXT(path) Returns a string with the file extension stripped from the end of the path.
I=STRLEN(S) Returns the number of bytes in the string expression (S). Double-byte characters count as 2.
S=STRSUB(S,I,I) STRSUB has been replaced with MID().
S=STRTMP(S) This function is no longer supported.
S=TO_LOWER(S) Returns a string where all characters in the string expression (S) are converted to lower case.
S=TO_UPPER(S) Returns a string were all characters in the string expression (S) are converted to UPPER case.
S=TRIM(S) Returns a string with all white-space characters trimmed from both the left and right sides of the string expression (S). White-Space characters are spaces, tabs, and line-feeds. For example:
STRING:#S1  // Original string
STRING:#S2  // returned string

#S1="   Trim   "
#S2=TRIM(#S1) // S2 now contains "Trim"

Notice the white-space characters on the both sides of the text are trimmed out.

System Filenames and Paths

Function Description
INCLUDE "S" Allows one macro file to be included into another. This macro statement includes the referenced file, into the currently running macro, at the location where the INCLUDE statement is located.

The INCLUDE statement is very useful for declaring all macro variables in a single file, then including the file at the start of the main macro. This establishes all the needed variables and their data types in a single easy to edit package.

The INCLUDE statement is followed by a quoted path and filename of the macro file to include.

See the Fundamentals: Variables topic for more information and examples of use.

S=GET_APP_PATH() Returns the folder where SmartCAM program files reside.
S=GET_CNC_PATH() Returns the folder where SmartCAM will write NC code files. This is the path where SmartCAM will write the files, to find the current NC code file use the CODFILE() macro command.
S=GET_COMM_PATH() Returns the SmartCAM common files path. This is where SmartCAM's support files are installed; such as sample data, machine and template files, default settings, among others.
S=GET_CTG_PATH() Returns the folder where SmartCAM will look for Custom Tool Graphic (CTG) files.
S=GET_JOF_PATH() Returns the folder where SmartCAM will look for the Job Operations Planner (JOF) file.
S=GET_MCL_PATH() Returns the default folder for SmartCAM Macro Command Language (MCL) files. This is the default path where SmartCAM will look for or write MCL files, to find the current running Macro filename, use the MCLFILE() macro command.
S=GET_SMF_PATH() Returns the folder where SmartCAM will look for SmartCAM Machine Files (SMF). This is the path where SmartCAM will look for the files, to get the exact file, use the SMFFILE() macro command.
S=GET_TEMP_PATH() Returns the folder where SmartCAM stores temporary files.
S=GET_USER_PATH() Returns the folder where SmartCAM User Configuration files reside. These are the .INI and Keep Default SU files that users can modify.
S=CGTFILE() Returns the current Code Generator Template path and file name
S=CODFILE() Returns the current Code path and file name
S=JOBFILE() Job file path plus job #DESC filename
S=MCLFILE() Returns the current Macro path plus current executing Macro name
S=SHPFILE() Returns the current Process Model path and filename.
S=SMFFILE() Returns the current Machine file path plus .smf file name
S=TMPFILE() Returns the current Template file path plus .tmp file name
S=VERSION() Returns the current application's Header text. The string contains the following information, separated by spaces: Application name, version number, platform, build date, build time.

Example: FreeForm_Machining 13.5.0 Windows 11/02/06 17:04:47

Status

Function Description
I=IB_CLEAR_ON() Returns whether or not the Insert Bar Clear field is enabled.

Values: 0 = Off, 1 = On

I=IB_PTOP_ON() Returns whether or not the Insert Bar Profile Top field is enabled.

Values: 0 = Off, 1 = On

D=CYLDIAM(elmt) Returns the Cylinder diameter of the given element.
D=ENV_XE()
D=ENV_YE()
D=ENV_ZE()
The end of the view envelope
D=ENV_XS()
D=ENV_YS()
D=ENV_ZS()
The start of the view envelope
D=GRP_DIAG() Returns the longest diagonal measurement of a bounding box oriented parallel to the world XY_PLANE axes, and surrounding the active group. The accuracy of the bounding box is determined by the Surface Entity Bounding Box Mode setting in the Utilities - Options - Performance Options.
D=GET_IB_CLEAR() Returns the current Insert Bar (IB) Clear value.

This function is only relevant when working with Steps, not Layers.

I=GET_IB_OFFSET() Returns the current Insert Bar (IB) Offset value.

Values are: 0 = Left, 1 = Right, 2 = None

This function is only relevant when working with Steps, not Layers.

D=GET_IB_LEVEL() Returns the current Insert Bar (IB) Level value.
D=GET_IB_PTOP() Returns the current Insert Bar (IB) Profile Top value.
S=GET_IB_WKPLN() Returns a string containing the current Insert Bar (IB) Workplane Name.
I=GET_SURF_ENV_MODE() Returns the current Surface Entity Bounding Box Mode setting from Performance Options.

Values are: 0 = Default, 1 = Exact

This function can be used in conjunction with the SURF_ENV_MODE_SET macro command, in order to read the current setting, change to a different setting, and then restore the original setting. The bounding box calculation is used by View - Envelope and the GRP_DIAG() function.

I=GRP(I) Returns the element number of an element in the active group. Where the integer parameter is the Group Element Index.

If the parameter is "0" and an active group exists, GRP returns the number of elements in the active group.

If the parameter is in the valid range of total elements in the group, GRP returns the element number of the nth element in the active group.

If there is no group or the element is out of range, GRP returns -1.

Use "1", as the parameter, for the first element in the group.

I=INSCNT() Current status of the Insert Container button, on the Insert Properties bar.

Values: 0 = Off, 1 = On

I=LAST_STEP() Returns the highest Step number currently defined in the open process model. If there are no defined steps, it returns 0 (zero). The Step does not need to be used, it only needs to exist.
I=LAST_TOOL() Returns the highest Tool number currently defined in the open process model. If there are no defined tools, it returns 0 (zero). The Tool does not need to be used, it only needs to exist. For non-turning applications.
I=LAST_TUR_TOOL(I) Returns the highest Tool number, for a given turret, defined in the open process model. If there are no defined tools, it returns 0 (zero). The tool does not need to be used, it only needs to exist. Provide the turret number as the argument for this function. For turning applications.
I=LAYER_BY_NAME(S) Returns the layer number of the first layer with a given name. The argument for this function is a string that contains the layer name to search for. The layer number for the first matching name is returned.

If there is no matching layer name, then -1 is returned.

Passing in an empty string (""), returns the first layer that does not have an assigned name.

The layer name string is case-sensitive.

I=LAYER_MASKED(layer number) Is the layer masked?

Values: 0 = Not Masked, 1 = Masked

I=LNUM() Returns the active layer number or -1 if a step number
I=MATCHPROP() Current status of the Match Properties button, on the Insert Properties bar.

Values: 0 = Off, 1 = On

I=OPNLIST(I) Returns values from the job operations setup list, based on the following settings:

If the integer parameter is 0 and the job operations setup has steps defined, OPNLIST returns the number of steps in the step list.

If the parameter is 0 and no steps exist, returns a 0.

If the integer parameter is a valid index in the step list, returns the step number of that step list entry.

If the parameter is greater than the total number of entries in the step list or less than 0, returns a -1.

OPNLIST formerly TNLIST(idx).

S=OPDESC(stpnum) Returns the string description of the Operation Type.
I=OPTYPE(stpnum) Returns the SNCS number for a step number
I=SECTION_STATUS() Determines whether View - Section is enabled or not. Returns 1 if Section is enabled. Returns 0 if Section is not enabled.
I=SEL_FILTER_ON() Current status of the Selection Filter button, on the Group toolbar and readout line.

Values: 0 = Off, 1 = On

I=SEQBA() Determines the insert mode.

Values: 0 = Before, 1 = After

I=SEQEL() Determines the current selected insert element number
I=SNUM() Returns the step number of the active step, or -1 if layer
I=STEP_INCR() Returns the current Step increment, the value added to the currently highest Step number when a new Step is created. Using this function and LAST_STEP() can calculate what the next step number will be, when a new Step is defined.
I=STEP_MASKED(stpnum) Is the step masked?

Values: 0 = Not Masked, 1 = Masked

I=SUBCOUNT() Returns the number of subs present in the process model. The subindexes begin at 0. So if SUBCOUNT() returns 5, the subindexes go from 0 to 4. See also SUB().
I=SUB_IS_USED(subindex) Returns 1 (YES) if the sub is currently being used in the process model, and 0 (NO) if it is not. See also SUB().
S=SUBNAME_FRM_EL(elmt) Returns the sub name if the element is a SubCall. Otherwise returns an empty string. See also SUB().
S=SUBNAME_FRM_IDX(subindex) Returns the sub name for the given sub index. See also SUB().
I=SUBREPTS(elmt) Returns the number of repeats for a SubCall.

Returns 0 if the element is not a SubCall or there are no repeats.

I=SUBTYPE_FRM_EL(elmt) Returns the sub type if the element is a SubCall.

Values: 0 = Not a subcall, 1 = Normal Sub, 2 = Drill Sub

See also SUB().

I=SUBTYPE_FRM_IDX(subindex) Returns the sub type for the given sub index.

Values: 0 = Not a valid sub index, 1 = Normal Sub, 2 = Drill Sub

See also SUB().

S=TDESC(stpnum) Returns the tool description for step number
S=TLCMT(stpnum) Returns the tool comment for the step number
D=TLDIA(stpnum) Returns the diameter of the tool for the given step number
D=TLEN(stpnum) Returns the length of the tool for a given step number
I=TLTYPE(stpnum) Returns a number indicating the type of tool for a step number.

It returns a single integer value, use the following table to interpret the return value.

TypeMillTurnPunchEDMBurnerRouterContour / Laser
1Spot DrillFaceRoundElectrodeTorchRouter BitCutter
2DrillTurnSquareDrillScribe
3ReamerBoreRectanglePunch Mark
4TapFace GrooveObround
5End Mill/Bull NoseOuter Diam. GrooveDiamond
6Ball MillInner Diam. GrooveTorch
7Face MillOuter Diam. ThreadAttachment
8BoreInner Diam. ThreadOther
9CounterboreDrill
10CountersinkTap
11OtherOther
12Draft Mill
13Radius Punch
14Single D
15Chamfer MillDouble D
16Rounding MillTrapezoid
17Thread Mill
I=TOOL_INCR() Returns the current Tool increment, the value added to the currently highest Tool number when a new Tool is created. Using this function and LAST_TOOL() can calculate what the next tool number will be, when a new Tool is defined.
I=TOTEL() Determines the number of elements in the database
S=TURTOOL(elmt) Returns a string with the Turret number and Tool number, in the format: Turret:Tool. Returns 0 if a layer.
I=UNITS() Returns the process model's current units.

Values: 0 = Inch, 1 = Metric

I=WKPLN_COUNT() Returns the number of workplanes currently defined.
I=WKPLN_MASKED("wkpln name") Is the workplane masked?

Values: 0 = Not Masked, 1 = Masked

Enter the name of the workplane, exactly as displayed user interface, in quotes. Example: #i=WKPLN_MASKED("XY_PLANE")

D=WKPLN_WRAD(plane index) Returns the workplane wrap radius.

Returns 0 if the plane is not wrapped or doesnt't exist.

See Also: PLN(elmt) and PLNNUM(wkpln name)

I=WKPLN_WRAPPED(plane index) Is the workplane wrapped?

Values: 0 = Not Wrapped, 1 = Wrapped

See Also: PLN(elmt) and PLNNUM(wkpln name)

Plane Orientation Functions

Function Description
D=PLNIX(I)
D=PLNIY(I)
D=PLNIZ(I)
D=PLNJX(I)
D=PLNJY(I)
D=PLNJZ(I)
D=PLNKX(I)
D=PLNKY(I)
D=PLNKZ(I)
D=PLNTX(I)
D=PLNTY(I)
D=PLNTZ(I)
Uses Workplane index as parameter and returns xyz components of a plane's IJKT orientation vectors
I=PLNNUM(wkpln name) Get plane index from name, PLNNUM(plane-name)

Utility Functions

Function Description
I=DIAGMSG(S) Sends a text string to the Utility - Diagnostic text area. You can review this text, by opening the Diagnostic window. Returns the integer 1 is successful.
D=MEAS_2D_EL(D, D, elmt) Measures the 2D distance between a point and element. The first two decimal parameters are the X and Y locations for the point to measure against.
D=MEAS_2D_PT(D, D, D, D) Measures the 2D distance between two points. The four decimal parameters are the X and Y locations of the first and second point.
D=MEAS_3D_PT(D, D, D, D, D, D) Measures the 3D distance between two points. The six decimal parameters are the X,Y,Z values for the two points.
D=STEPOVER_CUSP(D, D) Calculates the arc center distance between 2 overlapping arcs placed tangent to a line, based on a specified cusp height and radius. The cusp height is measured perpendicular to the line, and represents the distance from the line to the cusp peak. The cusp height must be greater than 0 and less than the radius, and the radius must be greater than 0.

Date and Time

Function Description
S=DATE() Returns a string containing the current system date. The returned string is an eight character filled string, for example: 2-Feb-2009 is returned as 02/02/09.

The DATE() function returns the date string using the Windows' Regional and Language Options setting for the short-date format.

S=SYSTIME() Returns a string containing the current system time. The returned time uses the format: Hour:Minute AM/PM. For example: 10:42AM.

The SYSTIME() function always returns the hour, minute and AM/PM notation, however it will use any special time separator as defined with Windows' Regional and Language Options setting for the time format.

Related Topics

Expressions

Variables

Math

Macro Development Fundamentals Overview

SmartCAM Automation Overview