NX Postprocessor Support
A comprehensive VS Code extension providing language support and remote debugging for NX CAM postprocessor development, including CDL, TCL, and DEF files.
Features
- Syntax Highlighting - Full syntax highlighting for CDL, TCL, and DEF files
- Code Formatting - Automatic code formatting for all supported file types
- Multi-language Support - Supports NX CDL, TCL, and DEF file formats
- Intelligent Code Analysis - Linting and error detection for postprocessor code
- Auto-completion - Context-aware code completion for faster development
- Signature Help - Shows parameters and documentation for custom and NX procedures
- Call Hierarchy - Traces incoming and outgoing calls between custom TCL procedures and MOM event handlers
- Document Highlights - Highlights all reads, writes, and calls of the symbol under the cursor
- Context-aware Completion - Prioritizes local symbols and suggests variables, procedures, namespaces, paths, Tcl subcommands, valid argument values, and options based on cursor context
- PSC and TclOO Classes - Indexes Tcl scripts referenced by PSC layers, including external folders. Classes from indexed files provide method completion, signature help, parameter hints, and class highlighting in other files. PSC script names may omit
.tcl; relative folders resolve from the PSC directory, and environment-variable folders are supported. Missing scripts are reported in the output channel; encrypted libraries cannot supply static class metadata.
- DEF Block Templates and Addresses - Reads the
.def files listed under <DefinedEvents> in PSC layers and suggests their BLOCK_TEMPLATE and ADDRESS names, see DEF block templates and addresses
- DEF Editing Support - Inside
.def files: completion of formats and addresses, a preview of how a FORMAT outputs numbers, and a hover over block templates that previews the whole NC block, see Editing DEF files
- Tcl Snippets - Inserts placeholder-based structures for
if, foreach, proc, switch, try, and dict for
- NX Tcl Remote Debugger - Breakpoints, stepping, call stack, scopes, variables, watches, evaluation, logpoints, hit conditions, and Tcl error stops directly in a running NX Post process
Supported File Types
.cdl - NX User Defined Event File
.tcl - NX TCL postprocessor files
.def - NX Definition files
Installation
- Install from the VS Code Marketplace
- Install Python 3.12 or higher
- Open any
.cdl, .tcl, or .def file
- The extension will automatically activate and provide language support
The former standalone NX Tcl Remote Debugger extension is no longer required. Disable or
uninstall local-nx.nx-tcl-debug before using the integrated debugger because both extensions
register the same nx-tcl debug type.
Configuration
The extension can be configured through VS Code settings:
nx-post-support.interpreter - Specify custom Python interpreter path for the language server
nx-post-support.formatter - Enable/disable the TCL formatter (default: false)
nx-post-support.inlayHint - Enable/disable inlay Hints (default: true)
nx-post-support.inlayHints.parameterNames - Show parameter names for all, only literals, or none (default: all)
nx-post-support.inlayHints.suppressWhenArgumentMatchesName - Hide redundant hints such as value: before $value (default: true)
TCL files default to unlimited inlay hint length so that VS Code does not
truncate later parameter names on a line. An explicit user setting for
editor.inlayHints.maximumLength still takes precedence.
DEF Block Templates and Addresses
The language server resolves the .def files of every PSC layer's <DefinedEvents> section the
same way as layer scripts (relative to the PSC, SubFolder, environment variables, missing .def
extension) and collects all BLOCK_TEMPLATE and ADDRESS declarations. Changes to PSC or DEF files
are picked up automatically.
| Command |
Suggestions |
MOM_do_template |
Block templates, then variables |
MOM_ask_address_value |
Addresses, then variables |
MOM_force, MOM_suppress |
1st argument: Always, Once, Off, then variables; further arguments: addresses, then variables |
Block templates, addresses, and Always|Once|Off are inserted in quotes ("steady_rest"); a quote
that is already typed or auto-closed is replaced instead of doubled. Variables are inserted with a
leading $. Typing $ yourself still shows variables only.
Three keywords list all loaded names anywhere in a Tcl file:
BLOCK_LIST - shows all block templates
ADDR_LIST - shows all addresses
FORMAT_LIST - shows all formats with their specification (Tcode &_02_00); the details of a
selected format show example values as in the format preview
Select the keyword from the completion list (or type it completely) to open the list; text typed
directly after the keyword, such as ADDR_LISTSP, narrows it. The keyword is replaced by the
selected quoted name.
Navigation between Tcl and DEF files
Block template and address names are linked to their declarations in the PSC .def files:
- Go to Definition (F12) on
MOM_do_template "steady_rest" or MOM_force Once X jumps to
BLOCK_TEMPLATE steady_rest or ADDRESS X. Inside a .def file, an address used in a block
template (X[$mom_pos(0)]) jumps to its ADDRESS declaration.
- Hover shows the body of a block template, or the format (resolved to its
FORMAT
definition), leader, trailer, min/max, and modality (FORCE) of an address.
- Find All References (Shift+F12) lists the declaration, all Tcl calls, and all block templates
that use an address.
- Rename (F2) changes the declaration and all usages in Tcl and
.def files together. Only
names declared in a loaded .def file can be renamed.
Recognized Tcl commands: MOM_do_template, MOM_add_to_block_buffer, MOM_polar_motion,
MOM_force_block, MOM_ask_address_value, MOM_add_to_address_buffer, MOM_enable_address,
MOM_disable_address, MOM_force, MOM_suppress, MOM_incremental, and
MOM_ask_definition_element/MOM_has_definition_element with ADDRESS or BLOCK. Names built
from variables (MOM_do_template $name) cannot be resolved statically.
Editing DEF Files
Inside .def files the extension uses all FORMAT, ADDRESS, and BLOCK_TEMPLATE declarations
of the current file and of the .def files loaded through the PSC layers. When a name is declared
in several layers, the last loaded declaration wins, as in NX.
| Position |
Suggestions |
After FORMAT or ZERO_FORMAT in an ADDRESS |
All formats with specification and output preview, e.g. Digit_command &__2_00 → G5 |
At the start of a line in a BLOCK_TEMPLATE |
All addresses with format and output preview, e.g. N Digit_4 &__4_00 → N5 |
- After
ZERO_FORMAT, formats whose name contains zero are listed first.
- A new block template element is inserted as
N[] with the cursor between the brackets. If the
line already has an element such as N[$mom_seqnum], only the name is replaced.
- The details of a suggestion show the same information as the hover.
FORMAT Name "spec" declarations outside an address get no suggestions.
Hover over a format name to see how it outputs numbers:
- after
FORMAT in an address: specification, description, and example values including the
address LEADER and TRAILER,
- after
ZERO_FORMAT: the output of the value 0,
- on the name of a
FORMAT declaration: the example values without leader and trailer.
FORMAT Digit_command "&__2_00"
FORMAT Zero_command "&_01_0_"
ADDRESS G_cutcom
{
FORMAT Digit_command ← hover: 5 → G5, -12.3456 → G-12, ...
ZERO_FORMAT Zero_command ← hover: 0 → G0
LEADER "G"
}
The address hover shows the same preview in its Format and Zero format rows.
Supported format specifications:
| Specification |
Meaning |
&<sign><lead><digits><point><decimals><trail> |
NX format: sign + (always) or _ (only -); lead 0 (leading zeros) or _; number of integer digits; point . (decimal point) or _; number of decimals; trail 0 (trailing zeros) or _ |
%s, %d, %.3f, ... |
printf format |
Examples:
| Format |
1.5 |
0.5 |
0 |
5 |
&__5.3_ |
1.5 |
.5 |
0. |
5. |
&_01.3_ |
1.5 |
0.5 |
0. |
5. |
&_01.40 |
1.5000 |
0.5000 |
0.0000 |
5.0000 |
&_02_00 |
02 |
01 |
00 |
05 |
&+05.3_ |
+00001.5 |
+00000.5 |
+00000. |
+00005. |
Values are rounded half up. Integer digits are a minimum width with leading zeros; longer
numbers are not cut.
Block template preview
Hover over a block template, in a .def file or on a Tcl call such as
MOM_do_template channel_init, to see its source, a preview of the whole NC block, and a table of
all its addresses:
Preview: G40 G99 G0 … X99999.999 … D99 M… F99 (… = value of a variable)
| Address |
Expression |
Format |
Output |
G_cutcom |
40 |
Digit_command &__2_00 |
G40 |
G_unit \opt |
99 |
Digit_3 &__3_00 |
G99 |
M_spindle |
$mom_sys_spindle_direction_code(OFF) |
Digit_command &__2_00 |
e.g. M5 |
- Literal values such as
G_cutcom[40] are formatted exactly as NX outputs them.
- Values from variables are shown as
… in the block preview and with a sample value in the table.
\nows joins the next element without a space, so POCKET4 previews as POCKET4(…,…,…).
- Modifiers such as
\opt are listed next to the address.
Text[M60] outputs M60. Addresses that no loaded .def file declares are marked not declared.
- Hover over an element such as
N[ ] to see the full address.
Leaders and trailers
Leaders and trailers are shown as far as they are known without running NX:
| Declaration |
Preview |
LEADER "G" |
G |
LEADER [$mom_sys_leader(G)], [$mom_sys_leader(M_spindle)] |
G, M (the usual value) |
LEADER [$mom_sys_leader(fourth_axis)] |
‹fourth_axis› |
TRAILER [$mom_sys_trailer(X)] |
empty |
other [...] expressions |
‹expression› |
NX Tcl Remote Debugger
Add a VS Code attach configuration
Create .vscode/launch.json through Run and Debug: create a launch.json file and select
NX Tcl: Attach to NX Post, or use this configuration:
{
"version": "0.2.0",
"configurations": [
{
"type": "nx-tcl",
"request": "attach",
"name": "Attach to NX Post Tcl",
"host": "127.0.0.1",
"port": 4711,
"connectTimeout": 120000,
"stopOnEntry": false,
"breakOnError": true,
"localRoot": "${workspaceFolder}"
}
]
}
When VS Code and NX see the source through different roots, set remoteRoot to the root used by
NX and keep localRoot as the corresponding workspace root.
Start debugging
- Set breakpoints on executable Tcl or DEF commands.
- Start Attach to NX Post Tcl in VS Code before running the postprocessor.
- Start postprocessing in NX.
- Use Continue, Step Over, Step Into, Step Out, Pause, Variables, Watch, and the Debug Console as
with a normal source debugger.
Breakpoints remain active and stop at every real invocation. Use a hit condition such as 1 for
a one-time stop. Blank lines, comments, declarations, and multiline Tcl commands may be relocated
to the nearest executable command; VS Code shows the resolved line. Dynamic
LIB_GE_command_buffer_edit_* bodies are mapped back to their original source and owning Tcl
procedure.
Usage
Simply open any supported file type and enjoy:
- Syntax highlighting
- Error detection and linting
- Code completion
- Code formatting (Format Document command), including
uplevel bodies and a space after # in comments
- Hover information
- Signature help while entering procedure arguments
- Incoming and outgoing call hierarchy for custom procedures and MOM event handlers
- Document-wide highlights for procedure and variable occurrences
- Context-aware completion with local symbols ranked before workspace and built-in symbols, plus semantic arguments, local paths, Tcl subcommands, and options such as
string compare -nocase
- Placeholder-based snippets for common Tcl control structures and procedures
- Block template, address, and format suggestions from PSC DEF files, including
BLOCK_LIST, ADDR_LIST, and FORMAT_LIST
- Go to Definition, hover, references, and rename for block templates and addresses across Tcl and DEF files
- Format and address completion in DEF files, format preview, and NC block preview for block templates
- Remote NX Tcl debugging with breakpoints and full stepping
Contributing
This extension is actively maintained. For issues or feature requests, please visit our repository.
License
AGPL-3.0 License - see LICENSE file for details.
| |