【www.arisingsemi.com--软件制图】

定制英文
POST BUILDER CUSTOM COMMANDS
In this NX A to Z article, we are going to talk about writing custom commands in Post Builder. Custom commands allow you to get just about whatever you want in your machine code file. We all know that the graphical tools within Post Builder provide a great way to configure the standard components of a postprocessor, but what about the non-standard stuff – that is what custom commands are for.  For an introduction to Post Builder, click here.
TCL
Postprocessors written for NX are written in a language called TCL (Tool Command Language). TCL is a scripting language, meaning that it is not compiled, and it’s syntax resembles C. TCL is a fairly straightforward language; however, it’s syntax can be troublesome. The link below is a very good resource for learning TCL; however, the best method for writing TCL is to copy it from an existing custom command that implements the same function you are trying to implement and then change the variables and expressions as required. For example, if you are trying to write and if…else loop, just find one in an existing custom command and change it as required to suit your desired functionality. This will help to eliminate a lot of the headaches due to syntax errors.
/doc/tcl/
Manufacturing Output Manager (MOM)
Before you write custom commands, you first need to understand how NX communicates with your postprocessor. When you postprocess a program from with NX, NX starts a program called NX Post. The primary component of NX Post is the Manufacturing Output Manager (MOM). MOM is described in the NX Help Documentation as follows: The Manufacturing Output Manager (MOM) is the central core of the NX Post postprocessor module. MOM converts tool paths from model files into manufacturing output (machine code) by adding the required functions and data as described below:
▪ The Event Generator reads through the tool path data, extracts events and their associated variable information, then passes the events to MOM for processing.
▪ MOM applies kinematics to the output then passes the event with its associated data to the Event Handler.
▪ The Event Handler creates the event, processes it to determine the actions required, then returns the data to MOM.
▪ MOM reads the Definition File to determine how to format the output for the machine tool control.
▪ MOM writes the formatted output to the specified Output File as machine code.
So, essentially, MOM reads the tool path in NX and then feeds the tool path through the postprocessor to generate the machine code. In order to write custom commands, you have to intercept the information that MOM is sending to the postprocessor and then manipulate it however you want and then send it to the machine code file. All of the information that MOM sends is in the form of MOM variables; furthermore, there are built-in commands available for you to use in your custom command and these are called MOM commands. You can see all of these variables and built-in commands and their descriptions by clicking on the Utilities menu in Post Builder and select Browse MOM Variables. You will see the window shown built-in commands start with an uppercase MOM and the variables with lowercase mom. There are way too many built-in commands and variables to go through them. The approach that we will use is to set out to do something specific with our postprocessor and then used the MOM Variables browser to find the variables and built-in commands we need. So the next step is to open our postprocessor and select the Custom Commands tab as shown below. This is a postprocessor that comes with NX for a 5-axis table table mill. Most of the custom commands that you see in the list are created by default when you create a new postprocessor. Some are used by default in certain parts of the program and the rest are available should you need them. For example, the custom command shown below, PB_CMD_tool_change_force_addresses is put into the tool change event by default when a new post is created. It uses the MOM_force built-in command to force the output of the tool length compensation data. Custom commands like PB_CMD_clamp_fourth_axis are driven by machine control events in NX and do not appear in any tool path events. Custom commands like PB_CMD_nurbs_initialize are not used by default and must be placed in an event marker after the post has been created if they are to be used. There is also a library of custom commands available to be imported into a postprocessor. If you click Import you will see the list shown below. There a lot of custom commands available and they are described in the Documentation under Manufacturing->Post Builder->Program and Tool Path->Custom Command->Custom Command Library. So enough about all the custom commands that are already done, let’s write one of our own. It is just a simple custom command to put name of the program at the start of the machine code file. In Post Builder, click Create on the Custom Command tab and Post Builder will create a copy of whatever custom command you have selected as shown below. So delete all the code and rename the custom command PB_CMD_program_name. Now we need a variable that comes from NX with the name of the program and a built in command that will output the name to the machine code file. If you open the MOM Variables Brower and search program name, you will see that mom_group_name is the variable that we want and if you set the search category to MOM Commandand search for output, you will see that MOM_output_literal is the build in command that we want. So in our Custom command, we type global mom_group_nameMOM_output_literal “Program Name: $$mom_group_name” The first line is a variable declaration. We are declaring the variable mom_group_name and the global statement indicates the scope of the variable. The global scope is the entire MOM process, meaning that if there is already a variable with the name mom_group_name that exists anywhere in the MOM process, we will be accessing that variable. It also means that if we change the variable, it will be changed for the entire MOM process until it is changed again by MOM. So essentially we are grabbing the mom_group_name variable from MOM and writing it out the machine code file. The $$ in the second line is a syntax character – it indicates that the word that follows is a variable name and substitutes the variables value into the output. This is shown below Then we place this custom command in the Program Start Sequence as shown belowThen post a program and this is what you get That’s it. Remember, your best bet is to find an existing custom command that does something similar to what you want and start changing it to get what you want. We’ll talk about debugging custom commands in a future article. 

本文来源:http://www.arisingsemi.com/it/66859/