Share

Tips for programming macros

This section gives tips to help you record macros.

  • Macros record any values you explicitly change in a dialog, but do not record the current default values. For example, if the default tolerance is 0.1 mm and you want a tolerance 0.1 mm, you must re-enter 0.1 in the tolerance field during recording. Otherwise PowerMill uses the current tolerance value, which is not necessarily the value you want.

  • Click File tab > Options > Reset forms. This ensures that PowerMill uses the default parameters in the dialogs.

  • When debugging a macro it is important to have the macrofixer turned off. Use the command:

      UNSET MACROFIX

    This ensures all syntax and macro errors are reported by PowerMill directly. You can use SET MACROFIX to turn it back on.

  • If you get a syntax error in a loop (DO-WHILE, WHILE, FOREACH) or a conditional statements (IF-ELSEIF-ELSE, SWITCH) check you have a space before any opening braces ({). For a DO-WHILE loop make sure the closing brace (}) has a space after it and before the WHILE keyword.

  • To exit a loop, press ESC.

  • Your code blocks must have matching braces. They must have the same number of opening braces ({) as closing braces (}).

  • The ELSEIF keyword does not have a space between the IF and the ELSE.

  • If you encounter expression errors check you have balanced parentheses, and balanced quotes for strings.

  • Decimal points in numbers must use a full stop (.) and not a comma (,).

  • The variable on the left of the = sign in assignments must have a $ prefix. So:

      $myvar = 5

    is correct, but:

      myvar = 5

    is wrong as it is missing the $ prefix.

  • Local variables override PowerMill parameters. If your macro contains:

      REAL Stepover = 10

    then during the execution of the macro any use of Stepover uses the value 10 regardless of what the value specified in the user interface. Also the command:

      EDIT PAR "Stepover" "Tool.Diameter*0.6"

    changes the value of this local Stepover variable NOT the PowerMill Stepover parameter.

Was this information helpful?