40 1 3MB
Post Building Techniques Student Guide October 2011 MT11060 — Post Builder 8.0
Publication Number mt11060_s — NX 8 — Copyright 2011 Siemens PLM Software
Proprietary and restricted rights notice
This software and related documentation are proprietary to Siemens Product Lifecycle Management Software Inc. © 2011 Siemens Product Lifecycle Management Software Inc. All Rights Reserved. Siemens and the Siemens logo are registered trademarks of Siemens AG. NX is a trademark or registered trademark of Siemens Product Lifecycle Management Software Inc. or its subsidiaries in the United States and in other countries. All other trademarks, registered trademarks or service marks belong to their respective holders
2
Post Building Techniques – Student Guide
mt11060_s — NX 8 — Copyright 2011 Siemens PLM Software
Contents
Proprietary and restricted rights notice . . . . . . . . . . . . . . . . . . . . . . 2 Course overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9 Course objectives . . . . . . . . . . Prerequisites . . . . . . . . . . . . . How to use this manual . . . . . Lesson format . . . . . . . . . . Learning tips . . . . . . . . . . Classroom system information
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. 9 10 11 11 11 12
The NX Post postprocessor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-1 Postprocessing in NX . . . . . . . . . . . . . . NX Post . . . . . . . . . . . . . . . . . . . . . . . . Manufacturing Output Manager (MOM) Using Post Builder . . . . . . . . . . . . . . . . Summary: The NX Post postprocessor .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
1-2 1-3 1-5 1-6 1-8
Build a postprocessor with Post Builder . . . . . . . . . . . . . . . . . . . . . 2-1 Files created by Post Builder . . . . . . . . . . . Activity: Classroom preparation . . . . . . . . . NX/Post Builder dialog box overview . . . . . . Defining a new postprocessor . . . . . . . . . . . Define a new main post . . . . . . . . . . . . . . . Add a new post to the NX menu . . . . . . . . . Activity: Introduction to Post Builder . . . . . Defining and editing main post processors . Machine Tool tab . . . . . . . . . . . . . . . . . . . . General parameters . . . . . . . . . . . . . . . . . . Mill specific parameters . . . . . . . . . . . . . . . Activity: Machine tool parameters . . . . . . . Program & Tool Path tab . . . . . . . . . . . . . . Activity: Word summary . . . . . . . . . . . . . . Program & Tool Path tab continued . . . . . . The Program tab interface . . . . . . . . . . . . . Program tab — program sequence structure Using the Program tab . . . . . . . . . . . . . . . . Activity: Program and tool path parameters NC Data Definitions . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . .
. 2-2 . 2-4 . 2-5 . 2-6 . 2-7 . 2-8 2-10 2-11 2-12 2-13 2-15 2-16 2-17 2-20 2-21 2-23 2-24 2-26 2-27 2-28
Post Building Techniques – Student Guide
3
Contents
Block tab . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Word tab . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Format tab . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Activity: NC Data Definitions tab . . . . . . . . . . . . . Create new M or G code groups . . . . . . . . . . . . . . Activity: Create a new group of coolant codes . . . . Output Settings tab . . . . . . . . . . . . . . . . . . . . . . . Listing File tab . . . . . . . . . . . . . . . . . . . . . . . . . . Other Options tab . . . . . . . . . . . . . . . . . . . . . . . . Activity: Output settings . . . . . . . . . . . . . . . . . . . Post Files Preview tab . . . . . . . . . . . . . . . . . . . . . Post Files Preview property page . . . . . . . . . . . . . Summary: Build a postprocessor with Post Builder
. . . . . . . . . . . . .
. . . . . . . . . . . . .
. . . . . . . . . . . . .
. . . . . . . . . . . . .
. . . . . . . . . . . . .
. . . . . . . . . . . . .
. . . . . . . . . . . . .
. . . . . . . . . . . . .
. . . . . . . . . . . . .
. . . . . . . . . . . . .
. . . . . . . . . . . . .
. . . . . . . . . . . . .
. . . . . . . . . . . . .
. . . . . . . . . . . . .
. . . . . . . . . . . . .
. . . . . . . . . . . . .
2-30 2-34 2-37 2-40 2-41 2-42 2-43 2-44 2-45 2-50 2-51 2-52 2-53
Units-only subposts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-1 Defining and editing units-only subposts . . . . . . . . . . . . . . . . . . . . . . . . 3-2 Activity: Create a units-only subpost . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-4 Summary: Units-only subposts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-5 Post Builder for Wire EDM applications . . . . . . . . . . . . . . . . . . . . . 4-1 Creating 2-axis and 4-axis wire EDM postprocessors Wire EDM specific parameters . . . . . . . . . . . . . . . . Activity: Create a 2-axis Wire EDM post . . . . . . . . . Summary: Post Builder for Wire EDM applications .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
4-2 4-3 4-4 4-5
Post Builder for 4-axis and 5-axis mills . . . . . . . . . . . . . . . . . . . . . . . 5-1 Creating 4-axis and 5-axis mill postprocessors Mill Fourth Axis and Fifth Axis parameters . . Rotary Axis Configuration dialog box . . . . . . . Activity: Create a 5-axis Mill post . . . . . . . . . . Summary: Post Builder for 5-axis mills . . . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. 5-2 . 5-3 . 5-6 . 5-9 5-10
Post Builder for lathe applications . . . . . . . . . . . . . . . . . . . . . . . . . . 6-1 Creating lathe postprocessors . . . . . . . . . . . . 2-axis lathe-specific parameters . . . . . . . . . . Activity: Create a lathe post . . . . . . . . . . . . . Summary: Post Builder for lathe applications
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
6-2 6-3 6-5 6-6
Create Mill-Turn postprocessors . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-1 Create a mill-turn post . . . . . . . . . . . . . . . . . . . . Activity: Create a Mill-Turn postprocessor . . . . . Define heads for mill-turn centers . . . . . . . . . . . . Activity: Create a 5-axis multi-link mill-turn post Summary: Create Mill-Turn postprocessors . . . . 4
Post Building Techniques – Student Guide
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
7-2 7-3 7-4 7-6 7-7
mt11060_s — NX 8 — Copyright 2011 Siemens PLM Software
Contents
Tcl basics for Post Builder . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-1 Tcl . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Tcl command structure . . . . . . . . . . . . . . . . . . Tcl variables . . . . . . . . . . . . . . . . . . . . . . . . . Value of variables . . . . . . . . . . . . . . . . . . . . . . Scope of variables . . . . . . . . . . . . . . . . . . . . . . Arrays of variables . . . . . . . . . . . . . . . . . . . . . Working with variables . . . . . . . . . . . . . . . . . Additional variable substitution examples . . . Determining set variables . . . . . . . . . . . . . . . Tcl control of word structure . . . . . . . . . . . . . . Tcl special characters . . . . . . . . . . . . . . . . . . . Tcl mathematical expressions . . . . . . . . . . . . . Activity: Tcl basics . . . . . . . . . . . . . . . . . . . . . Tcl scripts . . . . . . . . . . . . . . . . . . . . . . . . . . . Tcl procedures . . . . . . . . . . . . . . . . . . . . . . . . Explicitly returning a value from a procedure . Intermediate-level use of the return command Basic error handling . . . . . . . . . . . . . . . . . . . . Tcl input and output . . . . . . . . . . . . . . . . . . . Working with files in Tcl . . . . . . . . . . . . . . . . . Tcl string commands . . . . . . . . . . . . . . . . . . . Activity: Construct a simple procedure . . . . . . Program flow control . . . . . . . . . . . . . . . . . . . Activity: Program flow control . . . . . . . . . . . . Regular expressions . . . . . . . . . . . . . . . . . . . . Tcl and NX . . . . . . . . . . . . . . . . . . . . . . . . . . . Tcl reference manuals . . . . . . . . . . . . . . . . . . Summary: Tcl basics for Post Builder . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . . . .
. 8-2 . 8-3 . 8-6 . 8-7 . 8-8 . 8-9 8-10 8-11 8-12 8-13 8-14 8-15 8-17 8-18 8-19 8-22 8-22 8-23 8-24 8-30 8-37 8-40 8-41 8-49 8-50 8-53 8-54 8-55
Custom commands . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9-1 Custom Command tab . . . . . . Importing custom commands . Activity: Custom commands . . Summary: Custom commands
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
9-3 9-4 9-5 9-6
User defined events and user defined cycles . . . . . . . . . . . . . . . . . 10-1 User-defined events . . . . . . . . . . . . . . User Defined Cycles . . . . . . . . . . . . . . User-defined event .cdl file . . . . . . . . . Keywords in the .cdl file . . . . . . . . . . . Enabling the UDE Editor . . . . . . . . . . Create a UDE or UDC in Post Builder Create an event handler . . . . . . . . . . . View event handler Tcl code . . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
. 10-2 . 10-5 . 10-6 . 10-7 . 10-9 10-10 10-11 10-13
Post Building Techniques – Student Guide
5
Contents
View an event in the .cdl file . . . . . . . . . . . . . . . . . . . . . . . . . . . Add user defined events to the NX Manufacturing environment UDE dialog box graphic requirements . . . . . . . . . . . . . . . . . . . Activities: User defined events and user defined cycles . . . . . . . Summary: User-defined events and user-defined cycles . . . . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
10-14 10-15 10-18 10-19 10-20
Virtual NC controller . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11-1 Integrated simulation and verification overview Machine Tool Driver . . . . . . . . . . . . . . . . . . . . . VNC work flow . . . . . . . . . . . . . . . . . . . . . . . . . Activity: Use Post Builder to create a VNC . . . . Axes, junctions, and zero reference . . . . . . . . . . Summary: Virtual NC Controller . . . . . . . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. 11-2 . 11-3 . 11-5 . 11-7 . 11-8 11-11
Postprocessing with a Siemens controller . . . . . . . . . . . . . . . . . . . 12-1 Sinumerik template posts . . . . . . . . . . . . . . . . . . . Events and cycles for Sinumerik controllers in NX Procedures and settings . . . . . . . . . . . . . . . . . . . . Activity: Postprocess with a Siemens controller . . Summary Siemens controller support . . . . . . . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
12-2 12-3 12-5 12-6 12-7
Create a macro with Post Builder . . . . . . . . . . . . . . . . . . . . . . . . . . 13-1 Macro tab . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13-2 Activity: Create a macro with Post Builder . . . . . . . . . . . . . . . . . . . . . . 13-5 Summary: Create a macro with Post Builder . . . . . . . . . . . . . . . . . . . . 13-6 Project activities . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14-1 A guide to best practices of building a postprocessor . . . . . . . . . . A-1 Appendix: Checklist of information . . . . . . . . . . . . . . . . . . . . . . . . B-1 Appendix: Supermill technical document . . . . . . . . . . . . . . . . . . . C-1 UGS Supermill . . . . . . . . . . . . . Milling options . . . . . . . . . . . . . Tool Length pre-setting options Chip Conveyor . . . . . . . . . . . . . Dust removal system (vacuum) . Measurement options . . . . . . . . Specialized application software Supermill CNC options . . . . . . . Programming functions . . . . . . Milling accessories . . . . . . . . . . Services . . . . . . . . . . . . . . . . . . 6
Post Building Techniques – Student Guide
. . . . . . . . . . .
. . . . . . . . . . .
. . . . . . . . . . .
. . . . . . . . . . .
. . . . . . . . . . .
. . . . . . . . . . .
. . . . . . . . . . .
. . . . . . . . . . .
. . . . . . . . . . .
. . . . . . . . . . .
. . . . . . . . . . .
. . . . . . . . . . .
. . . . . . . . . . .
. . . . . . . . . . .
. . . . . . . . . . .
. . . . . . . . . . .
. . . . . . . . . . .
. . . . . . . . . . .
. . . . . . . . . . .
. . . . . . . . . . .
. . . . . . . . . . .
. . . . . . . . . . .
. . . . . . . . . . .
. . . . . . . . . . .
. . . . . . . . . . .
. . . . . . . . . . .
. . . . . . . . . . .
. . . . . . . . . . .
. . . . . . . . . . .
. . . .
C-2 C-5 C-8 C-9 C-10 C-11 C-12 C-13 C-14 C-18 C-19
mt11060_s — NX 8 — Copyright 2011 Siemens PLM Software
Contents
Index . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Index-1
Post Building Techniques – Student Guide
7
Course overview
The Post Building Techniques course acquaints users with tools and techniques that are used for building custom, machine tool specific post processors using the Post Builder application. For those post processors that cannot be fully developed using the Post Builder application, methods are shown for customizing and modifying the definition and event handler files, used by NX Post for specific needs. Intended Audience This course is suited for designers, engineers, manufacturing engineers, application programmers, NC programmers, CAD/CAM managers, and system managers who have a need to build posts for NC programming.
Course objectives After successfully completing this course, you will be able to: •
Build a postprocessor with Post Builder.
•
Define a units-only subpost for existing postprocessors.
•
Create an M-Code group.
•
Create posts Wire EDM, 5-Axis Mill, Lathe, and Mill Turn machines.
•
Make basic Tcl edits.
•
Create user-defined events (UDE) and user-defined cycles.
•
Use Post Builder to create a virtual NC controller (VNC).
Post Building Techniques – Student Guide
9
Course overview
Prerequisites Required courses •
NX Manufacturing Fundamentals
Working knowledge of the following:
10
•
Fixed and Multi-Axis Machining, or Turning Manufacturing Process.
•
A thorough understanding of NC/CNC programming principles and a thorough understanding of NC/CNC machine/controller functionality.
•
Successful completion of Essentials for Designers, or prerequisite assessment on Learning Advantage site (score >70%). Learning Advantage courses can also be used to prepare for the prerequisite assessment.
•
An understanding of basic programming principles such as conditional statements, variables, and procedures is needed to be successful with postprocessor customizing, although not required for the class. Familiarity with the Tcl language is recommended, but not required.
Post Building Techniques – Student Guide
mt11060_s — NX 8 — Copyright 2011 Siemens PLM Software
Course overview
How to use this manual The following guidelines describe how you can get the most benefit from your use of the course guide and the accompanying HTML activities.
Lesson format The general format for lesson content is: •
Instructor presentation
•
One or more activities
•
Project Projects allow you to test your new skills without detailed instruction. Consult your instructor for additional information.
•
Summary
Learning tips •
Ask questions.
•
Take notes.
•
Confirm important facts by restating them in your own words. Because later lessons often build on functionality taught in earlier lessons, it is important that you follow the lessons in the sequence in which they appear in the Student Guide.
Post Building Techniques – Student Guide
11
Course overview
Classroom system information Your instructor will provide the following items for working in the classroom: Student login: User name:
Password:
Work directory:
Parts directory:
Instructor:
12
Post Building Techniques – Student Guide
mt11060_s — NX 8 — Copyright 2011 Siemens PLM Software
1
Lesson
1
The NX Post postprocessor
Purpose This lesson describes the postprocessing function of NX and the various components of a postprocessor. An overview of the Post Builder module is also presented. Objective Upon completion of this lesson, you will be able to: •
Understand the terminology and interrelationships of the various components of NX Post.
•
Understand the use of the Post Builder as a tool to build postprocessors.
Post Building Techniques – Student Guide
1-1
The NX Post postprocessor
1
Postprocessing in NX Each machine tool and controller combination has different requirements, for example tool change commands, specific M-codes and G-codes, and the sequence of G-codes that is permitted in a program line. Postprocessing is the process of outputting machine code so that your tool path is recognized by a machine tool and controller combination. Before you can postprocess a tool path in NX, you must create the tool path in NX and create an appropriate post processor in NX Post Builder. A tool path consists of the following: •
Information about tool motion, such as GOTO points and feed rates.
•
Instructions to the controller, for example, coolant and spindle control, called events.
The NX postprocessor, referred to as NX Post, consists of the following:
1-2
•
Instructions to generate code words that control the machine tool’s response to events.
•
Definitions of how to sequence and format the output words.
•
Instructions to Post Builder so that can recreate the graphic interface for your post when you edit it.
Post Building Techniques – Student Guide
mt11060_s — NX 8 — Copyright 2011 Siemens PLM Software
The NX Post postprocessor
1
NX Post NX Post is a set of programs and files that you use in the Manufacturing application to post process NX tool paths with posts define by the NX Post Builder. You can start NX Post by the following means: •
Right-click a selected program or operation nodes in the Operation Navigator and choose Post Process.
•
Select one or more programs or operations and click Post Process on the Operations toolbar.
NX Post uses tool path data as input, and outputs machine controller readable CNC code. You can customize your postprocessors in several ways to generate the output that you require for several supported machine tool categories, including the following: •
Mills
•
Lathes
•
Production Centers, or machines that both turn and mill
•
Wire EDM machines
The extensibility of NX Post processors is achieved through the scripting language Tcl and the use of definition files.
Post Building Techniques – Student Guide
1-3
The NX Post postprocessor
1
The following flowchart illustrates the steps required to postprocess tool path data in an acceptable format for a machine tool and controller. NX Post architecture
NX tool path data
Format definition file — .def element of post processor
Event generator
.pui element of post processor — used only when you edit the post
NX Post and Manufacturing Output Manager (MOM)
Tcl procedure library — ugpost_base.tcl
Event handler — .tcl element of the post processor
Output — typically, .ptp machine tool executable file and optional .lst listing file
The event generator, event handler, and the definition file are interdependent.
1-4
Post Building Techniques – Student Guide
mt11060_s — NX 8 — Copyright 2011 Siemens PLM Software
The NX Post postprocessor
1
Manufacturing Output Manager (MOM) The Manufacturing Output Manager, or MOM, is a utility program used by NX Post to use tool path data to generate output. NX Post uses the MOM to do the following. •
Start the interpreter.
•
Add data and specify functions to the interpreter.
•
Load Event Handlers.
•
Load Definition files.
Post Building Techniques – Student Guide
1-5
The NX Post postprocessor
1
Using Post Builder Post Builder is an application that provides a graphical user interface for building posts. Post Builder allows you define many aspects of output, including the following: •
Types of output blocks and word addresses.
•
Sequence of output for the following: o
Start of program
o
Start of operation
o
End of operation
o
End of program
o
Tool changes
o
Canned cycles
One of the outputs of the Post Builder program is a Tool Command Language (Tcl) script file. With knowledge of the Tcl language, you can extensively customize Tcl scripts. Post Builder currently configures postprocessors for the following: •
3-axis milling machines
•
3-axis mill-turn centers (XZC)
•
Multi-axis mill-turn centers
•
4-axis milling machines with a rotary table or a rotary head
•
5-axis milling machines with dual rotary heads or rotary tables
•
5-axis milling machines with rotary head and rotary table
•
2-axis lathes
•
2 and 4-axis Wire EDM machines.
A controller library is provided, with support for several popular controllers, including Siemens Sinumerik controllers. 1-6
Post Building Techniques – Student Guide
mt11060_s — NX 8 — Copyright 2011 Siemens PLM Software
The NX Post postprocessor
1
The following flowchart illustrates the process of building a postprocessor using Post Builder: Post processor development process
Gather machine tool specifications and controller parameters from manufacturer manuals Enter parameters in Post Builder
Test the postprocessor output Deliver the functional post processor
Post Building Techniques – Student Guide
1-7
The NX Post postprocessor
1
Summary: The NX Post postprocessor In this lesson you were introduced to:
1-8
•
Post processing with NX Post.
•
The function of NX Post components.
•
Relationships between NX Post components.
Post Building Techniques – Student Guide
mt11060_s — NX 8 — Copyright 2011 Siemens PLM Software
Lesson
2
Build a postprocessor with Post Builder
2
Purpose This lesson describes the procedures of building postprocessors through the use of the Post Builder . Objective Upon completion of this lesson, you will be able to: •
Understand the various components of Post Builder.
•
Use Post Builder to build a 3-axis mill postprocessor. Post processor development process
Gather machine tool specifications and controller parameters from manufacturer manuals. Enter parameters in Post Builder.
Test output
Functional post processor.
Post Building Techniques – Student Guide
2-1
Build a postprocessor with Post Builder
Files created by Post Builder By default, Post Builder creates all related files for your postprocessor in the directory where you started Post Builder.
2
To use your postprocessor from the menus in NX you must add an entry to your template_post.dat file in your current postprocessor directory. You can modify and verify example posts for your specific needs. You must obtain a WebKey user name and password to access the sites: http://ftp.ugs.com/unigraphics/pb_posts/ http://webtest.industrysoftware.automation.siemens.com/ WebkeyLogin/Authenticate2?url=http://plmwebtest.industrysoftware. automation.siemens.com/postcatalog/index.jsp Files always created Post processors that you create with Post Builder have three main files. If your postprocessor name is my_machine_tool, the files created when you save your post are as follows: my_machine_tool.pui Contains information needed to create the .tcl file. This file must be present in the same directory as the .tcl and .def files and is refereneced when you edit your postprocessor. my_machine_tool.tcl NX Post uses this Tcl-language file to generate NC code blocks for events. my_machine_tool.def This file defines machine tool information such as word formats, addresses, and NC blocks. NX Post uses this file to format the output for events that are processed in the Tcl file.
2-2
Post Building Techniques – Student Guide
mt11060_s — NX 8 — Copyright 2011 Siemens PLM Software
Build a postprocessor with Post Builder
Other files my_machine_tool.cdl Appears when you create a user-defined event or a user-defined cycle. Contains the definition of a dialog box that appears when you add the event from NX. The dialog box is used to gather user input parameters to control your event or cycle. my_machine_tool_vnc.tcl Appears when you select the option to create a virtual NC controller or VNC. Contains the Tcl code needed to support simulation using machine tool driver (MTD) Tcl-based simulation.
Post Building Techniques – Student Guide
2-3
2
Build a postprocessor with Post Builder
Activity: Classroom preparation For the activities in this course, you will use a copy of the CAM folder where postprocessor-related files are stored.
2
You can experiment with Post Builder with no worries about write access or of corrupting system files. The following activity in the Build a postprocessor with Post Builder section will guide you through copying the folder from its installed location to your home folder: •
2-4
Classroom preparation
Post Building Techniques – Student Guide
mt11060_s — NX 8 — Copyright 2011 Siemens PLM Software
Build a postprocessor with Post Builder
NX/Post Builder dialog box overview Use the NX/Post Builder dialog box to do the following: •
Define a new post processor in the Create New Post Processor dialog box.
•
Edit an existing post processor.
•
Manage the available forms of help for the other dialog boxes.
The dialog box contains only a menu bar, toolbar, and a cue line. Other dialog boxes appear as you perform tasks related to post processor definition. When you open the Create New Post Processor dialog box or the editing dialog box, the cue line continues to show suggestions about the task related to the page that you are displaying in the other dialog boxes.
Where do I find it? Menu
Start®All Programs®Siemens NX 8.0®Manufacturing Tools®Post Builder
Post Building Techniques – Student Guide
2-5
2
Build a postprocessor with Post Builder
Defining a new postprocessor Use the New command in the Post Builder application to define the following:
2
•
The name and description of your new post processor.
•
The type of post to be created: Main Post or Units Only Subpost
•
The default output units
•
The type of machine tool for which the post is intended
•
The controller information
You can also choose to enable the user defined event editor and user cycle editing by default anytime the post is opened for edit.
2-6
Post Building Techniques – Student Guide
mt11060_s — NX 8 — Copyright 2011 Siemens PLM Software
Build a postprocessor with Post Builder
Define a new main post 1. In the NX/Post Builder dialog box, click New
.
2
2. In the Create New Post Processor dialog box, select Main Post. 3. Under Machine Tool, select the type of machine. For example, you can select Mill for any supported milling machine. 4. Specify the configuration for your machine tool. For example: If the machine is a mill, you could select 4–Axis with Rotary Head. If the machine is a lathe, the only option is 2–Axis. If the machine is a wire EDM, you could select 4-Axis. After you click OK in this dialog box, you cannot change the machine type for the post processor. 5. (Optional) Modify the default description to describe your machine tool in greater detail. You can access the description by choosing File®Post Properties in the NX/Post Builder dialog box while the post processor is open for editing. 6. In the Name box, type a name for your post processor. You can also temporarily accept the default name, new_post, and assign a name the first time you save the post processor. 7. Specify the default output units. You may find it convenient to use the units presented in the machine manual. For example, if values in the manual are in inches, you can define the machine using inch values. After you save the post processor, you can create a units-only subpost to output millimeters. If a millimeter subpost is defined and linked to an inch post processor, it is used automatically whenever millimeter output is required. 8. Click OK to create the post processor in computer memory and open it for edit.
Post Building Techniques – Student Guide
2-7
Build a postprocessor with Post Builder
Add a new post to the NX menu You can always browse to your post in NX. If you use a post frequently, you can add it to the list of available postprocessors that appears in the Postprocess dialog box in NX, and you can position it in the list, using the Edit Template Posts Data File dialog box.
2
1. In the NX/Post Builder dialog box, choose Utilities®Edit Template Posts Data File. 2. In the Install Posts dialog box, make certain that the path in the Template points to the template_post.dat file that is in the Posts Data File box folder pointed to by your UGII_CAM_RESOURCE_DIR variable.
If the path is not correct, click Browse
and navigate to the correct file.
3. In the editing window, select the post before which you want your new post to appear.
4. Click New. 5. In the Open dialog box, navigate to your new post, select it, and click Open.
2-8
Post Building Techniques – Student Guide
mt11060_s — NX 8 — Copyright 2011 Siemens PLM Software
Build a postprocessor with Post Builder
6. (Optional) If you want to reorder the list of posts, use the Cut and Paste buttons. When you paste a line, it is always inserted before a selected line in the file. The Edit button allows you to modify the path and file name of a post entry in the list of available post processors. Use it only if you have renamed or moved a post.
7. Click OK to save and close the edited file..
Post Building Techniques – Student Guide
2-9
2
Build a postprocessor with Post Builder
Activity: Introduction to Post Builder In the Build a postprocessor with Post Builder section, do the following activity:
2
•
2-10
Introduction to Post Builder
Post Building Techniques – Student Guide
mt11060_s — NX 8 — Copyright 2011 Siemens PLM Software
Build a postprocessor with Post Builder
Defining and editing main post processors The dialog box to define and edit a post processor shows the name of the currently open post processor in its title bar.
2
The following main tabs are available: Machine Tool
Lets you display a generic view of the machine tool, set basic kinematic parameters of the machine tool, and set or modify some basic controller capabilities, such as whether to output circular records.
Program & Tool Path
Lets you add code blocks and words, set the format and sequencing for controller words, managed linked posts, and more.
N/C Data Definitions
Lets you modify blocks, words, formats, and word formats; attach user defined event files; and inherit user defined events from other posts.
Output settings
Lets you manage listing file output and listing file content, attach units-only subposts, and more.
Virtual N/C Controller
Lets you configure a virtual numeric controller. Output is compatible only with the Tcl-based machine tool driver, or MTD.
Post Building Techniques – Student Guide
2-11
Build a postprocessor with Post Builder
Machine Tool tab The Machine Tool tab has options that allow you to configure the kinematics of your machine tool. You can define the limits and direction of axis movements, orientations where applicable, axis multipliers, traversal feed rate, and so on.
2
The machine tool configuration tree can be divided in as many as 3 sections, depending on the selected machine tool configuration. Configuration General Parameters
Available for…
Fourth Axis
All machines 4-axis and 5-axis mills
Fifth Axis
5-axis mills
Default and Restore The Default button returns you to the state when the post was last saved for the current tab. The Restore button returns you to the state when you entered the current tab.
2-12
Post Building Techniques – Student Guide
mt11060_s — NX 8 — Copyright 2011 Siemens PLM Software
Build a postprocessor with Post Builder
General parameters The following options are available for all machine types.
2
Display Machine Tool Click Display Machine Tool to visualize an approximation of your machine tool. You can verify axis orientations. For a four and five axis milling machine you see the address designation, A, B or C, and the current limit settings for each rotary axis. Pictures are not available for mill-turn and wire-EDM configurations. Output Circular Record You can set this option to Yes or No. If set to Yes, the system outputs all circles based on the circle motion parameters. If set to No the system does not output circle blocks (G2 or G3). Circular record output also depends on the Default Coordinate Mode and Circular Record Mode settings. Default Coordinate Mode Circular Record Mode setting setting Polar Polar Cartesian Cartesian Cartesian Polar Polar Cartesian
Output Polar circles Cartesian circles No circle output No circle output
Linear Axis Travel Limit This option allows you to check travel limits when you import the custom command pb_cmd_check_travel_limits.tcl. Home Position This defines the default FROM position if you have not specified a FROM position. Linear Motion Resolution This defines the minimum value to which the system rounds all coordinates. This does not necessarily control the format of the coordinate data. To control the format of the coordinate data you must change the number of decimal digits output.
Post Building Techniques – Student Guide
2-13
Build a postprocessor with Post Builder
Traversal Feed Rate This defines the feed rate that the system uses to calculate machine time for rapid motion. The system also uses this value to determine if a linear feed rate move is actually performed at rapid.
2
2-14
Post Building Techniques – Student Guide
mt11060_s — NX 8 — Copyright 2011 Siemens PLM Software
Build a postprocessor with Post Builder
Mill specific parameters Axis Multiplier Use Axis Multiplier with diameter programming for mill-turn postprocessors. Diameter Programming Use Diameter Programming to multiply the X and I words by two, so that they represent diameter instead of radius. Mirror X axis Use Mirror X axis to program your part in the fourth quadrant and output it in the first quadrant. X and I words are multiplied by minus one. Use Mirror Z axis to multiply the Z and K words by minus one. Initial Spindle Axis Specify a value for Initial spindle Axis to set the default spindle axis, which determines the initial work-plane of the machine tool.
Post Building Techniques – Student Guide
2-15
2
Build a postprocessor with Post Builder
Activity: Machine tool parameters In the Build a postprocessor with Post Builder section, do the following activity:
2
•
2-16
Machine tool parameters
Post Building Techniques – Student Guide
mt11060_s — NX 8 — Copyright 2011 Siemens PLM Software
Build a postprocessor with Post Builder
Program & Tool Path tab The Program &Tool Path tab has options that allow you to determine the NC output for specific events and commands that are generated by the NX Event Generator. The tabs under this option control the content, format and order of output for your NC Code.
Use the Program and Tool Path tab to create, modify, and customize of event handlers. The Program and Tool Path tab is divided into the following tabbed pages: Program Lets you create, modify, or customize program start sequences, operation start sequences, tool path events including machine control events, motion events, canned cycles events, operation end sequences and program end sequences. G Codes Lets you specify G-codes throughout the postprocessor. Changing any G-code in this list updates the G-code globally. M Codes Lets you specify M-codes throughout the postprocessor. Changing any M-code in this list updates the M-code globally. Word Summary Lets you modify groups of words that have the same format, such as G17, G18, and G19, or X, Y, and Z. To specify a different format for only one word in a group, use the Format tab on the NC Data Definitions tab. The following parameters appear on the Word Summary tab: Word Contains the system’s symbol for the word. This name is the same name that you find in the word address section of the N/C Data Definitions section.
Post Building Techniques – Student Guide
2-17
2
Build a postprocessor with Post Builder
Leader/Code Lets you modify the leader for any word. The leader is the character than precedes the numeric information. For instance, if the word is X12.345, then the leader is X. You can either type in a new leader or right click on the existing leader and choose from the list.
2
Data Type Lets you specify numeric or text. Usually NC code is numeric. Specify text when the code you need cannot be formatted from a number directly into a word address and a value. For example, if you need a G84.1 for tapping and G81 (without a decimal) for drilling. In this case you have to make the G_motion word text, and change all the G codes to G81 as text, instead of the number 81 with G as the leader. You can use the Format tab on the N/C Data Definitions tab to make the change. Plus (+) Lets you output a plus sign for all positive numbers. If you set this option to No you get an X1.0. If you set this to yes, you get an X+1.0. You always get a minus sign for all numeric data if the specified number is negative. Lead Zero Lets you define whether or not you output leading zeroes with your N/C Code. Integer Controls the number of digits that are output to the left of the decimal point. You get an error if your numeric data exceeds the format you have specified. Decimal (.) Controls whether or not numeric data is output with a decimal point. You get an error if you suppress the decimal point and do not output at least leading or trailing zeroes.
2-18
Post Building Techniques – Student Guide
mt11060_s — NX 8 — Copyright 2011 Siemens PLM Software
Build a postprocessor with Post Builder
Fraction Determines how many digits are output to the right of the decimal point. Trail Zero Lets you define whether or not you output trailing zeroes with your N/C Code.
Post Building Techniques – Student Guide
2-19
2
Build a postprocessor with Post Builder
Activity: Word summary In the Build a postprocessor with Post Builder section, do the following activity:
2
•
2-20
Word summary
Post Building Techniques – Student Guide
mt11060_s — NX 8 — Copyright 2011 Siemens PLM Software
Build a postprocessor with Post Builder
Program & Tool Path tab continued Word Sequencing Lets you customize the output order of controller words. For example, if you exchange the X and Y words, all blocks generated by all events reflect the change. You can also suppress or make any word active. If Balloon Help is active, each word displays its context in the balloon help. A representative code is used to display word groups. For example, the G17 word also represents the sequencing of G18 and G19. Custom Command Lets you add user-created custom commands as Tcl procedures that you can place with any event marker in the post. With syntax checking set to on, you cannot create a Tcl procedure that is syntactically incorrect; however, there is no checking of details within custom procedures. Several useful custom commands are provided with your default post. You can import additional custom commands from a library of custom commands. Numerous custom commands, designed for common special applications, are supplied with every release of Post Builder. When you create a custom command, the software places the correct syntax around the body of the procedure that you are creating. The first line of the Custom Command is: proc PB_CMD_name_of_proc {} {
The content goes between the braces, and the last line shows the closing brace: }
Custom procedures are processed in the sequence where you place them. Linked Posts Lets you specify posts that can be linked to your current post. Linked posts are used in situations where separate posts have been developed for special machine options such as right angle milling heads, specialized mill-turn centers, machining centers having more than two rotary axis or any application that requires multiple Postprocessors. You need to assign a HEAD UDE to the program or method group that indicates the post to be used to process the head. There is a table where you can specify a minor word after the HEAD command, or head name, to identify the post.
Post Building Techniques – Student Guide
2-21
2
Build a postprocessor with Post Builder
Macro Use this tab to create, edit, or remove block templates for making calls to macro, cycle, or functions in the NC program. The output codes are in the form of cycle or macro calls, such as CYCLE81(...) for the Sinumerik 840D controller or CYCLE DEF 204 A200=... for the Heidenhain iTNC530 controller, or other similar high level function calls.
2
2-22
Post Building Techniques – Student Guide
mt11060_s — NX 8 — Copyright 2011 Siemens PLM Software
Build a postprocessor with Post Builder
The Program tab interface When you select a sequence on the left, the parameters associated with the sequence are is displayed on the right.
2
Program sequence tree Add Block Display Combined N/C Code Blocks New block Trash can
Sequence marker Sequence blocks Normal block MOM command or custom command Operator message Custom macro
Blocks with a light blue background, like PB_CMD_tool_change_force_addresses in the graphic, are used by more than one marker. Changing one instance affects all instances of the block. Blocks with a white background are used only once in the post.
Post Building Techniques – Student Guide
2-23
Build a postprocessor with Post Builder
Program tab — program sequence structure Due to the way that tool paths are created in NX, certain events, such as tool change, spindle start, or approach motion events, can occur at the start and end of an NC program and for each operation.
2
Understanding the sequences and the events that trigger them allow you to properly place custom commands and blocks to obtain the desired output. At the markers of these predetermined events, designated by yellow rectangular blocks, you can force instruction blocks to be output. This output combination is referred to as a sequence. The program sequence tree contains the following: Program Start Sequence Determines the code blocks that are output when the program start event occurs, before any other event is processed. Operation Start Sequence Determines events and actions that will occur from the start of an operation to the first cut motion. Every operation has one of the following: first tool change, automatic tool change, manual tool change, or no tool change. Tool Path Sequence consist of Events and actions that pertain to machine control, motion control and canned cycles. You cannot drag new blocks into tool path sequences. Machine Control Controls machine tool features such as coolant, spindle, tailstocks and clamps. Can also be used to change modes such as incremental or absolute, inverse time, feed per minute or per revolution and constant surface speed. You can pass information to a postprocessor by parameter data which is available at the Start of Operation marker. This includes feeds and speeds and any cutting parameters such as stepover and tolerances. You can pass information within this and other tool path sequences by User Defined Events, or UDEs, which are sometimes called post commands. UDEs specified as Start of Post come out after the Start of Operation event in the order specified by operation markers, where markers indicate events that may occur. UDEs associated with the tool, program, method, or any other parent group are output before the Start of Operation event. The recommended method of output for start of operation NC code is to organize all of the data, such as 2-24
Post Building Techniques – Student Guide
mt11060_s — NX 8 — Copyright 2011 Siemens PLM Software
Build a postprocessor with Post Builder
spindle speed, spindle direction, coolant status, length compensation, and tool number, and then output this data as part of the Operation Start Sequence. Motion Controls how the postprocessor processes GOTO records in the tool path. Motion types included in this event type are cut, engage, first cut, stepover and side cut. Circular motion is handled by the Circle Move Event. An event type for Nurbs is currently handled by the Post Builder for Fanuc 6M, Siemens and Heidenhain controls. Canned Cycle Describes how the postprocessor handles canned cycles. You can define or modify the G-code, associated parameters, and output blocks that are used with pre-defined cycles, or, if UDE editing is enabled, you can create a used-defined cycle by right-clicking the background. Miscellaneous Controls suboperation start and end events. Operation End Sequence Contains events and actions that occur from the final retract motion to the end of the operation. These are items like returning to a home position or turning off the spindle and or coolant. If the same End of Operation function is always going to be performed at the end of every operation you can enter it into this sequence instead of programming UDEs. Program End Sequence Contains events and actions that occur from the end of the last operation to the end of the program.
Post Building Techniques – Student Guide
2-25
2
Build a postprocessor with Post Builder
Using the Program tab You can drag Add Block to add an available block selected in the list to the location where you want the output. You can place it above, below or next to an existing block component.
2
Selecting the Display Combined N/C Code Blocks check box displays all block components in the form of NC codes. By default, block components are displayed showing their descriptions. The Add Block component list shows available blocks. You can create a new block component and apply it to a sequence. You can also select one of the predefined block components.
To use the trash bin, drag an unwanted block to the trash bin icon. You can also delete the component by right-clicking it and choosing Delete. You can neither add or delete event blocks. You can create user-defined events. If you right-click the block component, a shortcut menu appears which allows you to perform the following actions:
2-26
•
Cut
•
Copy As
•
Paste
•
Delete
Post Building Techniques – Student Guide
mt11060_s — NX 8 — Copyright 2011 Siemens PLM Software
Build a postprocessor with Post Builder
Activity: Program and tool path parameters In the Build a postprocessor with Post Builder section, do the following activity: •
2
Program and tool path parameters
Post Building Techniques – Student Guide
2-27
Build a postprocessor with Post Builder
NC Data Definitions Use the NC Data Definitions tab to define output formats for NC data.
2 Words Words are the basic unit of data. Words are typically, but not always, a letter followed by one or more digits, for example, G01, X100.35, and M03 are typical words. We refer to the initial letter as the word address. You can select a word from a list by its group name and name. For example G_motion®G01–Linear Move, X®X–X Coordinate, or M_Spindle®M03–CLW Spindle Direction appear in lists. You can choose words from a tree diagram by their name. For example, G_motion, X, and M_Spindle appear in the word tree diagram. Word names in Post Builder sometimes refer to several possible releated controller words, for example, the following post words can identify several ontroller words: G_Cutcom – Cutcom(LEFT/RIGHT/OFF) can output G41, required by the event generated in the tool path.
G42,
M_Spindle – Spindle Direction(CLW/CCLW) can output required.
M03
or
or
G43,
M04,
as
as
Blocks Blocks consist of one or more words arranged in the context of a machine operation. The order of words in a block is set on the Word Sequencing tab. You can drop a word into a block anywhere, and it assumes the correct position. Blocks also have names that you can select from lists or tree diagrams. For example: The default cutcom_off block contains the single word G_cutcom – Cutcom Off and outputs G40 by default. The default absolute_mode block contains the words G_cutcom – Cutcom Off, G_plane – XY Plane Code, G_mode – Absolute Mode, and G – Output Unit (Inch/Metric), and the default output for a metric post is G40 G17 G90 G71. 2-28
Post Building Techniques – Student Guide
mt11060_s — NX 8 — Copyright 2011 Siemens PLM Software
Build a postprocessor with Post Builder
Formats Formats are also named and you can select a word format from a list or a tree diagram.
2
There are many default named formats such as Coordinate, Digit_2, and Tcode.
Post Building Techniques – Student Guide
2-29
Build a postprocessor with Post Builder
Block tab Use the Block tab to create and edit blocks. When you create a new block on this page, you are copying an existing block and editing it. You are limited to copying a single existing block. If you need more than one block for your function, you must create multiple blocks on the Program tab of the Program & Tool Path tab.
2
Creating a New Block You can create a new block in the following ways:
2-30
•
Drag a new block into a sequence on the Program tab of the Program & Tool Path tab.
•
Copy an existing block on the Block tab of the N/C Data Definitions tab.
Post Building Techniques – Student Guide
mt11060_s — NX 8 — Copyright 2011 Siemens PLM Software
Build a postprocessor with Post Builder
Editing new or existing blocks You can edit a block in the following ways: Add a new word Select applicable words from the list, and drag Add Word to the block.
2
Remove a word Drag unwanted words to the
icon, or right-click and choose Delete.
Modify a word Right-click a word and choose from the following actions: Edit Opens the dialog box to edit a word. Change Element Lets you swap the word for another word in the same group. For example, you can replace G17 with G18. Optional When a check-mark appears, the word is not output if a variable for the word is not defined, and there will not be an error message. Click the menu option to toggle it between selected and not selected. is required — there are no conditions turned on
G90
with the optional condition turned on
G90
No Word Separator When selected. omits the separator, for example a space character, before the word. Click the menu option to toggle it between selected and not selected. with the optional condition turned on P
with the optional and no word separator conditions turned on P
Post Building Techniques – Student Guide
2-31
Build a postprocessor with Post Builder
Force Output Available in blocks where output is not forced by the presence of the word. The word is output, regardless of modality, provided the optional setting does not inhibit the output.
2
with no conditions G41 with force output turned on turned on
G41
G41 with all conditions turned on
Delete Removes the word from the block. Preview a word format Examine the green box above the word parameter window to preview the format of the selected word. Restore a previous state Choose one of the following: Default Restores the block being edited to the state last saved with the post. Restore Restores the block being edited to the state it was in when you began the current edits. If you stop editing a block, edit something else, and come back to it later, Restore does not remove earlier edits in the session. When you right-click a word in a block, the menu contains a mixture of commands and status indicators, as described in the preceding paragraphs. The status of the three indicators is shown graphically by the word in the block, as described, and also by the presence of a check mark. In the following graphic, the Optional status indicator is checked, meaning that the optional output condition is turned on.
2-32
Post Building Techniques – Student Guide
mt11060_s — NX 8 — Copyright 2011 Siemens PLM Software
Build a postprocessor with Post Builder
New Address
2
Select New Address from the list and drag Add Word to a block. The WORD: user_add dialog box appears, where you can name the word, set the format, and identify the expression for which your word reflects the value. Text Select the Text option from the list and drag Add Word to a block. The Text Entry dialog box appears Existing Words Select the word that you want from the list. When you choose an existing word the current value for the associated variable is output. For example, if you choose X-Coordinate, the word is output with the current X position in the format defined for the word. You can specify a specific variable that you create using the User Defined Expression option that is available in every word group.
Post Building Techniques – Student Guide
2-33
Build a postprocessor with Post Builder
Word tab Use the Word tab to create and edit words. A word is composed of an address leader, a number, or text and a trailer.
2
You have the same options for editing a word as you do within the event or sequence dialogs. To create a new word or word group, you must copy an existing word or word group and edit the copy.
Format You can specify the format for a selected word in the following ways. •
Select from the list of currently defined named formats
•
Create a new format.
•
Edit an existing format and verify that the change does not compromise an existing word.
The green rectangle above the parameter input area shows a preview of the output word formatting.
2-34
Post Building Techniques – Student Guide
mt11060_s — NX 8 — Copyright 2011 Siemens PLM Software
Build a postprocessor with Post Builder
Leader and Trailer An address leader may be any characters. For NC code the address leader is usually a single letter such as G, M, or X. Leaders and trailers can be multiple characters such as A1=, B1=, C1=, and so on for Sinumerik 840D controllers. An example of leaders and trailers for some Siemens controls is the format for absolute output of circle centers with I, J, and K. G3 X-3.257 Y-47.45 I=AC(2.487) J=AC(-51.45)
Leader
Trailer
I=AC(
)
J=AC(
)
K=AC(
)
The same is true for some tool numbers, expressed as TC(1): Leader
Trailer
TC(
)
Modal? Select Yes for words that are modal. The word is output only if the value of the expression changes. This is the default setting for all words. Typically, modal words are for coordinate data, motion G codes, and so on. Select No for words that must be output in every block in which the word appears. For example, the opstop event should always force an option is set to No by default.
M01;
the Modal?
Post Building Techniques – Student Guide
2-35
2
Build a postprocessor with Post Builder
Maximum and Minimum Define the maximum and minimum value that can be output with the selected word. You can define the action when maximum or minimum value is exceeded from the following:
2
Truncate The maximum or minimum value is used instead of the value specified in NX. Warning Warnings are output if one of the following is true: •
The Output Warnings postprocessing option in NX is set to Yes.
•
The Post Builder option Output Warning Messages on the Output Settings®Other Options tab is selected and the Output Warnings option in NX is set to anything other than No.
Warnings are output to a file with the base name of the output file, and the suffix and extension warning.out. For example, if the output file is my_part.ptp, the warning file is my_part_warning.out. There is no interactive warning in the NX session. Abort Postprocessing is aborted. An error message is output to the system log file, Help®Log File. The message may appear at the beginning of a lengthy trace, but you can identify the beginning lines similar to the following: *** IKS has been initialized *** *** EXCEPTION: Error code 1745005 in line 560 of o:\ugnx80\ip19\src\cams\no\ind\mom_post.c at Tue Apr 19 11:45:16 2011 Eastern Daylight Time +++ ADDRESS:F, Maximum is 600.000000, this value is 619.685039
2-36
Post Building Techniques – Student Guide
mt11060_s — NX 8 — Copyright 2011 Siemens PLM Software
Build a postprocessor with Post Builder
Format tab
2
Use the Format tab to create and edit formats. Post Builder comes with a default set of formats that are applied to words in the default posts. You can also change formats within the context of the words and blocks on several other tabs where words are displayed. Tree diagram The tree diagram at the left of the Format tab shows the formats that are defined in the current post. You can edit a format by selecting it in the tree. You can create a new format by selecting an existing format and clicking Create. This gives you a new format exactly like the original, with _1 appended to the name. You can rename, cut, and paste formats, with the exception that you cannot cut a format that is in use.
Post Building Techniques – Student Guide
2-37
Build a postprocessor with Post Builder
Preview The green area at the top of the format window shows a preview of the selected format.
2 Data Type Specifies the data type as numeric or text. You should select numeric for all NC data except for certain G codes. For instance, if your controller needs L instead of G01, R instead of G00, CW instead of G02, and so on, then you can change the data type to text and change all of the codes to the text that the controller recognizes. This is the only case we have found where it is necessary to use a text format. If you specify text, you no other formatting options available to you. You should try text format only if you are familiar with this area. Number spin boxes Let you set the number of digits to the left and right of the decimal point.
Output Decimal Point (.) Some words do not require a decimal point, even when the value has one or more decimal places. For example, if you want to output P3000 for a dwell time of 3.000 seconds, you would make the format 1.3, select the Output Trailing Zeros check box, and clear the Output Decimal Point (.) check box.
2-38
Post Building Techniques – Student Guide
mt11060_s — NX 8 — Copyright 2011 Siemens PLM Software
Build a postprocessor with Post Builder
Check boxes The check boxes on the Format tab do what their names indicate. Some examples follow. The number to be output is 53.1, and the spin boxes are set to the 5.3 format. Check boxes selected Output Decimal Point (.) Output Decimal Point (.) Output Leading Plus Sign (+) Output Decimal Point (.) Output Leading Zeros Output Decimal Point (.) Output Leading Zeros Output Trailing Zeros Output Leading Plus Sign (+) Output Leading Zeros Output Trailing Zeros
Output 53.1 +53.1 00053.1 00053.100 +00053100
If none of the decimal point, leading zeros, or trailing zeros check boxes is selected, you will get an error message. At least one of these must be selected to assure that the output has a clear meaning. When the output represents a decimal value between 1.000 and –1.000, then the following formats are useful: Zero_int
Outputs integer numbers with leading zeros.
Zero_real
Outputs decimal numbers with both leading and trailing zeros.
Post Building Techniques – Student Guide
2-39
2
Build a postprocessor with Post Builder
Activity: NC Data Definitions tab In the Build a postprocessor with Post Builder section, do the following activity:
2
•
2-40
NC Data Definitions tab
Post Building Techniques – Student Guide
mt11060_s — NX 8 — Copyright 2011 Siemens PLM Software
Build a postprocessor with Post Builder
Create new M or G code groups M and G codes are classified into logical groups. One such group is the Motion group. This group consists of the following words: •
G00 – Rapid Move
•
G01 – Linear Move
•
G02 – Circular Interpolation (CLW/CCLW)
•
G02 – Circular Interpolation CLW
•
G03 – Circular Interpolation CCLW)
•
G81 – Drill
•
… several other drilling and boring cycles.
•
G80 – Cycle Off
•
G-Cycle Code Representative
•
G – User Defined Expression
2
Only one word from a group can be active at any given time, because the groups represent mutually exclusive moves. For example, a machine cannot be moving in the G00 mode (rapid) while making a G01 move (linear feed) simultaneously. As a general rule, Post Builder supports all common M and G code groups. In some instances however, certain machine tool and controller combinations support functions that are unique and require custom M or G codes. Post Builder allows you to create these new M or G code groups as shown in the following activity.
Post Building Techniques – Student Guide
2-41
Build a postprocessor with Post Builder
Activity: Create a new group of coolant codes In the Build a postprocessor with Post Builder section, do the following activity:
2
•
2-42
Create a new group of coolant codes
Post Building Techniques – Student Guide
mt11060_s — NX 8 — Copyright 2011 Siemens PLM Software
Build a postprocessor with Post Builder
Output Settings tab Use the Output Settings tab to control elements such as following: •
The presence of a listing file and details included in the listing.
•
The way your post handles program groups in NX.
•
The defaults for warning output and the debugging tool.
•
Additional Tcl files to read before posting.
•
Links to Alternate Units subposts.
2
You can also compare what is as stored on disk to information currently in memory for the post you are editing, for the following categories: •
Events
•
Formats
•
Words
•
Blocks
Post Building Techniques – Student Guide
2-43
Build a postprocessor with Post Builder
Listing File tab Generate Listing File When selected, your post always outputs a listing file.
2
The listing file contains a header that contains all the runtime information that includes time and date, part name, name of the postprocessor files used and user name. The listing file also contains the NC file, warnings, and the absolute axis positions. Listing File Extension Sets the extension used for the listing file. The name of your listing file is the name of the output NC file, with the listing file extension. For example, for 1234.ptp, the default listing file is 1234.lpt. Components Use the check boxes to control the following outputs to a table in the listing file:
2-44
•
X-Coordinate
•
Y-Coordinate
•
Z-Coordinate
•
4th Axis Angle
•
5th Axis Angle
•
Feed
•
Speed
Post Building Techniques – Student Guide
mt11060_s — NX 8 — Copyright 2011 Siemens PLM Software
Build a postprocessor with Post Builder
Other Options tab Output Control Elements group NC File Output Extension Sets the default extension for the NC output file that the post generates. You can override this in NX, by entering an extension in the File Extension box in the Output File group of the Postprocess dialog box. Generate Group Output Lets you define how your post handles program groups in NX. You can define more than one NC program in a part file. If the top level group is NC_PROGRAM and all the subgroups are in the level immediately under NC_PROGRAM, all subgroups are output in the same NC tape file, regardless of the setting in the post. The option controls whether additional files are output. By default, the Generate Group Output check box is not selected. All group organization in NX is ignored, and a single file is output for the selected program or program group, or for selected operations in the same group. Select this check box when you want additional output of a separate NC tape file for each group immediately below the top level selected, for example, all top level groups below NC_PROGRAM. Each file has the same name as the top-level output file, with the group name appended to it. For example, if the name of the NX file is gearbox.prt and the NC_OPERATION program has the following subgroups: ROUGHING, FINISH_MILLING and DRILLING, the output files for the NC_OPERATION group when the Generate Group Output check box is selected are: •
gearbox.ptp
•
gearbox_roughing.ptp
•
gearbox_finish_milling.ptp
•
gearbox_drilling.ptp
The behavior when the check box is selected is similar if groups have subgroups below them. Do not mix operations in groups with operations outside of groups when the Generate Group Output check box is selected. This causes unpredictable output.
Post Building Techniques – Student Guide
2-45
2
Build a postprocessor with Post Builder
You can use the name of the selected group or program in NX as the program name in the Start of Program event. Access the name using the variable mom_group_name. Output Warning Messages Outputs warnings to a warning log file when Output Warnings in the NX Postprocess dialog box is set to its default value, Post Defined. The system suffix and extension _warning.out are appended to the base name of the NC output file, and the warnings file is in the same directory as the NC output.
2
Display Verbose Error Messages Displays detailed error messages if a Tcl error is encountered. If you select the Display Verbose Error Messages check box when you are debugging your post; you need not examine the NX log file for error messages. Because this option causes degradation in performance, use this option only when you are debugging your post.
2-46
Post Building Techniques – Student Guide
mt11060_s — NX 8 — Copyright 2011 Siemens PLM Software
Build a postprocessor with Post Builder
Activate Review Tool Opens the debugging dialog box after postprocessing is complete. The debugging dialog box has three lists. The first list displays all events that were created by the event generator. The second list displays all of the variables that were created and passed to your postprocessor during a selected event, including MOM variables, and the variable values. The third list displays a list of the NC output that your postprocessor generated. For example, if you select an event in the first list , the data generated by the selected event is shown in the second list , and the NC code generated for the selected event is highlighted in the third list . The listing at the top of the display shows you the selected event, or the event that caused selected NC code .
The review tool causes a significant degradation in performance. Use this option only with relatively small files and when you are debugging a problem.
Post Building Techniques – Student Guide
2-47
2
Build a postprocessor with Post Builder
User Tcl Source Identifies an additional Tcl file to read based on the options in this section. This file must be in the default postprocessor folder.
2
Source User’s Tcl File Includes handlers for UDE post commands that you create in your own Tcl file. Your Tcl file must be in the same folder as the current postprocessor. File Name Specifies the name of the file that you want sourced into your post.
2-48
Post Building Techniques – Student Guide
mt11060_s — NX 8 — Copyright 2011 Siemens PLM Software
Build a postprocessor with Post Builder
Optional Alternate Units Subpost The options under Optional Alternate Units Subpost work together with the option Units Only Subpost in the Create New Post Processor dialog box. Default Modifies the postprocessor file name to the format for a units-only subpost. The name links your post to a subpost with millimeter units for an inch-unit post and subpost with inch units for a millimeter-unit post. You can explicitly create the subpost later, after your post is fully defined. You can also link to an existing subpost, if, for example you are linking a family of posts for a complex machine to a single subpost. For example, if the post you are creating is named new_post and has inch units, the default name for the alternate units post is new_post__MM.pui. If the post you are creating is named my_post and has millimeter units, the default name for the alternate units subpost is my_post__IN.pui. In the name of the alternate units post, the unit abbreviation is in uppercase and it is preceded by two underscores. If the alternate units subpost exists and is in the same folder as your post, it is used automatically when you request output in the units of the subpost. Specify Lets you specify an existing units-only subpost to link to your main post. The subpost must have the correct units, and must be compatible for the machine tool for which you are defining your post. For example, if your main post has millimeter units, the subpost you select must be for inch output. Typically, you use this option to reuse the same units-only subpost for a set of linked posts, such as the set of posts for a complex machining center. Select Name Available when Specify is selected. Lets you navigate to and select an existing subpost. The subpost must have the correct units. Link Tcl Variables to C Variables Enables NX Post to process the MOM Tcl variables more efficiently. This option can improve the performance of NX Post by approximately 25 percent; however, it might cause NX Post to fail in some situations. Use this option with caution, and, as always, thoroughly test your postprocessor before distributing it.
Post Building Techniques – Student Guide
2-49
2
Build a postprocessor with Post Builder
Activity: Output settings In the Build a postprocessor with Post Builder section, do the following activity:
2
•
2-50
Output settings
Post Building Techniques – Student Guide
mt11060_s — NX 8 — Copyright 2011 Siemens PLM Software
Build a postprocessor with Post Builder
Post Files Preview tab Use the Post Files Preview tab to examine the current and previously saved source code for the definition file and event handlers. When you select the Event Handlers tab or the User Defined Events tab, you can browse Tcl code.
When you select the Definitions tab you can browse the elements of the definition file.
Post Building Techniques – Student Guide
2-51
2
Build a postprocessor with Post Builder
Post Files Preview property page
2
The Post Files Preview property page allows you to examine the Definition file (.def) and the Event Handlers (.tcl) before output generation. Newly defined code appears in the top window while the original code is displayed in the bottom window.
2-52
Post Building Techniques – Student Guide
mt11060_s — NX 8 — Copyright 2011 Siemens PLM Software
Build a postprocessor with Post Builder
Summary: Build a postprocessor with Post Builder The Post Builder is an efficient and robust tool that can be used to build the majority of the Postprocessors that are required in today’s manufacturing environment. The following functions were used in conjunction of building a Postprocessor with the Post Builder: •
Created a directory structure for testing Postprocessors developed with the Post Builder.
•
Creation, modification and customization of Event handlers with the Program and Tool path function.
•
Defined output formats
•
Modified listing and output options.
•
Verified the output of your Postprocessor using the Post Review Tool.
Post Building Techniques – Student Guide
2-53
2
2
Lesson
3
Units-only subposts 3
Purpose This lesson describes the process for creating a subpost with units that are not the default units of the main post. This subpost is called automatically by the main post when you define the output in units other than the default units. Objective When you complete this lesson, you will be able to: •
Create an alternate units subpost.
•
Link a subpost to a main post.
Post Building Techniques – Student Guide
3-1
Units-only subposts
Defining and editing units-only subposts The dialog box to define and edit a post processor shows the name of the currently open post processor in its title bar. Values from the main post are shown in blue boxes that cannot be changed in this dialog box. Values for the units of the subpost appear in white boxes that you can modify. The following main tabs are available:
3
Units Parameters Values default to standard conversions of values in the main post. If your machine and controller manuals specify different values from the automatically converted values, you can set them on this tab. WORD
Values for word formats are defaulted to the same number of digits, with a shift in the decimal point. For example, if the format is 4.4 in Inches, it is represented in this dialog box as 9999.9999. The metric format is automatically converted to 9999.999. If your controller recognizes a different format for alternate units, you can set it on this tab.
FORMAT
Values for word formats are defaulted to the same number of digits, with a shift in the decimal point. This tab has formats for absolute coordinates, coordinates, and feed rates.
3-2
Post Building Techniques – Student Guide
mt11060_s — NX 8 — Copyright 2011 Siemens PLM Software
Units-only subposts
3
Where do I find it? Application
Prerequisite Toolbar
Menu Create New Post Processor dialog box
Post Builder You must have a main post from NX 8 or later on which to base the subpost. NX/Post Builder®Open NX/Post Builder®File®Open NX/Post Builder®File®Recently Opened Posts
OK
Post Building Techniques – Student Guide
3-3
Units-only subposts
Activity: Create a units-only subpost In the Units-only subposts section, do the following activity: •
Create a units-only subpost
3
3-4
Post Building Techniques – Student Guide
mt11060_s — NX 8 — Copyright 2011 Siemens PLM Software
Units-only subposts
Summary: Units-only subposts In this lesson, you: •
Created a new alternate units subpost.
•
Linked a subpost to the main post of a family of posts that work together to program a complex machine.
3
Post Building Techniques – Student Guide
3-5
3
Lesson
4
Post Builder for Wire EDM applications
Purpose Wire EDM machines have requirements that differ from mills and lathes. This lesson describes the Post Builder options that are unique to creating a post for a wire EDM. Objective After you complete this lesson, you will be able to: •
Use the Post Builder to build 2-axis or 4-axis Wire EDM postprocessors.
Post Building Techniques – Student Guide
4-1
4
Post Builder for Wire EDM applications
Creating 2-axis and 4-axis wire EDM postprocessors Two options are available in Post Builder for creating wire EDM postprocessors. They are: •
2-axis
•
4-axis
4 After you make the selection of a 2-axis or 4-axis Wire EDM postprocessor, you must specify the type of controller that you want. Your choices are: Generic, Library, and User’s. Generic Uses generic options common to most machine tool controllers. Library Lets you select Agie, Charmilles and Mitsubishi controllers. These templates contain the basic codes required for the most common wire EDM codes such as threading, start and end of cut, and power settings. User’s Lets you select a post that you created previously as a template. Click Browse to select the existing postprocessor.
4-2
Post Building Techniques – Student Guide
mt11060_s — NX 8 — Copyright 2011 Siemens PLM Software
Post Builder for Wire EDM applications
Wire EDM specific parameters Wire Tilt Control Defines the method to control the upper wire guide. Angles Outputs tilt and lead relative to the direction of motion. This is typical output for Agie controllers. Coordinates Outputs upper wire guide coordinates relative to the X and Y position of the lower wire guide. This is typical of the output for Mitsubishi and Charmilles controllers.
4
Post Building Techniques – Student Guide
4-3
Post Builder for Wire EDM applications
Activity: Create a 2-axis Wire EDM post In the Post Builder for Wire EDM applications section, do the following activity: •
Create a 2–axis Wire EDM post
4
4-4
Post Building Techniques – Student Guide
mt11060_s — NX 8 — Copyright 2011 Siemens PLM Software
Post Builder for Wire EDM applications
Summary: Post Builder for Wire EDM applications The flexibility of Post Builder allows you to easily generate postprocessors for 2 axis and 4 axis wire EDM machines. In this lesson you were introduced to: •
Creating a 2-axis Wire EDM Postprocessor using Post Builder.
4
Post Building Techniques – Student Guide
4-5
4
Lesson
5
Post Builder for 4-axis and 5-axis mills
Purpose Mills with 4 and 5 axes have rotary heads, rotary tables, or a combination of the two, that you must configure. This lesson describes the Post Builder options that are needed to define 4th and 5th rotary axes. Objective After you complete of this lesson, you will be able to: •
5
Use Post Builder to build 4-axis and 5-axis mill postprocessors.
Post Building Techniques – Student Guide
5-1
Post Builder for 4-axis and 5-axis mills
Creating 4-axis and 5-axis mill postprocessors In the Create New Postprocessor dialog box, the following options are available for multi-axis mills: •
4-Axis with rotary table
•
4-Axis with rotary head
•
5-Axis with dual rotary heads
•
5-Axis with dual rotary tables
•
5-Axis with rotary head and table
In the editing dialog box, on the Machine Tool tab, you can select General Parameters, Fourth Axis and Fifth Axis parameters.
5
when you click Display Machine Tool, a generic machine tool of the type you selected, which shows current axis limits, is displayed.
5-2
Post Building Techniques – Student Guide
mt11060_s — NX 8 — Copyright 2011 Siemens PLM Software
Post Builder for 4-axis and 5-axis mills
Mill Fourth Axis and Fifth Axis parameters The fourth axis dialog box and fifth axis dialog box set the same parameters, with a couple of exceptions that are mentioned in the following list. The default settings work for most machines. There is a general restriction in Post Builder that the C axis (XY plane) cannot be the 4th axis of a 5-axis machine tool. In order to get the correct output for a dual head rotary 5-axis machine tool with a B-axis in the ZX plane attached to a C-axis in the XY plane, you must define the fourth axis as B in the ZX plane, and the fifth axis as C in the XY plane. The machine tool display function will not work correctly for this configuration; however, the NC program output will be correct. Machine Zero to 4th Axis Center Available when Fourth Axis is selected. Sets the distance from machine zero to the center of rotation for the 4th axis.
5
This value must be specified for the postprocessor to map correctly between the MCS programmed in NX and the machine tool coordinate system. 4th Axis Center to 5th Axis Center Available when Fifth Axis is selected. Sets the distance between the centers of rotation for the 4th axis and the 5th axis. This value must be specified for the postprocessor to map correctly between the MCS programmed in NX and the machine tool coordinate system. Rotary Motion Resolution (Deg) Controls the number of digits to which the calculated rotary angles are rounded by the postprocessor. Angular Offset (Deg) Sets the value that needs to be added to adjust the rotary angle to 0.0 when the tool axis is (0,0,1). For example, some Sundstrand head and table machine tools require an offset of –90, because prior to entering the offset, a tool axis vector of (0,0,1) results in output of an angular position of 90.0 degrees for the fourth axis. Post Building Techniques – Student Guide
5-3
Post Builder for 4-axis and 5-axis mills
Axis Rotation Defines whether the axis rotates according to the right-hand rule. The rule states that when you hold your right hand with the thumb pointing in the positive direction of the rotation axis, the fingers curl in the positive direction of rotation. Normal is the default option. Select Reverse if your table does not rotate according to the right-hand rule. For example, if you get B90 output when you require B–90, you may need to select Reverse. As always, test the post thoroughly. Axis Direction Defines how the rotary table determines whether to rotate clockwise or counterclockwise. Magnitude Determines Direction Rotation to a larger angle is always clockwise and rotation to a smaller angle is always counter clockwise.
5
and B90 cause rotation to different positions that are 180 degrees apart on the rotary axis.
B–90
Typically, the travel limits on this type of table are more than 360 degrees, for example, –9999 to 9999. Sign Determines Direction The sign determines only the direction of rotation. B90
and B–90 cause rotation to the same position on the rotary table.
When you program B90, the table rotates clockwise from its current location to 90 degrees. When you program B–90, the table rotates counterclockwise from its current location to 90 degrees. Typically, the limits on this table are from 0 to 360. Axis Limits (Deg) Sets the minimum and maximum angles that you can program for the axis. The postprocessor measures the range of travel clockwise from the minimum angle to the maximum angle. For example, if you have a rotary axis that has 40 degrees of travel, you can enter one of the following sets of values:
5-4
•
–20 degrees for the minimum and 20 degrees for the maximum.
•
340 degrees for the minimum and 20 degrees for the maximum.
Post Building Techniques – Student Guide
mt11060_s — NX 8 — Copyright 2011 Siemens PLM Software
Post Builder for 4-axis and 5-axis mills
This Rotary Axis Can Be Incremental Outputs axis motion incrementally when you define operation start and end events for incremental output in NX tool paths. In the Machine Control section of the operation editing dialog box, create start of path events and end of path events for each operation. For the operation start event, enter: SET/MODE,INCR
For the operation end event, enter: SET/MODE,ABSOL
5
Post Building Techniques – Student Guide
5-5
Post Builder for 4-axis and 5-axis mills
Rotary Axis Configuration dialog box Under Rotary Axis, click Configure to open the Rotary Axis Configuration dialog box.
5
4th Axis and 5th Axis Display the name for the type of axis that you selected in the Create New Postprocessor dialog box: Head or Table. For each axis, you can set: •
The plane of rotation, for example, XY, YZ, or ZX.
•
The word leader, for example, A, B, or C.
Max. Feed Rate (DegMin) Sets the maximum rotary feed rate for the machine tool. If the amount of rotation during a combined linear and rotary move exceeds the maximum degrees per minute, the post processor reduces the feed rate so that it does not exceed this value.
5-6
Post Building Techniques – Student Guide
mt11060_s — NX 8 — Copyright 2011 Siemens PLM Software
Post Builder for 4-axis and 5-axis mills
Pivot Distance Sets the distance from the head or table rotation pivot point to the spindle gage point. This option is not valid for the dual rotary type five-axis machine tool. You can specify this value in either the fourth axis or the fifth axis dialog box; however, there is only one pivot distance on the machine tool. Axis Limit Violation Handling Warning Outputs a warning to the listing file or warning file, if one or both options are active. No corrective action is taken. Enable warning output on the Output Settings®Other Options tab. Enable listing output on the Output Settings®Listing File tab. Retract/Re-Engage • Retracts to clearance cylinder or sphere. •
Repositions the rotary axis to a valid position, if possible.
•
Re-engages to a user-defined distance above the part.
•
Feeds to the previous position.
•
Moves to the programmed end point.
5
To change the default retract or re-engage distance you must modify the custom command PB_CMD_init_rotary. Modify the following lines: set set set set
mom_kin_retract_plane 10.0 mom_kin_retract_distance 10.0 mom_kin_retract_type "PLANE" ;# DISTANCE or PLANE mom_kin_reengage_distance .20
User Defined Lets you click Handler to specify a block with appropriate words or custom commands to execute when a rotary axis limit violation occurs.
Post Building Techniques – Student Guide
5-7
Post Builder for 4-axis and 5-axis mills
Linearization Interpolation Lets you specify the default linearization tolerance. The tool path is broken into moves that are within the specified tolerance. By default, linearization is set to off. Combined rotary and linear motion causes the motion to deviate from the desired straight line move. To activate linearization for four-axis and five-axis milling machines, you can use the post command LINTOL in NX.
Under Machine Control, create a start of path event, User Defined. The syntax for this command is as follows:
5
LINTOL/ [ON | OFF | n]
When you specify a tolerance value n, it implicitly turns on linearization. ON
turns on linearization with the last specified linearization value.
OFF
turns off linearization.
You can also use linearization for mill turn machines to linearize the XZC moves. To use linearization for XZC posts, set the output mode to polar. To do this, use the default setting for the post command: SET/POLAR,ON. The syntax for the command is: SET/POLAR, [ON | OFF] sets the output mode to polar. The coordinate output is XZC and is linearized if needed.
ON
sets the output mode to Cartesian. The coordinate output is XYZ and no linearization takes place.
OFF
For head-head machines, linearization is not in effect when the NC points are output at the tool tip. For example, when the Z Offset value for the tool, or the gauge-pivot distance in the post, is 0.0.
5-8
Post Building Techniques – Student Guide
mt11060_s — NX 8 — Copyright 2011 Siemens PLM Software
Post Builder for 4-axis and 5-axis mills
Activity: Create a 5-axis Mill post In the Post Builder for 5-axis mill applications section, do the following activity: •
Create a 5-axis Mill post
5
Post Building Techniques – Student Guide
5-9
Post Builder for 4-axis and 5-axis mills
Summary: Post Builder for 5-axis mills In this lesson you were introduced to: •
Creating a 5-axis mill postprocessor using the Post Builder tool.
5
5-10
Post Building Techniques – Student Guide
mt11060_s — NX 8 — Copyright 2011 Siemens PLM Software
Lesson
6
Post Builder for lathe applications
Purpose Lathes have requirements that differ from mills and wire EDM machine tools. This lesson describes the Post Builder options that are unique to building postprocessors for 2-axis lathes. Objective After you complete this lesson, you will be able to: •
Use Post Builder to build 2-axis lathe postprocessors.
6
Post Building Techniques – Student Guide
6-1
Post Builder for lathe applications
Creating lathe postprocessors In the Create New Postprocessor dialog box, lathe options are the same as mill options.
Currently, you can create only one type of lathe postprocessor using Post Builder: •
2-Axis
In the editing dialog box, on the Machine Tool tab, when you select General Parameters, you see options that are shared by all types of machines, and options that are unique to lathes.
6
6-2
Post Building Techniques – Student Guide
mt11060_s — NX 8 — Copyright 2011 Siemens PLM Software
Post Builder for lathe applications
2-axis lathe-specific parameters Output Method Defines the tool tracking method. Tool Tip Makes the X-values and Z-values in your NC output file represent the tool tip location. Resets the tool tip location with every tool change. The basic elements for tool tip programming are: •
A FROM command at the beginning of the program to define the initial turret reference position.
•
A G92 block with each tool change to take into account the change in offsets.
•
A GOHOME or return to the home position to return to the turret reference position.
Turret Reference Makes the X-values and Z-values in your NC output file represent the turret reference location, similar to the method for milling machine programs.
6
Turret Defines whether you have one or two turrets. One Turret The default option. Two Turrets Currently, when you select this option, the turrets must be a fixed distant apart and may not move independently. becomes available when you select Two Turrets. Configure Available when you select Two Turrets. You must select the names of the two turrets from lists of recognized names, and you must specify the X-distance and Z-distance between them. The postprocessor adds the offset values to the X-axis and Z-axis coordinates when the secondary turret is used. The distance must be measured from the primary turret to the secondary turret.
Post Building Techniques – Student Guide
6-3
Post Builder for lathe applications
Axis Multipliers Specifies that the machine requires diameter programming. You can also use it if your shop practice is to use diameter programming. Diameter Programming Outputs the X-word as a diameter. When you select 2X, then 2I becomes available. Select 2I if your machine also requires the I-value to be multiplied by two. Mirror Output Lets you program your part in other quadrants and output in the first, or positive, quadrant. Select the combination of X, I, Z, and K multipliers that you require. For each word selected, the corresponding value is multiplied by negative one in the output.
6
6-4
Post Building Techniques – Student Guide
mt11060_s — NX 8 — Copyright 2011 Siemens PLM Software
Post Builder for lathe applications
Activity: Create a lathe post In the Post Builder for lathe applications section, do the following activity: •
Create a lathe post
6
Post Building Techniques – Student Guide
6-5
Post Builder for lathe applications
Summary: Post Builder for lathe applications The flexibility of Post Builder allows you to easily generate postprocessors for 2-axis lathes. In this lesson you were introduced to: •
Creating a 2-axis lathe postprocessor using Post Builder.
6
6-6
Post Building Techniques – Student Guide
mt11060_s — NX 8 — Copyright 2011 Siemens PLM Software
Lesson
7
Create Mill-Turn postprocessors
Purpose This lesson describes the procedures required to build mill-turn postprocessors through the use of Post Builder. Objective When you complete this lesson, you will be able to: •
Construct a postprocessor for a mill-turn machine.
7
Post Building Techniques – Student Guide
7-1
Create Mill-Turn postprocessors
Create a mill-turn post 1. Create a new 2-axis lathe post. 2. Save the 2-axis lathe post using one of the following options: •
Save it as lathe_tool_tip in the folder where you intend to create your mill-turn post.
•
Save it in your postprocessor folder, using a name of your choice.
3. Create a new mill post and select 3-Axis Mill-Turn (XZC). 4. In the mill post, on the Machine Tool tab, on the General Parameters page, under Machine Mode, do one of the following: •
If you saved the 2-axis lathe post as lathe_tool_tip in the folder where you intend to save your mill-turn post, select XZC Mill to automatically use the lathe_tool_tip post.
•
If you saved your lathe post in your postprocessor folder using a name of your choice, select Simple Mill-Turn and click Select Name to navigate to your lathe post.
5. Complete your mill post and save it to the folder where you saved your lathe post. 6. In NX, on the Navigator toolbar, click Geometry 7. Make sure that all the lathe tool paths are in the MCS_SPINDLE group object.
7
8. Make sure that all the mill tool paths are in the MCS_MILL group object. 9. Postprocess your tool paths.
7-2
Post Building Techniques – Student Guide
mt11060_s — NX 8 — Copyright 2011 Siemens PLM Software
Create Mill-Turn postprocessors
Activity: Create a Mill-Turn postprocessor In the Create Mill-Turn postprocessors section, do the following activity: •
Create a Mill-Turn postprocessor
7
Post Building Techniques – Student Guide
7-3
Create Mill-Turn postprocessors
Define heads for mill-turn centers Some mill-turn centers use special heads for turning, for example, Z-axis, X-axis, Y-axis or 5-axis work. You can output commands to use these heads by the following procedure: 1. Create the postprocessors for the auxiliary heads that you need, and save them to one common folder. For example, if you require an X-axis head and a turning head in addition to the main mill-turn XZC head, create an X-axis mill post and a lathe post, and configure them to your machine and controller combination. 2. Create a milling post in the common folder, and in the Create New Post Processor dialog box, under Machine Tool, select 3-Axis Mill-Turn (XZC). This is your main post. Select it from the list of postprocessors in NX when you are posting programs for your mill-turn center. 3. In the mill-turn post, on the Program & Tool Path tab, on the Linked Posts tab, select the Link Other Posts to This Post check box. In the Linked Posts dialog box, the Post contains this_post. You must supply a name to reference the current post in the NX HEAD event. 4. In the Linked Posts dialog box, in the Head box, enter a name for the head used in the main post. Use a name that is meaningful to both you and your users. For example, if the main post moves primarily in the Z-axis, call it ZHEAD. Always use uppercase letters for head names in your post and in NX. Tcl is case sensitive, so a standard practice of using only uppercase letters avoids issues with inconsistent naming.
7
5. (Optional) If your machine and controller combination requires special commands at the start or end of head use, click Start of Head and End of Head to add the necessary commands. 6. In the Linked Post dialog box, click OK. 7. Repeat the following for each linked post: a. On the Linked Posts tab, click New. b. In the Linked Post dialog box, click Select Name. c. In the Select a file dialog box, from the common folder, select one of your posts for other heads on the machine and click OK. 7-4
Post Building Techniques – Student Guide
mt11060_s — NX 8 — Copyright 2011 Siemens PLM Software
Create Mill-Turn postprocessors
d. In the Linked Post dialog box, in the Head box, enter a meaningful name for the head that corresponds to the post that you specified. For example, you could call it XHEAD or TURN. e. (Optional) If your machine and controller combination requires special commands at the start or end of head use, click Start of Head and End of Head to add the necessary commands. f.
In the Linked Post dialog box, click OK.
8. Save the completed main post in the common folder. 9. In NX, open a part with a suitable test program that uses all of the heads on your machine tool. 10. In the Method view of the Operation Navigator, create methods that correspond with the available head posts. For example, you can create methods for turning, X-head milling, X-head drilling, Z-head milling, and so on. 11. Drag operations from the Unused Items folder to your methods. 12. For each method, do the following: a. Right-click the method and choose Object®Start Events. b. In the User Defined Events dialog box, from the Events Available list, select Head and click Add new event
.
7
c. In the Head dialog box, verify that Status is set to Active. d. Select the Name Status check box. e. In the Name box, enter the name of the head exactly as you specified it in the main post under Linked Posts. f.
Click OK.
g. In the User Defined Events dialog box, click OK. 13. Postprocess your test program and verify whether all output is correct.
Post Building Techniques – Student Guide
7-5
Create Mill-Turn postprocessors
Activity: Create a 5-axis multi-link mill-turn post In the Create Mill-Turn postprocessors section, do the following activity: •
Create a 5-axis multi-link mill-turn post
7
7-6
Post Building Techniques – Student Guide
mt11060_s — NX 8 — Copyright 2011 Siemens PLM Software
Create Mill-Turn postprocessors
Summary: Create Mill-Turn postprocessors When you use Post Builder to generate linked postprocessors for combination-type machine tools, you can: •
Save time.
•
Customize each section of the post.
•
Reuse sections of a post on machines with common requirements.
7
Post Building Techniques – Student Guide
7-7
7
Lesson
8
Tcl basics for Post Builder
Tcl Basics for Post Builder Purpose This lesson describes the basics of the Tcl scripting language that is used by existing NX Post and Post Builder programs, within postprocessors that you create, and for customizing that you perform. Objectives After you complete this lesson, you will be able to: •
Interpret the syntax and basic structures of Tcl.
•
Write simple Tcl programs.
8
Post Building Techniques – Student Guide
8-1
Tcl basics for Post Builder
Tcl Tcl is public domain software. The Tcl source and a link to a provider of the compiled executable is available at tcl.sourceforge.net. Tcl stands for tool command language. Tcl is an interpreted language, that is, a Tcl script is interpreted at run time by a Tcl interpreter. The difference between Tcl and a compiled language such as C or GRIP is that you can make changes to the scripts and test them without having compile your code. In NX CAM, you use Tcl for procedures in NX Post, Process Assistants, Shop Documentation, the internal CLSF, and Post Builder. You also use Tcl to create the following: •
User-defined event handlers
•
User-supplied rules
Tcl has an extension called Tk, which stands for tool kit. Tk provides user graphic interface elements such as buttons, check boxes, and scroll bars. You can open a Tk window by running the program ugwish.exe in the \mach\auxiliary directory. Although Post Builder 8.0.0.4 uses Tcl 8.4.19 internally, NX Post uses an older version. Siemens PLM Software recommends that you follow the 8.0.5 syntax to maintain compatibility with NX Post. You can find Tcl 8.0.5 command documentation at: http://www.tcl.tk/man/tcl8.0/ In Tcl syntax, the following grouping symbols are necessary: ()
Parentheses
[]
Brackets, or square brackets
{}
Braces, or curly braces
8
8-2
Post Building Techniques – Student Guide
mt11060_s — NX 8 — Copyright 2011 Siemens PLM Software
Tcl basics for Post Builder
Tcl command structure Tcl is a command-based language. Commands instruct the Tcl interpreter to perform some type of task. Commands are made up of words that include the name of the command and may also include options and arguments. The basic syntax of a Tcl command is: command argument1 argument2 argument3 ...
Command arguments Arguments can be any type of information that a command can process, change, or use. In the command set principal_axis X, the command is set, which instructs to interpreter to assign a value to a variable. The two arguments convey the following information: The first argument, principal_axis, is the name of a variable to be assigned a value. The variable is created if it does not already exist. The second argument, X, is the text string to assign to the variable.
Post Building Techniques – Student Guide
8-3
8
Tcl basics for Post Builder
Command options Options are used with some commands to give the interpreter detailed instructions of the task that the command must perform. Options begin with the ‘–’ character. For example,
glob -nocomplain *.ini
consists of:
The command glob, which instructs the interpreter to match patterns using the standard file name wild card format. The option -noclomplain which instructs the interpreter to return an empty list if nothing matches. Without this option, an error would occur if there are no matches. The argument *.ini, which matches any text string that ends with .ini. The effect of the command, when used in the correct context, is to identify all file names that have the extension .ini. Words Tcl command strings are divided into words. By default, white space characters divide strings of text characters into words. In your programs, you often group words and white space with brackets or braces to create words that consist of two or more other words. Brackets and braces have different meanings to the interpreter. Braces prevent variable substation from taking place on their content.
8
8-4
Post Building Techniques – Student Guide
mt11060_s — NX 8 — Copyright 2011 Siemens PLM Software
Tcl basics for Post Builder
Specifying the order in which words are interpreted Tcl is structured so that you can specify which words to interpret first. This allows you to combine commands to achieve a more complex result. For example: set ini_file_list [glob -nocomplain *.ini]
The set command is going to assign a value to the variable ini_file_list. The third word in the command consists of other words grouped inside square brackets. You can think of the content of the square brackets as an inner command. The square brackets tell the interpreter to analyze their content before doing anything else with the line, and substitute the resulting value before interpreting the outer command, set. The inner command glob -nocomplain *.ini is interprested first, and the result is inserted into the set command string. The result of the entire line is to assign the names of all files with the .ini extension to the variable ini_file_list. The variable ini_file_list becomes a Tcl list, or, a sequence of words, where words are: •
Sets of characters separated by spaces.
•
Sets of words and spaces grouped in braces.
8
Post Building Techniques – Student Guide
8-5
Tcl basics for Post Builder
Tcl variables Variables A variable can be thought of as a named place holder for information. In many languages other than Tcl, variables must have a declared type, such as numbers or strings of text characters. In these languages, in order to set aside the right amount of memory to hold a value of the corresponding type, you must declare variables before you use them. Tcl variables always hold text. You need not declare a Tcl variable before you use it. The only declaration statement in Tcl is used to set the scope of a variable, or whether the variable is known throughout the entire program, or only within the procedure that contains it. Variable names A Tcl variable name must start with an alphabetic character and can consist of alphanumeric characters and the underscore. Variable names are case sensitive. For example, the following are all different variables.: X x this_is_a_Variable pre_drill PRE_DRILL mom_head_name
By convention, mom variables start with mom_ in lowercase letters. Siemens PLM recommends that you use variable names that follow the convention of using only lowercase letters and underscores.
8
8-6
Post Building Techniques – Student Guide
mt11060_s — NX 8 — Copyright 2011 Siemens PLM Software
Tcl basics for Post Builder
Value of variables When you execute the set command at the Tcl command prompt % to create or modify a variable, the interpreter responds with the value that is stored in the program memomry. For example: % set X 10.5 10.5 % set mom_sys_debug_mode OFF OFF
At the command prompt, you can use the set command with only one argument, a variable name, to see the current value. In the following command line example, we use set to define a variable X, and then use set to find the current value of X: % set x 10.5 10.5 % set x 10.5
The unset command removes a variable from your program. The command prompt returns nothing if the command is successful, but there is an error message if there is no such variable. % set pi 3.1415926535897932384626433832795 3.1415926535897932384626433832795 % unset pi % set pi can’t read "pi": no such variable % unset fred can’t unset "fred": no such variable
8
Post Building Techniques – Student Guide
8-7
Tcl basics for Post Builder
Scope of variables In Tcl, the scope of variables can be either local or global. A local variable is a variable that is recognized only in the procedure in which it is declared. When the procedure ends, its local variables are removed. In Tcl, a procedure is the equivalent of a subroutine or function in other programming languages. A global variable persists through the life of the program, outside of any procedures. You can access the value of a global variable between calls to a procedure, or share it among multiple procedures. The following shows the method to set the scope of a variable to global: global cycle_name
The variable in the post.
cycle_name
can be set, accessed, or modified in any procedure
You must use the global command to specify global variables in procedures that use them. You can specify more than one global variable on the same line. In the following example from Post Builder, two global MOM variables are used: proc PB_CMD_end_of_alignment_character {} { # This command restores sequnece number back to orignal setting. # This command may be used with the # command "PM_CMD_start_of_alignment_character" # global mom_sys_leader saved_seq_num if { [info exists saved_seq_num] } { set mom_sys_leader(N) $saved_seq_num } }
The indentation combined with the placement of braces in the preceding example conforms to a common programming standard that makes the code easier to read.
8
8-8
Post Building Techniques – Student Guide
mt11060_s — NX 8 — Copyright 2011 Siemens PLM Software
Tcl basics for Post Builder
Arrays of variables You can define variable arrays in Tcl. Example: •
mom_pos(0)
can have a value of 12.4567.
•
mom_pos(1)
can have a value of 33.9876.
•
mom_pos(Xstr)
can have a value of “X string is”.
In Tcl arrays, the values and the indices are character strings. In the last example, mom_pos(Xstr), the character string Xstr is the index. By convention, in Post Builder, array members use the numbers 0, 1, 2, and so on as index strings . For example, mom_pos(0) stores an X-coordinate, mom_pos(1) stores a Y-coordinate, and mom_pos(2) stores a Z-coordinate. To define an array, you must place an index in parentheses after the variable name: % set myarray(0) 3.14 3.14 % set myarray(one) SomeValue SomeValue
To obtain all indices and corresponding values in an array, you must use the array get command: % array get myarray 0 3.14 one SomeValue
The output of the array get command is a series of text strings separated by spaces. Each array index is followed by the value of the corresponding array element. You can interpret the example output as follows: •
The first character string, 0, is the first index.
•
The value of the array member identified by index character string, 3.14.
•
The next string,
•
The value identified by index
one,
0
is the second
8
is the second index. one
To undefine an array, use the array
is
SomeValue.
unset
command.
% array unset myarray
After you undefine an array, the array get command used on the undefined array does not return a list, and it does not cause an error. Post Building Techniques – Student Guide
8-9
Tcl basics for Post Builder
Working with variables The Tcl interpreter does not directly work with numbers. To do math with values that represent numbers, you must use commands that work with numbers. For example, the expr command is used to evaluate math expressions: % set x 0.866 0.866 % set y 0.5 0.5 % set ang [expr atan2($y,$x)] 0.52361147777
The preceding example shows variables being referenced in a command. The $ character tells the Tcl interpreter to substitute the value of a variable. The interpreter makes exactly one substitution pass before any interpretation takes place. After the substitution, the example command is interpreted as: set ang [expr atan2(0.5,0.866)]
The value of the variable named x is substituted for $x, and the value of the variable named y is substituted for $y. The example also shows one of many built-in math functions that are arguments to expr, atan2(y,x). Because Tcl does not work with math and numbers directly, if you try to use arguments to the expr command without expr, you get an error like the following: % atan2($y,$x) invalid command name "atan2(0.5,0.86602540378)"
The atan2 function and many other functions that work with angles accept and return values in radian measure. You can define variables to hold radian conversion factors. Post Builder handles conversion between degrees and radians with the following code: % set RAD2DEG [expr 90.0 / asin(1.0)] 57.2957795131 % set DEG2RAD [expr asin(1.0) / 90.0] 0.0174532925199
8
Thus, to obtain the value of the previous example in degrees, you could write: set ang [expr atan2($y,$x) * $RAD2DEG] 30.0007277808
You can be more precise: % set x 0.86602540378 0.86602540378 % set y 0.5 0.5 set ang [expr atan2($y,$x) * $RAD2DEG] 30.0000000001
8-10
Post Building Techniques – Student Guide
mt11060_s — NX 8 — Copyright 2011 Siemens PLM Software
Tcl basics for Post Builder
Additional variable substitution examples In the following examples, lines that begin with % (percent sign) show input at the Tcl command prompt. The following lines show the returned values. % set a N N % set b X X % set c $a$b NX % set b 32 32 % set a b b % set a $b 32 % set c $b+$a+$b 32+32+32 % set c [expr $b+$a+$b] 96 % set a $b.3 32.3 % set a $b9 can’t read "b9": no such variable
8
Post Building Techniques – Student Guide
8-11
Tcl basics for Post Builder
Determining set variables You sometimes need to know whether a variable name is safe to use in your procedure. For example, there are many mom variables, but they may not always be defined. At the Tcl command prompt, if x is undefined, you can type set x for the following result: % set x can’t read "x": no such variable
Note that when a command expects a variable name, you do not use a dollar sign. It would be a mistake to use $x in the preceding example. If you attempt to use an undefined variable in an executing program, you get a run-time error. In Tcl you can use the info command to check many things by giving it different arguments. To check whether a variable exists, use the command info exists follwed by the name of a variable. You must not use a dollar sign in front of the variable name. % set pi 3.14 3.14 % info exists pi 1 unset pi % info exists pi 0
Tcl follows a common convention. The command info exists returns 1, or true, when the variable is defined, and 0, or false, when the variable is not defined. To use the info
exists
command effectively, you must use the if command.
if
The if command executes the block of code that is its second argument, if its first argument, a logical comparison, evaluates to 1, the value for true in logic commands. if {[info exists variablename]==1} { # some code that uses the variable }
8
The first argument to if is the pair of commands in the first braces. The result of the command in the brackets is compared to 1. If the command evaluates to anything but 1, the comparison returns 0, a logical false, and the second argument, a block of code in braces, is ignored. If the command evaluates to 1, then the comparison returns 1, a logical true, the next argument, a block of code in braces, is executed.
8-12
Post Building Techniques – Student Guide
mt11060_s — NX 8 — Copyright 2011 Siemens PLM Software
Tcl basics for Post Builder
Tcl control of word structure Tcl words break at whitespace characters: space, tabs, and newlines. Semicolons end a command. The following are exceptions: •
Double quotes prevent breaks and must be used to specify strings that have spaces: % set X "this is a word which has spaces" this is a word which has spaces
•
Curly braces prevent breaks and substitutions: % set Y {{nested }{braces}} {nested }{braces} % set X 27.5 27.5 % set Y "X is $X" X is 27.5 % set Y {X is $X} X is $X
•
The backslash is the escape character. A backslash removes the special meaning of characters, including spaces: % set Z word\ with\ \[\ $\ and\ spaces word with [ $ and spaces
•
You can use the backslash before the dollar sign to avoid getting an error message when you want to output a dollar sign. % puts "The cost is $100" can’t read "100": no such variable % puts "The cost is \$100" The cost is $100
•
The closing square bracket does not need to be escaped: % set XX \[\ escaped,\ ]\ not\ escaped [ escaped, ] not escaped
8
If in doubt about a character, escape it — it does no harm. •
Substitutions do not change word structure: % set abc "two words" two words % set b $abc two words
Post Building Techniques – Student Guide
8-13
Tcl basics for Post Builder
Tcl special characters Some characters, such as $ (dollar sign), have special meaning. You must escape special characters to output them as literal characters. Example with special meaning removed $ \$ \\ — outputs \ — useful in windows \ — the escape character or backslash paths ; \; [ \[ { \{ } \} " \" # \# ] \] Character
There are other special characters that require the escape character to give them their special meaning. In many languages, these character strings are called escape sequences. Character \n \t
Meaning in output newline tab
Examples: % puts stdout "\tFred" Fred % puts stdout "Tab\tSeparated" Tab Separated % puts stdout "High\nLow" High Low % puts stdout "\"Quoted\"" "Quoted" % puts stdout "\$100" $100
8
8-14
Post Building Techniques – Student Guide
mt11060_s — NX 8 — Copyright 2011 Siemens PLM Software
Tcl basics for Post Builder
Tcl mathematical expressions Tcl mathematical expressions are performed by the expr command. Basic operators + – / * sin(x) cos(x) tan(x)
Operation addition subtraction division multiplication sine of x, where x is in radians cosine of x, where x is in radians tangent of x, where x is in radians
More complex operators, such as inverse trigonometric and logarithmic functions are also available. Examples Spaces around th eoperators are neither required nor meaningful, but they make your code easier to read % expr 1+2 3 % expr 1 + 2 3
As with other languages, there is a hierarchy of operator precedence. For example, multiplication and division are performed before addition and subtraction: % expr 1 + 2 * 5 11 % expr 2 * 3 + 1 7
As with other languages, you can group operands with parentheses to control the order of arithmetic operations, and to make you intention clear to anyone who reads your code: % expr (1 + 2) * 5 15 % expr 2 * (3 + 1) 8
You must do radian to degree conversion before doing trigonometric functions. For example, to obtain the sine and cosine for 30 degrees, you must change 30 degrees to radians % expr sin(30 * $DEG2RAD) 0.499999999999 % expr cos(30 * $DEG2RAD) 0.866025403785
Post Building Techniques – Student Guide
8-15
8
Tcl basics for Post Builder
In Post Builder, numbers like those in the preceding example are automatically output to your controller according to the word format you defined for the relevant address. If you are outputting numbers to a print report, you can format numbers to round them to a reasonable number of decimal places. Tcl implements a formatting statement that uses the same modifying symbols as many other languages: % format %1.3f [expr sin(30 * $DEG2RAD)] 0.500 % format %1.6f [expr cos(30 * $DEG2RAD)] 0.866025 % format %1.2f [expr cos(30 * $DEG2RAD)] 0.87
The following are some of the formatting rules: •
The charcter f sets a floating decimal point format.
•
The number to the left of the decimal sets the minimum field width of the output, including the decimal point.
•
The number to the right of the decimal sets the number of decimal places to show. The field is padded with zeros as necessary.
•
A space character after the % inserts a blank space to the left of the output.
•
A zero after the % pads the output with zeros on the left.
The number before the decimal refers to the minimum field width. Remember, in Post Builder, variables named RAD2DEG and DEG2RAD are defined and available to you.
8
8-16
Post Building Techniques – Student Guide
mt11060_s — NX 8 — Copyright 2011 Siemens PLM Software
Tcl basics for Post Builder
Activity: Tcl basics In the Tcl basics for Post Builder section, do the following activity: •
Tcl basics
8
Post Building Techniques – Student Guide
8-17
Tcl basics for Post Builder
Tcl scripts A Tcl script consists of a sequence of commands separated by either a "new line" or a semicolon. Comments are preceded by the "#". The following example illustrates the use of a comment and the concept of a script:
Lines in scripts set mom_pos(0) 12.4 set mom_pos(1) 28.3 set mom_pos(2) 0
is the same as set mom_pos(0) 12.4; set mom_pos(1) 28.3; set mom_pos(2) 0
Comments in scripts In the example, the lines beginning with # are comments. The Tcl interpreter ignores comments except when they contain curly braces. Curly braces in comments are counted for matching pairs of braces. This makes it awkward to comment out sections of code for testing and debugging. You can work around this issue with the if command. To do this, construct code similar to the following:
8
# example showing how to comment out lines in a script if {0} { # code between the braces is never executed! }
You can use the ; (semicolon) and the # (pound or number sign) characters together to add a comment on the same line as a command. set mom_pos(0) 12.4; # set the X coordinate
8-18
Post Building Techniques – Student Guide
mt11060_s — NX 8 — Copyright 2011 Siemens PLM Software
Tcl basics for Post Builder
Tcl procedures Procedures in Tcl are sets of commands that are analogous to subroutines in other languages. You can use common procedures throughout your programs. This makes it easier to create and modify programs. The following example illustrates the structure of a procedure: proc procedureName {arg1 arg2 arg3 ...} {body}
If there is only one argument, you can omit the braces around the argument list: proc procedureName argument {body}
When you define a procedure in Post Builder, proc is inserted , the standard prefix PB_CMD_ is added to the name automatically , and the braces around the body are placed for you . The brace placement is styled for legibility.
8
Post Building Techniques – Student Guide
8-19
Tcl basics for Post Builder
The white spaces adjacent to braces are critical. If you omit a space, your program crashes and you might get one of the following messages: •
No white space between first pair of braces: proc TEST {} ( puts "testing 1 2 3" } wrong # args: should be "proc name args body"
•
No white space between first closing brace and second opening brace: proc TEST { }( puts "testing 1 2 3" } extra characters after close-brace
•
No white space after second opening brace: proc TEST { } (puts "testing 1 2 3" } wrong # args: should be "proc name args body"
•
No white space before second closing brace: proc TEST { } ( puts "testing 1 2 3"} extra characters after close-quote
or proc TEST { } (puts testing} wrong # args: should be "proc name args body"
Use capital letters when you name procedures. Capitals, whether used for the entire name or for the first word, make procedure names easier to locate in scripts. Use lowercase for variable names, so that you can easily distinguish variables from procedures. For example, in Post Builder, is a variable.
MOM_set_csys
is a procedure, and
mom_csys_matrix
In the command: proc HI {} (puts "Hello World!"}
8
proc HI
is the command to define a procedure.
is the name of the procedure.
There are no arguments. Testing at the Tcl command prompt, you see the following: % proc HI {} (puts "Hello World!"} % HI Hello World! %
To call or execute the procedure, use the procedure name. 8-20
Post Building Techniques – Student Guide
mt11060_s — NX 8 — Copyright 2011 Siemens PLM Software
Tcl basics for Post Builder
A procedure can have one or more arguments, and procedures return the value of the last command they execute. For example: % proc MULT {a b} {puts stdout "$a times $b equals [expr $a * $b]} % MULT 3 4 3 times 4 equals 12 %
You can provide default values for variables by grouping the variable and the default value in braces. For example: % proc ECHO {{word "nothing to echo"}} {puts $word} % ECHO fred fred % ECHO nothing to echo
Arguments may contain local and global variables. Example of a procedure: #================================== proc PB_CMD_ptp_size { } { #================================== # Output the current size of the ptp output file. # Add this to the end of the End of Program event. global ptp_file_name global mom_sys_control_out global mom_sys_control_in set ci $mom_sys_control_in set co $mom_sys_control_out # Check the file size MOM_close_output_file $ptp_file_name set ptp_size [file size $ptp_file_name] MOM_open_output_file $ptp_file_name # Put a message for the file size in the ptp file set ptp_feet [expr $ptp_size/120.] MOM_output_literal "$co PTP file size = $ptp_size bytes\ [format "%5.1f" $ptp_feet] feet $ci" }
8
Post Building Techniques – Student Guide
8-21
Tcl basics for Post Builder
Explicitly returning a value from a procedure Procedures return the value of the last command they execute. You can use program logic to return different values by determining which command is executed last. Use the return command with no arguments to return the value of a command. return [expr $x / $y ]
Intermediate-level use of the return command In Tcl, division with the expr command when either operand is a decimal number returns a decimal number. If both operands are integers, you get an integer result: % expr 1.0 /2 0.5 % expr 1 / 2 0
If you divide by zero, you get a terse error message: % expr 1 / 0 divide by zero
The following example procedure is designed to return a string as a formatted decimal value regardless of any valid input, and it gives a more explicit error message. % proc DIV {x y) { if [expr $y == 0] { return -errorcode —code error \ "Division by zero is an illegal operation" } else { if [string is integer $x] {set x $x.0} return [format "%1.4f" [expr $x / $y ]] } }
Examples using the DIV procedure after it is saved as div.tcl:
8
% source div.tcl % DIV 1 2 0.5000 % DIV 1 0 Division by zero is an illegal operation
8-22
Post Building Techniques – Student Guide
mt11060_s — NX 8 — Copyright 2011 Siemens PLM Software
Tcl basics for Post Builder
Basic error handling When Tcl reports an error at run time, your program crashes. To prevent this, you can use the catch command, which works at run time. Returned values are 1, or true, if an error occurs, and 0, or false, if no error occurs. The catch command places error text in the variable that you specify. The general format is: catch {command | procedure} optional variablename
In the following command line examples, -code is an intermediate-level option for the return command, and set errorInfo returns the most recent error text and the name of the command or procedure that caused the error. % proc OOPS {} {return —code 1 Mistake!} % catch {OOPS} myInfo 1 % set myInfo Mistake! % set errorInfo Mistake! while executing "OOPS" %
8
Post Building Techniques – Student Guide
8-23
Tcl basics for Post Builder
Tcl input and output Tcl maintains three standard input and output (I/O) channels: stdin for standard input, stdout for standard output, and stderr for standard error. By default, stdin accepts input from the keyboard and stdout and stderr output text to the Tcl window. puts The puts command places its argument as a string of text to stdout, which is usually the command window. The puts command has the following general format: puts [channel] string
The name of the output channel is optional. If only a single argument is supplied, the argument is output to stdout. % puts Hello, % puts Hello,
stdout "Hello, world!" world! "Hello, world!" world!
It is good programming practice to always supply stdout as the second argument when you want the output to go to standard output. It avoids confusion for anyone who has to interpret your code, and it assists with debugging. gets The gets command reads a string of text from the keyboard that the user terminates by pressing the Enter key. The terminating Enter character is not kept and not counted. The gets command assigns the input to the specified variable, and returns the number of characters it reads, not counting the enter key. % gets stdin title King 4 % gets stdin name Charles III 11 % puts stdout [concat $title $name] King Charles III
8
8-24
Post Building Techniques – Student Guide
mt11060_s — NX 8 — Copyright 2011 Siemens PLM Software
Tcl basics for Post Builder
Combining puts and gets The puts command has an option that is useful when you are prompting for input: puts —nonewline stdout "Please enter your name: " flush stdout
You can follow the puts command with a gets command to prompt the user to enter text on the same line as your prompt. Example script: # myio.tcl proc MyIO {} { global name; # make $name known outside this procedure puts -nonewline stdout \ "Please enter your name: "; # issues the prompt flush stdout; # required to output the incomplete line gets stdin name; # accepts user typing until they press Enter puts "Hello, $name"; # issues a personal greeting }
You can use \ (backslash) before the newline character in procedures to continue a long command over multiple lines. source The source command is another form of I/O. It reads a file into the current Tcl session or program. It is used frequently in Post Builder. For example, near the beginning of your posts, you see the source command used to retrieve a library of standard procedures: source ${cam_post_dir}ugpost_base.tcl
The following example shows a command prompt session to read and use the procedure that is defined in the example for combining puts and gets in a script: % source myio.tcl; # reads procedure into session % unset name; # make certain that name does not exist % MyIO; # executes the procedure Please enter your name: Shengmin Hello, Shengmin
Post Building Techniques – Student Guide
8-25
8
Tcl basics for Post Builder
format The format command lets you control the format in which output is written. For example, you can control the number of decimal places, field width, scientific notation, and so on. The general format for the command is: format specification value1 value2 ...
The specification can contain literal output and formatting instructions. Because the format string can contain white space, substitutions, and special characters, it is common to place format specifications in double quotes. The command operates by scanning the format string from left to right. Each character from the format string is appended to the result string unless it is a percent sign. If the character is % then the characters following the % character are treated as a conversion specifier. Here are some command line examples of using the format command for floating point numbers. % set PI [expr 2.0 * asin(1.0)] 3.14159265359 % puts [format "%1.4f" $PI] 3.1416
In the format specification
"%1.4f":
•
% introduces the rest of the string as a format specification
•
The 1 sets the minimum field width for the output — we have several characters, so the 1 does nothing in this case.
•
The
•
The f tells the interpreter to expect a floating-point number.
.4
specifies 4 decimal precision.
The format string in the following example includes literal text. % puts [format "Pi is approximately %1.4f" $PI] Pi is approximately 3.1416
8
8-26
Post Building Techniques – Student Guide
mt11060_s — NX 8 — Copyright 2011 Siemens PLM Software
Tcl basics for Post Builder
The following example introduces a wider-than-necessary field width, and specifies padding with zeros: % puts [format "%010.5" $PI] 0003.14159
In the format specifier
"%010.5f":
•
% introduces the rest of the string as a format specification.
•
The first 0 instructs the command to pad the output field to the left with zeros, if necessary.
•
The 10 sets the minimum field width for the output at ten characters, including the decimal point and the decimal digits.
•
The .5 specifies a 5 decimal precision. The decimal point and decimal digits take up six characters of the ten-character width, leaving 4 characters for the digit 3 and padding characters.
•
The f tells the interpreter to expect a floating-point number.
The interpreter does its one round of variable substitution before it analyzes the format string. You can place format specifications in variables and use the variables in the format specification. % set myFormat %10.5f %10.5f # The % in the previous line is not the prompt; # it is part of the value returned by the format statement. % format $myFormat $PI 3.14159 # Notice the leading spaces. # The field is 10 characters wide.
Please refer to the Tcl documentation for the complete list of formatting capabilities and the corresponding specifications.
8
Post Building Techniques – Student Guide
8-27
Tcl basics for Post Builder
scan The scan command lets you format text input to your specifications. When you read a line of text from stdin, or from a file, you often want to set one or more variables. The general format of the scan command is: scan text_string format_specifcation var 1 var2 ...
The scan command uses the following format specifications: •
f
— the input field must be a decimal number with an optional sign.
•
d
— the input field must be an integer in the decimal number system.
•
s — the input field consists of all the characters up to the next white-space character.
•
— the input field consists of the characters within the brackets in any order. You can use the dash to represent a range of characters.
•
— the input field consists of characters that do not match any of the characters in the brackets.
[characters]
[^characters]
Please refer to the Tcl documentation for the complete list of formatting capabilities and the corresponding specifications. The scan command returns the number of matches it makes from an input string: % scan "abc" %s result 1 % set result abc
Enclose multiple match patterns in braces so that the specification string is recognized as a single word. The following example matches uppercase letters, a string, lowercase letters, and an integer, and sets four variables in an array:
8
% set claim "NX is number 1" NX is number 1 % scan $claim {%[A-Z] %s %[a-z] %d} r(0) r(1) r(2) r(3) 4 % array get r 0 NX 1 is 2 number 3 1
Match anything but uppercase Z and set one variable: % scan $claim {%[^Z]} great 1 % set great NX is number 1
8-28
Post Building Techniques – Student Guide
mt11060_s — NX 8 — Copyright 2011 Siemens PLM Software
Tcl basics for Post Builder
Match anything but a space character and set one variable: % scan $claim {%[^ ]} product 1 %set product NX
The following example matches a string, anything but a space character, the letters "r e n b u m" in any order, and an integer, and sets four variables: % scan $claim {%s %[^ ] %[renbum] %d} a b c d 4 % set a NX % set b is % set c number % set d 1
The scan command returns zero if there are no matches: % scan $claim {%[AB_34]} nothing 0 % set nothing can’t read "nothing": no such variable
The following shows how the scan command is used in ugpost_base.tcl: set a [scan $mom_tool_use($nn,0) %d tn]
Inside the square brackets, the variable tn is created or modified if a value taken from an array called $mom_tool_use is recognized as a decimal integer. The element from the array is determined by the row index specified by the value of variable $nn, and by the column index "0". Outside the square brackets, a is set to the number of matches returned by the scan statement. If a is 1, then tn contains a tool number from the array location $nn, 0. If a is 0, then either tn is not set, or the value in tn is from a previous assignment. The total effect is to attempt to assign a tool number out of the array $mom_tool_use, and set a flag a to signal success or failure.
8
Post Building Techniques – Student Guide
8-29
Tcl basics for Post Builder
Working with files in Tcl File management is an essential component of postprocessing. In addition to the basic function of writing NC output files, warnings files, and listing files, you can do file-related tasks like the following: •
Write to or append to a log file
•
Write a documentation file
•
Read data files
•
Delete files
To manage files, you can: •
Use Tcl built-in file commands.
•
Call MOM procedures in Post Builder.
I/O channels In file management, you use I/O channels that you create to communicate with files. The channel is called a file identifier, and you store it in a variable. You can use the variable in the same context as you would use stdout, stdin, or stderr. Refer to Tcl documentation for a more advanced type of channel that is beyond the scope of this class. file exists Use the file exists command to check whether a file exists before you attempt to work with it. Command line example: % file exists tclsh.exe 1 % file exists "nonexistent_file" 0
8
Program example: if { [file exists "$result_file"]==1 } { # work with the file named by $result_file }
open The open command opens a file and returns an identifier. The general format for the command is: open filename access permissions
8-30
Post Building Techniques – Student Guide
mt11060_s — NX 8 — Copyright 2011 Siemens PLM Software
Tcl basics for Post Builder
filename
Identifies an existing file. Include the full operating system path if the file is not in the current directory. access
Describes the type of access of which the channel is capable. Unless otherwise specified, the file must exist. The following are the standard flags for access. Advanced users may use the POSIX access flags, not described here. r
Opens the file for reading.
r+
Opens the file for reading and writing.
w
Opens the file for writing. Truncate the file if it exists. Create it if it does not exist.
w+
Opens the file for reading and writing. Truncate the file if it exists. Create it if it does not exist.
a
Opens the file to append data. Data written is appended to the end of the file.
a+
Opens the file for reading and to append data. Data written is appended to the end of the file.
permissions
This argument applies only to Linux systems. Use the format described in the man pages for the chmod command. Command line example: % set fid [open "scratch.txt" w] file633c10
In the previous example, the string file633c10 contains a random hexadecimal number that is guaranteed to be unique.
8
Post Building Techniques – Student Guide
8-31
Tcl basics for Post Builder
The following example from a Post Builder post shows a results file being opened for reading: if { [file exists "$result_file"] } { set fid [open "$result_file" r] # work with the file }
In the example program: •
$fid
can be used to identify the file in an argument to the read command.
•
The double quotes are inserted automatically by Post Builder in case the value being retrieved, a file name, has a space in it. If you are programming the file name directly and you know that the name does not contain a space, you do not need the double quotes.
close Use the close command with a file identifier to close an I/O stream. close $fid
puts Use the puts command without options to write a line of output and a newline character to a file that is open for writing. puts $fid $myString
You can force output without a newline character using the -nonewline option before the first argument. puts —nonewline $fid $myString % set fid [open testfile.txt w] file 1c7d770 % puts $fid "My name is Fred." % puts -nonewline $fid "I write " % puts $fid "postprocessors." % close $fid % set fid [open "testfile.txt" r] file1c7d7e8 % read $fid My name is Fred. I write postprocessors.
8
gets Use the gets command to read a line of input from a file that is open for reading and discard the trailing newline character. Successive use of the gets command reads the file line by line. There are subtleties to distinguishing between blank lines and the end of file when gets is used with only one argument. In this introduction the examples have two arguments: gets $channel line
8-32
Post Building Techniques – Student Guide
mt11060_s — NX 8 — Copyright 2011 Siemens PLM Software
Tcl basics for Post Builder
In the two-argument syntax, gets returns the number of characters read, or 0 for a blank line. With two arguments, when the end of the file is reached, gets returns –1. The following example is used in a procedure. while { [gets $sub line] >=0 } { MOM_output_literal $line } close $sub MOM_output_literal is a procedure that writes a list of literal characters and variables held in the variable $line, without a sequence number.
In the loop condition, the return from gets $sub line is compared to 0 or greater, because the file could include blank lines for which gets returns 0. When the end of file is reached, gets returns –1, the loop terminates, and the file is closed. The net effect is to copy everything in $sub to the NC output file. read The read command can be more efficient that gets because it returns a block of data, which is often all of the remaining data in the specified file. If you do not use any options, read returns all of the data remaining in the file, formatted in the same way as it is in the file. You can use one of the following options, but you cannot combine them. read —nonewline file_id
The –nonewline option discards trailing newline characters in each line of text. read file_id numchars
The numchars argument is an integer number. It modifies the read command to read the specified number of number of characters, or to the end of the file if there are not the specified number of characters remaining. For example, read $fid 80 reads 80 characters from the file identified by $fid. split The split command splits a text string into a Tcl list. The basic syntax is: split string split_characters
Post Building Techniques – Student Guide
8-33
8
Tcl basics for Post Builder
The string specified by the first argument is divided into a list element at every character in the specified splitting characters. A single splitting character is not enclosed in double quotes; however, several characters must be enclosed in double quotes. The splitting characters are discarded, and braces are inserted as needed. % split "my.long.file.name" . my long file name % split "Aqlittlebpuzzlecfordyou" "qbcd" A little puzzle for you
You can specify a null splitting character set to divide a string into characters: % split "Hello, world!" {} H e l l o , { } w o r l d !
Note that the space character is grouped inside braces in the output. The split command groups any word that contains spaces within braces. When the string being split is the contents of a file, for example, a big string returned by the basic read command, the special character \n, the newline character, is used to split the lines into list words: foreach line [split [read $fid] \n] ( # do something with $line }
The foreach command is explained under program flow structures. Working with file specifications The following operations do not require that the file in filename exists, except as specified. file dirname filename
Returns the path to the file identified by filename. If the path is the current directory, on Windows and Linux the single character ‘.’ is returned, and on Mac the character ‘:’ is returned. On Windows, you must escape any backslash characters in the path, or simply convert them to forward slashes. % file dirname "tclsh.exe" . % file dirname "C:\\Windows\\system.ini" C:/Windows % file dirname "C:/Windows/system.ini" C:/Windows
8
Note that the path returned uses the forward slash, as in the Unix or Linux style. file isdirectory filename
8-34
Returns 1 if filename is a directory, or returns 0 otherwise.
Post Building Techniques – Student Guide
% file isdirectory "C:/Windows" 1 % file isdirectory "tclsh.exe" 0
mt11060_s — NX 8 — Copyright 2011 Siemens PLM Software
Tcl basics for Post Builder
file extension filename
Returns all of the characters in the text string filename after and including the last dot in the last element of filename. Elements are strings separated by the / (slash) character. If there is no dot in the last element of filename then an empty string is returned. % file extension "tclsh.exe" .exe % set fid [open "fred" w] file1bc7bd8 % file exists fred 1 % set myext [file extension fred] % info exists myext 1 % string length $myext 0
You can determine if a variable contains an empty string by checking that the variable name is defined, and that the string length of the variable value is zero characters. file normalize filename
Removes all relative path characters the text string filename and returns the full operating system path to the file identified by filename. On Windows, the backslash in the path is replaced by the forward slash. % file normalize "./tclsh.exe" C:/Tcl/bin/tclsh.exe
file size filename
Returns a decimal string giving the size of the file identified by filename in bytes. If the identified file does not exist or if the size of the identified file cannot be queried, an error occurs. % file size "tclsh.exe" 20480
Note that the size of tclsh.exe varies depending on platform and version. file tail filename
Returns all of the characters in the text string filename after the last directory separator. If filename contains no separators, the command returns filename. % file tail "C:/Windows/system.ini" system.ini % file tail "tclsh.exe" tclsh.exe % file tail "C:/Nosuchfolder/nosuchfile.txt" nosuchfile.txt
See the Tcl documentation for a list of the many other arguments that you can use with the file command. Post Building Techniques – Student Guide
8-35
8
Tcl basics for Post Builder
Tests for permissions The file exists command may not give you enough information. For example, you may need to know if the file is readable and writable for the current user, or if the current user is the operating system owner of the file. file readable filename
Returns 1 if the current user has read permission to the file identified by filename, or returns 0 otherwise.
file writable filename
Returns 1 if the current user has write permission to the file identified by filename, or returns 0 otherwise.
file owned filename
filename,
Returns 1 if the current user owns the file identified by or returns 0 otherwise.
Intermediate-level file commands Intermediate-level and advanced-level programmers may refer to the Tcl documentation for information about eof, seek, tell, and glob.
8
8-36
Post Building Techniques – Student Guide
mt11060_s — NX 8 — Copyright 2011 Siemens PLM Software
Tcl basics for Post Builder
Tcl string commands Strings, or sequences of text characters, are the only data type that Tcl stores. As you might expect, the Tcl string command has several arguments that are useful to investigate and manipulate text strings. Several arguments specify an index or position in the string. Tcl follows the common convention of numbering characters in the string beginning with zero; thus, the character with index 1 is actually the second character in the string, and the last character has an index that is one less than the number of characters in the string. There are other commands that work with strings, for example the command splices its arguments together to form one string.
concat
It is not necessary to quote a string argument if it consists of a single word. To view a list of valid arguments for the string command, use an invalid argument for the command at the Tcl command prompt. % string bad bad option "bad": must be bytelength, compare, equal, first, index, is, last, length, map, match, range, repeat, replace, tolower, toupper, totitle, trim, trimleft, trimright, wordend, or wordstart string length str
Returns the number of characters in the string str. In UTF-8 encoding, characters may require two or three bytes. This explains why string bytelength str is also available. % string length "abcdef" 6 % set str abcdef abcdef % string length $str 6 % string length abcdef 6
string tolower str
Returns the lowercase conversion of str. % set str ABC123DEF ABC123DEF % string tolower $str abc123def
8
The string tolower command has optional arguments. You can specify the indices of the first and last characters to convert, or you can specify one index, to convert only the specified character. Remember that string indices start at 0. % string tolower $str 0 1 abC123DEF % string tolower $str 7 ABC123DeF
Post Building Techniques – Student Guide
8-37
Tcl basics for Post Builder
string toupper str
Returns the uppercase conversion of the same as string tolower.
str.
The syntax is
% set myUpper [string toupper "g17 g20 g40"] G17 G20 G40 % set myUpper G15 G20 G40 string range str first last
Returns the range of characters in the string between the first and last integer indices. This is the Tcl equivalent of the substring command in other languages. No error occurs if last is greater than the last valid index. % set home "G28 G91 X0 Y0 Z0" G28 G91 X0 Y0 Z0 % string range $home 0 6 G28 G91 % set newHome [concat [string range $home 0 6] \ [string range $home 13 15]] G28 G91 Z0
string trim str
Removes all whitespace characters from the beginning and end of str. The trim argument is useful to get rid of unwanted spaces, tabs, and so on from user input. % set bulky "\t abc \t" abc % string length $bulky 11 % set slim [string trim $bulky] abc % string length $slim 3
string trim str characters
Removes any or all of the specified characters if they appear in any order at the beginning or end of str. % string trim ababcdebaba ab cde
string trimleft str and string trimright str
8
Work like string trim except that they remove whitespace or optional characters only from the left or right of the string. These commands are useful when characters that you want to keep:
string trim
removes
% string trim "N3670 G01 X100.35 Y50.10 F100" "N 0123456789" G01 X100.35 Y50.10 F
Although the intention was to remove any possible sequence number, the value of the feed rate word is also removed! The string trimleft command avoids this problem:
% string trimleft "N3670 G01 X100.35 Y50.10 F100" "N 012345678 G01 X100.35 Y50.10 F100
8-38
Post Building Techniques – Student Guide
mt11060_s — NX 8 — Copyright 2011 Siemens PLM Software
Tcl basics for Post Builder
string is double and string is double —strict
There are several similar commands to see what kind of value is represented by a string. Arguments include alpha, boolean, false, true, and several more. These commands return 1 if the string is a valid member of the specified class, otherwise it returns 0. If the parameter -strict is specified, an empty string returns 0, otherwise, an empty string always returns 1. % string trim "N3670 G01 X100.35 Y50.10 F100" "N 0123456789" G01 X100.35 Y50.10 F
Although the intention was to remove any possible sequence number, the value of the feed rate word is also removed! The string trimleft command avoids this problem: % 1 % 1 % 0 % 1 % 0
string is double 10.0 string is double 25 string is double "fred" string is double "" string is double —strict ""
8
Post Building Techniques – Student Guide
8-39
Tcl basics for Post Builder
Activity: Construct a simple procedure In the Tcl basics for Post Builder section, do the following activity: •
Construct a simple procedure
8
8-40
Post Building Techniques – Student Guide
mt11060_s — NX 8 — Copyright 2011 Siemens PLM Software
Tcl basics for Post Builder
Program flow control Tcl has flow control commands for conditional execution or branching, and for looping. In branching, you define logic to control which statements are executed. In looping, you set a test to determine how many times a loop of commands is repeated. if then else The branching structure uses the following general command formats. if
example: if {test} { # commands to execute if the test result is true }
if else
example:
if {test} { # commands to execute if the test result is true } else { # commands to execute if the test result is false } if elseif else
example:
if {test_1} { # commands to execute if the test_1 result is true } elseif {test_2} # commands to execute if the test_2 result is true } else { # commands to execute if both test results are false }
The then command is optional in Tcl. If the test is a long string of code, use then to make your code easier to read. if {long test statement, perhaps more than 1 line} then { # commands to execute if the test returns true }
The white space around the braces in if commands is critical, but not as critical is it is with procedure syntax. You must place white space after a closing brace. The error message is extra characters after close-brace. The constructions } else { and } elseif { must be on the same line of code, and spaced. Error messages include invalid command name else{ and invalid command name elseif{.
Post Building Techniques – Student Guide
8-41
8
Tcl basics for Post Builder
The test can be a command that returns an integer, or a logical comparison. Remember that Tcl is a string-based language, so you need to be mindful of formatting and tolerances when you compare numbers. Operator == != > >= < 360.0} { set a4 [expr $a4-360.0] }
If the variable a4 is larger than 360, this loop executes, subtracting 360 from a4 on each iteration, until a4 is less than 360. Note that if a4 is ever exactly 360, the loop is going to execute one last time, because the test comparison operator is < (less than), and not