PowerMILL 2012 R2 - Macro Programming Guide
PowerMILL 2012 R2 - Macro Programming Guide
User Guide
Macro Programming Guide
Release issue 1
Copyright 1996 - 2012 Delcam plc. All rights reserved.
Delcam plc has no control over the use made of the software
described in this manual and cannot accept responsibility for any
loss or damage howsoever caused as a result of using the software.
Users are advised that all the results from the software should be
checked by a competent person, in accordance with good quality
control procedures.
The functionality and user interface in this manual is subject to
change without notice in future revisions of software.
The software described in this manual is furnished under licence
agreement and may be used or copied solely in accordance with the
terms of such licence.
Delcam plc grants permission for licensed users to print copies of
this manual or portions of this manual for personal use only.
Schools, colleges and universities that are licensed to use the
software may make copies of this manual or portions of this manual
for students currently registered for classes where the software is
used.
Acknowledgements
This documentation references a number of registered trademarks
and these are the property of their respective owners. For example,
Microsoft and Windows are either registered trademarks or
trademarks of Microsoft Corporation in the United States.
Patents
The Raceline smoothing functionality is subject to patent
applications.
Patent granted: GB 2374562 Improvements Relating to Machine
Tools
Patent granted: US 6,832,876 Machine Tools
Some of the functionality of the ViewMill and Simulation modules of
PowerMILL is subject to patent applications.
Patent granted: GB 2 423 592 Surface Finish Prediction
Licenses
Intelligent cursor licensed under U.S. patent numbers 5,123,087
and 5,371,845 (Ashlar Inc.)
Index 95
Creating macros
You can create macros by:
Recording (see page 2) a sequence of commands within
PowerMILL.
Writing (see page 5) your own macro using a text editor.
Editing macros
You can edit recorded macros to troubleshoot and correct any
errors.
1 Expand Macros and select the macro you want to edit.
When you have defined a local variable you can use it as many
times as you want in a macro.
You can define as many local variables as you want in a macro.
DO - WHILE loop
1 Edit the PrintBottles function in example.mac to
FUNCTION PrintBottles(INT Count) {
IF statement
You can use an IF statement to ensure the 10 green bottles sitting on
the wall line is printed at least twice.
1 Edit the Main function in example.mac to:
FUNCTION Main (INT Count) {
Each code block or function can define its own set of local
variables; the scope of the variable is from its declaration
to the end of the enclosing block or function.
4 Add the NumberStr function into example.mac.
This gives exactly the same output as the Returning values from
macros (see page 18) example. It shows you an alternative way
of creating the same output.
This gives exactly the same output as the Returning values from
macros (see page 18) example. It shows you an alternative way
of creating the same output.
Variables in macros
You can create variables in macros just as you can in a PowerMILL
project. When you create a variable in a macro, it has the same
properties as a PowerMILL parameter, and can store either a value
or an expression.
Assigning parameters
When you assign a value to a variable the expression is evaluated
and the result is assigned, the actual expression is not retained.
This is the same as using the EVAL modifier in the PowerMILL
parameter EDIT PAR command. These two statements are
equivalent:
EDIT PAR "Stepover" EVAL "Tool.Diamter * 0.6"
$Stepover = Tool.Diameter * 0.6
This command returns the name of the tool the user selected.
This example creates two folders, creates two tool in each folder,
then asks the user to select one of the tools:
// Create some tools in folders
CREATE FOLDER 'Tool' 'Endmills'
CREATE IN 'Tool\Endmills' TOOL 'End 20' ENDMILL
EDIT TOOL ; DIAMETER 20
CREATE IN 'Tool\Endmills' TOOL 'End 10' ENDMILL
EDIT TOOL ; DIAMETER 10
CREATE FOLDER 'Tool' 'Balls'
CREATE IN 'Tool\Balls' TOOL 'Ball 12' BALLNOSED
EDIT TOOL ; DIAMETER 12
CREATE IN 'Tool\Balls' TOOL 'Ball 10' BALLNOSED
EDIT TOOL ; DIAMETER 10
// Prompt user to pick one
STRING ToolName = ''
$ToolName = INPUT ENTITY TOOL "Please select a Tool."
Using lists
A list, like an array, contains multiple values. You can create a list
with initial values:
INT LIST MyList = {1,2,3,4}
FUNCTION Main() {
INT LIST MyList = {10,20,30,40}
CALL PrintArray(MyList)
}
You will normally access the elements of a list with a FOREACH loop,
but you can also access the elements using the array subscripting
notation:
INT Val = MyList[2]
FOREACH tp IN folder('Toolpath\MyFolder') {
INT Size = add_last(TpNames, tp.name)
}
For more information see Adding comments to macros (see page 7).
Building a list
You can use the inbuilt member() function in a macro function to
build a list of tool names used by toolpaths or boundaries without
any duplicates:
FUNCTION ToolNames(STRING FolderName, OUTPUT STRING LIST
ToolNames) {
Subtract function
You can use the subtract() function to determine what happened
after carrying out a PowerMILL command. For example, suppose
you to find out if any new toolpaths are created during a toolpath
verification. If you get the list of toolpath names before the
operation, and the list of names after the operation, and then
subtract the ‘before’ names from the ‘after’ names you are left with
the names of any new toolpaths.
FUNCTION GetNames(STRING FolderName, OUTPUT STRING LIST
Names) {
FOREACH item IN folder(FolderName) {
INT n = add_last(Names, item.Name)
}
}
FUNCTION Main() {
IF is_empty(NewNames) {
PRINT "No new toolpaths were created."
} ELSE {
PRINT "The new toolpaths created are:"
FOREACH item IN NewNames {
PRINT = item
}
}
}
Comparing variables
Comparing variables allows you to check information and defines
the course of action to take when using IF (see page 49) and WHILE
(see page 56) statements.
The result of a comparison is either true or false. When true the
result is 1, when false the result is 0.
A simple comparison may consist of two variables with a relational
operator between them:
Relational operator Description
Symbol Text
== EQ is equal to
!= NE is not equal to
< LT is less than
Scope of variables
A variable exists from the time it is declared until the end of the
block of code within which it is declared. Blocks of code are macros
and control structures (WHILE, DO - WHILE, SWITCH, IF-ELSEIF-
ELSE, and FOREACH).
A variable, with a specific name, can only be defined once within
any block of code.
For example,
// Define a local variable 'Count'
INT Count = 5
// Define a second local variable 'Count'
INT Count = 2
Gives an error since Count is defined twice.
However, within an inner block of code you can define another
variable with the same name as a variable (already defined) in an
outer block:
INT Count = 5
IF Count > 0 {
// Define a new local variable 'Count'
INT Count = 3
// Print 3
PRINT $Count
// The local Count is no longer defined
}
// Print 5
PRINT $Count
A variable defined within an inner block of code hides any variable
declared in an outer block. This is also important if you use a name
for a variable which matches one of PowerMILL’s parameters. For
example, if the toolpath stepover is 5 and in your macro you have:
// 'Hide' the global stepover by creating your own
variable
REAL Stepover = 2
// Print Stepover
PRINT $Stepover
// Assignments
$Stepover = Tool.Diameter * factor
$factor = 0.75
Operator precedence
The order in which various parts of an expression are evaluated
affects the result. The operator precedence unambiguously
determines the order in which sub-expressions are evaluated.
Multiplication and division are performed before addition and
subtraction.
For example, 3 * 4 +2 is the same as 2 + 3 * 4 and gives the
answer 14.
Exponents and roots are performed before multiplication and
addition.
For example, 3 + 5 ^ 2 is the same as 3 + 5 and gives the
answer 28.
-3 ^ 2 is the same as -3 and gives the answer -9.
Use brackets (parentheses) to avoid confusion.
For example, 2 + 3 * 4 is the same as 2 + (3 * 4) and gives the
answer 14.
Parentheses change the order of precedence as terms inside in
parentheses are performed first.
For example, (2 + 3) * 4 gives the answer 20.
or, (3 + 5) ^2 is the same as (3 + 5) and gives the answer 64.
You must surround the arguments of a function with
parentheses.
For example, y = sqrt(2), y = tan(x), y = sin(x + z).
Relational operators are performed after addition and
subtraction.
For example, a+b >= c+d is the same as (a+b) >= (c+d).
Logical operators are performed after relational operators,
though parentheses are often added for clarity.
For example:
5 == 2+3 OR 10 <= 3*3
is the same as:
(5 == (2+3)) OR (10 <= (3*3))
but is normally written as
(5 == 2+3) OR (10 <= 3*3).
Macro functions
When you run a macro you can use arguments, such as the name of
a toolpath, tool, or a tolerance. You must structure the macro to
accept arguments by creating a FUNCTION called Main (see page
46) then specify the arguments and their type.
For example, a macro to polygonise a boundary to a specified
tolerance is:
FUNCTION Main(REAL tol) {
EDIT BOUNDARY ; SMASH $tol
}
A macro to set the diameter of a named tool is:
FUNCTION Main(
STRING name
REAL diam
)
{
EDIT TOOL $name DIAMETER $dia
}
To run these macros with arguments add the arguments in the
correct order to the end of the MACRO command:
MACRO MyBoundary.mac 0.5
MACRO MyTool.mac "ToolName" 6
If you use FUNCTION in your macro, then all commands must be
within a function body. This means that you must have a FUNCTION
Main, which is automatically called when the macro is run.
FUNCTION CleanBoundary(string name) {
REAL offset = 1 mm
REAL diam = entity('boundary';name).Tool.Diameter
// Delete segments smaller than tool diameter
EDIT BOUNDARY $name SELECT AREA LT $diam
DELETE BOUNDARY $name SELECTED
//Offset outwards and inwards to smooth boundary
EDIT BOUNDARY $name OFFSET $offset
EDIT BOUNDARY $name OFFSET ${-offset}
}
FUNCTION Main(string bound) {
FOREACH bou IN folder(bound) {
CALL CleanBoundary(bou.Name)
}
}
Main function
If a macro has any functions:
It must have one, and only one, FUNCTION called Main.
The Main function must be the first function called.
Function names aren't case sensitive: MAIN, main, and MaIn all refer
to the same function.
Running a macro where the Main function is called with either the
wrong number of arguments or with types of arguments that don't
match, causes an error. For example:
MACRO MyTool.mac 6 "ToolName"
generates an error since the macro expects a string and then a
number, but is given a number and then a string.
If you want to repeat a sequence of commands at different points
within a macro, you can use a FUNCTION.
For example, if you want to remove any small islands that are
smaller than the tool diameter and smooth out any minor kinks
after a boundary calculation. One solution is to repeat the same
commands after each boundary calculation:
EDIT BOUNDARY ; SELECT AREA LT Boundary.Tool.Diameter
DELETE BOUNDARY ; SELECTED
EDIT BOUNDARY ; OFFSET "1 mm"
EDIT BOUNDARY ; OFFSET "-1 mm"
FUNCTION Main() {
REAL Par1 = 2
REAL Par2 = 1
CALL Test(Par1, Par2)
// Prints 2 - value is unchanged
PRINT $Par1
// Prints 0 - value has been changed
PRINT $Par2
}
When the CALL command is executed in the MAIN function:
1 PowerMILL creates a new REAL variable called aInput. It is
assigned the value of Par1, and passed into Test.
2 PowerMILL passes Par2 directly into Test where it is known as
aOutput.
INCLUDE common.inc
FUNCTION Main(input string bound) {
FOREACH bou IN folder(bound) {
CALL CleanBoundary(bou.Name)
}
}
To call this macro from PowerMILL:
The first brace must be the last item on the line and on the
same line as the IF.
The closing brace must be on a line by itself.
SWITCH statement
When you compare a variable with a number of possible values and
each value determines a different outcome, it is advisable to use the
SWITCH statement.
The SWITCH statement allows you to compare a variable against a
list of possible values. This comparison determines which
commands are executed.
The basic control structure is:
SWITCH variable {
CASE (constant_A)
Commands A
CASE (constant_B)
Commands B
DEFAULT
Commands C
}
Commands D
If condition_A is true then Commands A, B, C, and D are executed.
If condition_B is true then Commands B, C, and D are executed.
If condition_A and condition_B are false then Commands C, and D are
executed.
FOREACH loop
A FOREACH loop repeatedly executes a block of commands for each
item in a list or array.
The basic control structure is:
FOREACH item IN sequence{
Commands A
}
Commands B
where:
item is an automatically created variable that PowerMILL initialises
for each iteration of the loop;
sequence is either a list or an array.
Commands A are executed on the first item in the list.
Commands A are executed on the next item in the list. This step is
repeated until there are no more items in the list.
At the end of the list, Commands B are executed.
For example,
FOREACH item IN folder("path") {
Commands A
}
WHILE loop
A WHILE loop repeatedly executes a block of commands until its
conditional test is false.
The basic control structure is:
WHILE condition {
Commands A
}
Commands B
DO - WHILE loop
The DO - WHILE loop executes a block of commands and then
performs its conditional test, whereas the WHILE loop checks its
conditional test first to decide whether to execute its commands or
not.
The basic control structure is:
DO {
Commands A
} WHILE condition
Commands B
Commands A are executed.
While condition remains true, then Commands A are executed.
When condition is false, Commands B are executed.
CONTINUE statement
The CONTINUE statement causes a jump to the conditional test of
any one of the loop constructs WHILE, DO - WHILE, and FOR EACH in
which it is encountered, and starts the next iteration, if any.
This example, calculates and offsets, all unlocked boundaries,
outwards and inwards.
FOREACH bou IN folder('Boundary') {
IF locked(bou) {
// This boundary is locked go get the next one
CONTINUE
}
REAL offset = 1 mm
EDIT BOUNDARY $bou.Name CALCULATE
EDIT BOUNDARY $bou.Name OFFSET $offset
EDIT BOUNDARY $bou.Name OFFSET ${-offset} }
The CONTINUE statement enables the selection of the next
boundary.
IF NOT active(entity('toolpath',TpName).Tool.TipRadius)
{
// Error if toolpath does not use a tipradius tool
PRINT "Toolpath does not have TipRadius tool"
RETURN
}
FUNCTION Main() {
FOREACH tp IN folder('Toolpath') {
ACTIVATE TOOLPATH $tp.Name)
}
}
Terminating macros
The command MACRO ABORT immediately terminates the current
macro.
The command MACRO ABORT ALL terminates the all the macros that
are currently running. If you call MACRO ABORT ALL from within a
macro that has been called by another macro, then both macros are
terminated.
Constants
PowerMILL has a small number of useful constant values that you
can use in expressions and macros these include:
REAL PI = 3.141593
REAL E = 2.718282
BOOL TRUE = 1
BOOL FALSE = 0
STRING CRLF = newline
Use these values to make your macros more readable. For example,
use CRLF constant to build up multi-line messages and prompts:
STRING msg = "This is line one."+CRLF+"This is line two."
MESSAGE INFO $msg
Displays the message:
This is line one.
This is line two.
Built-in functions
This section details all the built-in functions that you can use in your
macros.
General mathematical functions (see page 61).
Trigonometrical functions (see page 61).
Vector and point functions (see page 62).
Workplane functions (see page 64).
String functions (see page 64).
Trigonometrical functions
The basic structure of the trigonometrical functions are:
Description of return value Function
Trigonometric sine real sin( angle )
Trigonometric cosine real cos( angle )
Trigonometric tangent real tan( angle )
Trigonometric arcsine real asin( real a )
Trigonometric arccosine real acos( real a )
Trigonometric arctangent real atan( real a )
Length
The length() function returns the length of a vector.
For example:
REAL ARRAY V[] = {3,4,0}
// Prints 5.0
PRINT = length(V)
The inbuilt function unit() returns a vector that points in the same
direction as the input vector, but has a length of 1:
PRINT PAR "unit(V)"
// [0] (REAL) 0.6
// [1] (REAL) 0.8
// [2] (REAL) 0.0
// prints 1.0
PRINT = length(unit(V))
Parallel
The parallel() function returns TRUE if two vectors are either
parallel (pointing in the same direction) or anti-parallel (pointing in
the opposite direction) to each other.
For example:
// prints 0
PRINT = parallel(VecX,Vecy)
Normal
The normal() function returns a vector that is normal to the plane
containing its two input vectors. If either vector is zero it returns an
error. If the input vectors are either parallel or anti-parallel a vector
of zero length is returned.
For example:
REAL ARRAY norm = normal(VecX,VecY)
Angle
The angle() function returns the signed angle in degrees between
two vectors, providing that neither vectors have a zero length.
For example:
// Prints 90
PRINT = angle(VecX,VecY)
// Prints 90
PRINT = angle(VecY,VecX)
The apparent_angle() function returns the apparent angle
between two vectors when looking along a reference vector. If a
vector is parallel or anti-parallel to the reference vector, or if any of
the vectors have a zero length it returns an error:
// prints 270
print = apparent_angle(VecX,VecY,MVecZ)
// prints 90
print = apparent_angle(VecY,VecX,MVecZ)
Setting
The set_vector() and set_point() functions return the value 1 if
the vector or point is set.
For example:
REAL ARRAY Vec1[3] = {0,0,1}
REAL ARRAY Vec2[3] = {0,1,0}
REAL X = Block.Limits.XMax
REAL Y = Block.Limits.YMin
REAL Z = Block.Limits.ZMax
ok = set_point(ToolAxis.Origin, X,Y,Z)
Workplane functions
You can use the inbuilt function set_workplane() to define the
origin and axis of a workplane entity. You can call the function:
with two workplanes, where the values from the second
workplane are copied into the first:
bool ok =
set_workplane(Workplane,entity('workplane','3'))
which sets the active workplane to have the same values as
workplane 3.
with a workplane, two vectors, and an origin:
REAL ARRAY YAxis[] = {0,1,0}
REAL ARRAY ZAxis[] = {0,0,1}
REAL ARRAY Origin = {10,20,30}
bool ok =
set_workplane(entity('workplane','reference'), YAxis,
Zaxis,Origin)
String functions
PowerMILL parameters and variables can contain strings of
characters. There are a number of inbuilt functions that you can use
to test and manipulate strings.
The basic structure of string functions are:
Description of return value Function
Returns the number of int length( string str )
characters in the string.
For more information see
Length function in a string
(see page 66).
Another example:
STRING One = "One"
STRING Two = "Two"
STRING CountToTwo = One + ", " + Two
PRINT = length(CountToTwo)
The command window displays the result, 8.
Substrings
The substring function returns part of the string. You can define
where the substring starts and its length. The original string is
unchanged.
The basic structure is:
string substring( string str, int start, int length)
For example:
PRINT = substring("Scooby doo", 2, 4)
The command window displays the result, ooby.
Whitespace in a string
The ltrim() function removes any leading whitespace from a
string. Use this to clean up user input before further processing. The
original string is unchanged.
For example:
STRING Original = " What's up Doc!"
STRING Trimmed = ltrim(Original)
print = Original
print = Trimmed
Where:
print = Original displays " What's up Doc!" in the command
window.
print = Trimmed displays "What's up Doc!" in the command
window.
Splitting a string
The tokens() function will split a string into a list of strings that were
separated by the separator characters. By default the separator
characters are spaces and tabs.
For example:
STRING InputStr = "One Two Three"
STRING LIST Tokens = tokens(InputStr)
FOREACH Tok IN Tokens {
PRINT = Tok
}
You can also give the tokens() function an optional extra argument
that changes the separator character.
For example:
STRING InputStr = "10:20:30:40"
STRING LIST Tokens = tokens(InputStr,':')
List functions
List functions control the content of a list or array.
The basic structure of list functions are:
Description Function
Returns the components (see list components( entity
page 72) of another object. entity )
Returns a list of all the list folder( string
entities in the folder (see page folder )
73).
Determines if the list has any is_empty()
content (see page 74).
Determines if the list contains member()
a specific value (see page 74).
Adding (see page 75) a list or +
array to another list or array
Removes duplicate (see page remove_duplicates()
75) items from a list.
Creates a list by compiling the set_union()
contents of two lists (can
contain duplicate naming)
Creates a list containing items intersection()
that are present in two lists
(see page 75).
Creates a list by subtracting subtract()
(see page 76) from the first
list those items that are
present in the second list.
List components
The inbuilt components function returns the components of another
object.
List folder
The folder function returns a list of all entities within a folder,
including those in subfolders.
The basic structure is:
list folder( string folder )
The names of the root folders are:
MachineTool
NCProgram
Toolpath
Tool
Boundary
Pattern
The name of the folder is case sensitive, so you must use Tool
and not tool.
You can use a FOREACH loop to process all of the entities within a
folder. For example, to batch process tool holder profiles:
FOREACH tool IN folder ('Tool'){
EDIT TOOL $tool.Name UPDATE_TOOLPATHS_PROFILE
}
An example, to batch process all the boundaries in your project:
FOREACH bou IN folder('Boundary') {
EDIT BOUNDARY $bou.Name CALCULATE
}
Empty list
The is_empty() function queries a list to determine whether it is
empty or not.
REAL LIST MyList = {}
IF is_empty(MyList) {
PRINT "Empty List"
}
List member
The member() function returns TRUE if the given value is one of the
items in the list. For example, to check that a toolpath doesn't occur
in more than one NC program, you can loop over all NCProgram and
check that each toolpath is only seen once. Do this by building a list
of toolpath names and checking that each time you add a name you
haven't already seen it.
// Create an empty list
STRING List names = {}
// Cycle through the NC programs
FOREACH ncp IN folder('NCProgram') {
// loop over the components in the nc prog
FOREACH item IN components(ncp) {
// Check that it is a toolpath
IF item.RootType = 'nctoolpath' {
Adding lists
The + function adds a list or array to another list or array. For
example, you can add two lists together to get a list of all the tools
used by the toolpaths and boundaries:
STRING LIST UsedToolNames = ToolpathTools + BoundaryTools
The FOREACH loop adds each item to the start of the list. As the
add_first command adds the next pattern to the start of the list.
So you end up with a list
{"Pattern_3","Pattern_2,"Pattern_1"}.
The WHILE loop takes the first item in the list, removes it from the
list and pints it. This gives:
Pattern_3
Pattern_2
Pattern_1
Folder name
The pathname function returns the full folder name of the entity,
or,if the entity doesn't exist, an empty string.
The basic structure is:
string pathname( entity ref )
Also,
string pathname( string type, string name)
Returns the full folder name of the entity.
For example, if you have a BN 16.0 diam tool in a Ballnosed tool
folder, then:
pathname('tool', 'BN 16.0 diam')
returns the string Tool\Ballnosed tools\BN 16.0 diam.
Directory name
The directory name function returns the directory prefix from the
path.
The basic structure is:
string dirname( string path)
For example you can use this to obtain the argument for the inbuilt
folder() function.
STRING flder = dirname(pathname('toolpath',Name))
Base name
The base name function returns the non-directory suffix from the
path.
The basic structure is:
string basename( string path)
Usually basename(pathname('tool',tp.Name)) is the same as
tp.Name, but you can use this in conjunction with dirname (see page
80) to split apart the folder names.
For example, suppose your toolpaths are split in folders:
Toolpath\Feature1\AreaClear
Toolpath\Feature1\Rest
Toolpath\Feature1\Finishing
Toolpath\Feature2\AreaClear
Toolpath\Feature2\Rest
Toolpath\Feature2\Finishing
You can rename all your toolpaths so that they contain the feature
name and the area clearance, rest, or finishing indicator.
Project name
The project pathname function returns the pathname of the current
project on disk.
The basic structure is:
project_pathname(bool basename)
The argument dirname_only gives a different result if it is true to if
it is false.
If true, returns the name of the project.
If false returns the full path of the project.
For example if you have opened a project
called:C:\PmillProjects\MyProject
project_pathname(0) returns"C:\PmillProjects\MyProject.
project_pathname(1) returns MyProject.
A PowerMILL macro example is:
EDIT BLOCKTYPE TRIANGLES
STRING $ARBLOCK = project_pathname(0) + '\' + 'block_test.dmt'
GET BLOCK $ARBLOCK
Conditional functions
The basic structure of conditional functions are:
Evaluation functions
The evaluation function evaluate a string argument as an
expression.
For example:
print = evaluate("5*5")
prints 25.
You can use evaluate to provide a different test at runtime.
This example provides a bubble sort for numeric values. By
changing the comparison expression you can get it to sort in
ascending or descending order.
FUNCTION SortReals(STRING ComparisonExpr, OUTPUT REAL
LIST List) {
// Get number of items.
INT Todo = size(List)
// Set swapped flag before we start
Bool swapped = 1
// Repeat for number of items
FUNCTION Main() {
/Set up some data
REAL ARRAY Data[] = {9,10,3,4,1,7,2,8,5,6}
// Sort in increasing value
CALL SortReals("List[Idx] > List[Idx+1]", Data)
PRINT PAR "Data"
REAL ARRAY Data1[] = {9,10,3,4,1,7,2,8,5,6}
// Sort in decreasing order
CALL SortReals("List[Idx] < List[Idx+1]", Data1)
PRINT PAR "Data1"
}
Parameter functions
All of the PowerMILL parameters have an active state which
determines whether the parameter is relevant for a particular type
of object or operation.
The basic structure of the parameter functions are:
Description of return value Function
Evaluates the active bool active( par )
expression of par.
Returns whether the bool locked( par )
parameter can be changed or
not.
Returns the number of sub- int size( par )
parameters that par contains.
Statistical functions
The statistical functions enable you to return the minimum and
maximum values of any number of numeric arguments.
The basic structure of the statistical functions are:
Description of return value Function
Returns the largest value in a real max( list numeric a
list of numbers. )
Returns the smallest value in real min( list numeric a
a list of numbers. )
This example finds the maximum and minimum block height of the
toolpaths in the active NC program.
REAL maxz = -100000
REAM minz = abs(maxz)
Equivalence
You can use the inbuilt function geometry_equal() to test whether
two tools,or two workplanes are geometrically equivalent. For a tool
the test is based on the cutting geometry of the tool.
Number of segments
The inbuilt function segments() will return the number of segments
in a pattern or boundary:
IF segments(Pattern) == 0 {
PRINT "The pattern is empty"
}
Limits
The inbuilt function limits() returns an array of six elements
containing the XYZ limits of the given entity. The supported entities
are: pattern, boundary, toolpath, feature set, or model.
REAL ARRAY Lims[] = limits('model','MyModel')
IF NOT entity_exists(entity('toolpath','')) {
PRINT "Please activate a toolpath and try again."
MACRO ABORT ALL
}
// Prints 4
PRINT = new_entity_name('workplane')
DELETE WORKPLANE 2
CREATE WORKPLANE ;
// Prints 2_1
PRINT = new_entity_name('workplane', '2')
2 To create a macro path, click , and use the Select Path dialog
to select the desired location. The path is added to the top of the
list.
3 To change the path order, select the path you want to move, and
use the and buttons to promote or demote the path.
4 Click Close.
5 To load the new paths into PowerMILL, expand the Macros node
in the explorer.
Only the paths that contain at least one macro are shown.
For more information, see Displaying Macros in explorer.
7 Close and then restart PowerMILL to check that the settings from
the pmuser macro are activated.
A C
Adding items to a list • 32, 76 Calling from other macros • 4
Adding lists • 75 Carriage returns in dialogs • 28
Adding macro loops • 10 Comparing variables • 36, 37
Adding macro variables • 9 Components
Arguments in macros • 44 List components • 72
Function values • 46 Compound macros • 4
Running macros with arguments • 11 Conditrional functions • 81
Sharing functions • 48 Constants • 60
Arrays • 29 Euler's number • 60
Lists • 29 Pi • 60
Points • 35 Converting numerics to strings • 66
Using arrays • 24 Creating macros • 1
Vectors • 35 Basic macro • 9
Creating variables (macros) • 25
B
Base name • 80
D
Basic macro • 9 Decision making in macros • 13
Adding macro loops • 10 Decisions in macros
Adding macro variables • 9 BREAK statement • 53, 58
Decision making in macros • 13 IF - ELSE statement • 49
Returning values from macros • 18 IF - ELSEIF - ELSE statement • 50
Running macros with arguments • 11 IF command • 48
Using a FOREACH loop • 21 SWITCH statement • 51
Using arrays • 24 Dialogs in macros • 26
Using functions in macros • 15 Carriage returns in dialogs • 28
BREAK statement • 53, 58 Directory name • 80
Building a list • 34 DO - WHILE loop • 57
Built-in functions • 60 Decision making in macros • 13
T
Tips for programming macros • 92
Trouble shooting macros • 92
Type conversion functions • 83