MxServiceCode CLI Command Reference
Compiled from the project source (
src/MxCommand.ts,src/sample/*.ts). MxServiceCode is a Node.js command-line project; the entry point ismxapp.js, and the process exits after each command (no daemon).
I. Invocation Format
<node executable> mxapp.js <command> param1=value1 param2=value2 [debug=1]- Built-in runtime: Windows
bin\node.exe, Linux./node(located in the project directory) - On Linux you may add
linux=1to force Linux-mode execution - Output: one line of JSON on stdout; on success
codeorretis 0
II. Command Overview (12 commands)
| Command | Function |
|---|---|
| convert | ⚠️ Unusable (wgh format deprecated; see detailed 1); use mxcadassembly directly for DWG→mxweb |
| getcaddata | Extract text/block attribute data from a drawing to JSON |
| getPolylineTheSpecifiedLayer | Extract vertex data of all polylines on a specified layer to JSON |
| testParamDraw | Parametric drawing: lines/dashed lines/blocks/title block/text/hatch |
| testParamDrawTk | Parametric drawing: insert title block frame (A3) + title block (BT) |
| compare_dwg | Compare whether the block table contents of two DWG files match |
| frameCut | Batch cutting by title block frame blocks (⚠️ depends on the 1337 service, not provided in the standalone edition; use frameCut2) |
| frameCut2 | Batch cutting by title block frame blocks (calls mxcadassembly directly; recommended) |
| getAllLayer | Get all layer information of a drawing as JSON |
| margeDwg | Merge multiple DWGs into a target DWG (layer filtering supported) |
| mxtest_getxdata | Debug example: read extended data, geometry calculations, intersection (hardcoded paths; do not use in production) |
| Mx_Custom_ExportPdf | Export the whole drawing to PDF (auto-scaled to sheet size, includes title block frame location info) |
There is also a generic entry fileparam (JSON file parameter passing; see section 5).
III. Command Details
1. convert — DWG to frontend display file (unusable)
bin\node.exe mxapp.js convert file=t1.dwg- Parameter:
filesource DWG path (relative paths are relative to the project directory)
⚠️ Tested: unusable: returns
{"code":-4,"message":"js program exception, see log for details"}; the log showsTypeError: this.imp.writeWebGLFile is not a function. Reason: the wgh format output bywriteWebGLFileis deprecated and the new native module has removed that function; the mxcad frontend only accepts mxweb.Workaround (recommended): call
mxcadassemblydirectly (see "Deployment and Startup Notes" section 3):js// Run with the project's built-in node (CommonJS); put the source drawing in the converter directory const { execFileSync } = require('child_process'); const jsonStr = JSON.stringify({ srcpath: 't1.dwg', outname: 't1.mxweb', outpath: './out' }); const enc = encodeURIComponent(jsonStr); // percent-encoding, NOT plain hex! const out = execFileSync('mxcadassembly.exe', ['[' + enc + ']'], { cwd: '<converter directory>', encoding: 'utf8', timeout: 180000 }); // Output {"code":0,"message":"ok"}; produces out\t1.mxweb (relative to the converter directory)Notes: ① In the source, this command concatenates
curPath + param.filedirectly — passing an absolute path produces an invalid path; the workaround accepts an absolute path viasrcpath. ② Theoutpathdirectory must pre-exist (the program does not create it; otherwise it returns{"code":2,"message":"write file error"}).
2. getcaddata — Drawing data extraction
bin\node.exe mxapp.js getcaddata file=t1.dwg outfile=t1.json- Parameters:
filesource DWG;outfileoutput JSON path - Behavior: extracts all text (TEXT) and block attributes (INSERT attributes) in the drawing; each item contains the text content, coordinates (posx/posy), and the owning layer
- Returns:
{"ret":0,"resultfile":"<output file>"} - ⚠️ Limitation: extracts TEXT and block attributes only — no geometry entities (lines/polylines/circles, etc.). For geometry data, do secondary development (see the example in section 9 of "Mx2DNodeSecondaryDevAPIReference.md"). The output is an array; each item contains fields such as
layer
3. getPolylineTheSpecifiedLayer — Polyline extraction on a specified layer
bin\node.exe mxapp.js getPolylineTheSpecifiedLayer file=t1.dwg outfile=t1.json [debug=1]- Behavior: extracts the vertex sequences (x/y/z/bulge) of LWPOLYLINE entities whose layer name matches. The layer name filter value is hardcoded in
GetDwgData.ts; modify it for the target drawing before use - Returns:
{"ret":0,"resultfile":"<output file>"} - ⚠️ Limitations: ① extracts LWPOLYLINE only; no other geometry such as LINE; ② the layer filter value is hardcoded in
GetDwgData.ts— before using across drawings you must change the source and recompile withnpm run build
4. testParamDraw — Parametric drawing
bin\node.exe mxapp.js testParamDraw outfile=testdraw.dwg [debug=1]- Behavior: based on the blank template, draws lines, dashed lines (custom linetype), block references (tree.dwg), text (SimHei), and pattern hatching (rectangular path). The drawing logic lives in the
TestDrawclass ofsample/ParamDraw.ts; replace that drawing code for secondary development - Returns:
{"ret":0}
5. testParamDrawTk — Title block frame + title block generation
bin\node.exe mxapp.js testParamDrawTk outfile=testdrawtk.dwg [debug=1]- Behavior: inserts the title block frame (the A3 block of A3.dwg) + the title block (the BT block of BT.DWG) and fills in the title block attribute text. The frame/title block DWGs must sit at the same level as the project directory
- Returns:
{"ret":0}
6. compare_dwg — Drawing comparison
bin\node.exe mxapp.js compare_dwg file1=t1.dwg file2=t2.dwg- Behavior: bidirectionally compares object differences among all entities in the two drawings' block tables (aligned by handle)
- Returns:
{"ret":0}when identical; non-zero means differences exist (negative values mean missing objects) - ⚠️ Limitation: compares only the block table contents (block definitions), not whole-drawing geometry
7. frameCut — Cutting by title block frames (1337 service edition; unusable in the standalone edition)
bin\node.exe mxapp.js frameCut file=testcut.dwg tkname="Frame0521" outtype=.pdf [debug=1]- Parameters:
filesource DWG;tknametitle block frame name prefix;outtypeoutput format suffix (.pdf/.dwg); optionalsavefileoutput prefix,colorPolicy - Behavior: selects blocks whose names start with tkname → sorts them by rows in the Y direction → calls the port-1337 service one by one to cut each by its bounding rectangle
- The standalone MxServiceCode does not provide the 1337 service, so this command is unusable; use
frameCut2(functionally equivalent; see detailed 8) - Returns (when a service is available):
{"code":0,"cutnum":n,"errornum":0}
8. frameCut2 — Cutting by title block frames (mxcadassembly edition; recommended)
bin\node.exe mxapp.js frameCut2 file=testcut.dwg tkname="Frame0521" outtype=.pdf width="5000" height="3000" [colorPolicy=mono]- Parameters:
file,tkname,outtype(.pdf/.dwg/.mxweb);width/heightoutput size;colorPolicycolor policy - Behavior: same selection and sorting as frameCut, but calls
mxcadassemblylocally to run thecut_dwgcutting — no dependency on the 1337 service; withouttype=.mxwebit first cuts to DWG and then converts to mxweb - Returns:
{"code":0,"cutnum":n,"errornum":0,"out_files":[...]}
9. getAllLayer — Layer information extraction
bin\node.exe mxapp.js getAllLayer file="A.dwg"- Behavior: outputs
<source filename>_layers.jsoncontaining each layer's name, colorIndex, color, and off (whether turned off) - Returns:
{"ret":0,...} - ⚠️ Limitation: outputs only the layer table information; no entities on the layers
10. margeDwg — Drawing merge
bin\node.exe mxapp.js margeDwg file="mB.dwg" marge_file="mA.dwg" out_file="mC.dwg" marge_layer="['2306','2307']" [debug=1]- Parameters:
filetarget DWG (opened and kept);marge_filethe DWG(s) to merge in (a single file, or a JSON array string['a.dwg','b.dwg']for multiple);out_fileoutput file;marge_layeroptional — merge only the specified layers (JSON array string) - Returns:
{"code":0,"message":"ok"}
11. mxtest_getxdata — Extended data debugging
bin\node.exe mxapp.js mxtest_getxdata- A debug example: opens a hardcoded-path DWG and demonstrates xdata read/write,
explode(decomposition), curve area (getArea), and intersection of two entities (intersectWith). File paths are hardcoded in the source; for reference only. - ⚠️ Limitation: hardcoded file paths — must not be used directly in production; an API usage example only
12. Mx_Custom_ExportPdf — Whole-drawing PDF export
bin\node.exe mxapp.js Mx_Custom_ExportPdf file="TkPdf.dwg" outfile="TkPdf22.pdf" pdf_width=1500 pdf_height=2500- Parameters:
filesource DWG;outfileoutput PDF;pdf_width/pdf_heightPDF size (default 1500x2500) - Behavior: scales the whole drawing to the sheet ratio and outputs a PDF (black and white), and computes the coordinate range of the title block frame (located based on the "version/design/drawn by" texts) within the PDF
- Returns: the print_to_pdf result +
tk,x1/y1/x2/y2coordinates - ⚠️ Limitation: title block frame localization depends on the "version/design/drawn by" texts inside the title block; if the title block does not match, the
tklocation may fail
IV. General Parameter Notes
- Path parameters: relative paths are relative to the MxServiceCode project directory (the directory containing
mxapp.js). Convention: put target files in the project directory and pass relative paths - ⚠️ Do not pass absolute paths (tested): some commands' source does direct string concatenation
curPath + param.file(e.g.getcaddata,getPolylineTheSpecifiedLayer); an absolute path produces an invalid path colorPolicyvalues:noPolicy(default, keep original colors),mono(black and white)- Error code convention:
0success;1~8parameter/file errors;-1~-5program/file open errors
V. fileparam — JSON File Parameter Mode
A command can take a JSON file in place of command-line parameters (suited for complex parameters or special characters):
bin\node.exe mxapp.js fileparam filepath="testcut.dwg_param.json"JSON file contents:
{
"cmd": "frameCut2",
"file": "testcut.dwg",
"tkname": "Frame0521",
"outtype": ".pdf",
"width": "5000",
"height": "3000"
}The cmd field names the command actually executed; the remaining fields are that command's parameters.
VI. Secondary Development Guide
- New command: create a .ts under
src/sample/with a handler function (takes aparamobject, returns a JSON object), register it viaMxProcessor.addCommand("command name", function)inReginstCommand()ofsrc/MxCommand.ts, then recompile withnpm run build - All drawing/data APIs: see "Mx2DNodeSecondaryDevAPIReference.md"
- Runtime environment, logs, and test scripts: see "Deployment and Startup Notes"
