CAD Drawing Operations · Backend MxServiceCode Guide
Scope: server-side CAD drawing processing (Node.js command line: format conversion, data extraction, parametric drawing generation, splitting/merging, batch export). Routing rules: see Entry Guide; frontend operations: see Frontend mxcad Guide.
Contents
- I. What MxServiceCode Is
- II. Program Acquisition & Directory Structure
- III. Local Reference Docs (must read)
- IV. Task → Command Selection Quick Reference
- V. Task → Doc Lookup Guide
- VI. Capability Boundaries
I. What MxServiceCode Is
MxServiceCode is a standalone Node.js command-line project for processing CAD drawing files on the backend: open/save DWG, format conversion, data extraction, parametric drawing generation, batch cutting by title block frames, merge/compare, PDF export, and so on.
How it works: invoked from the command line, it runs one command and exits — no daemon, no service to start. The entry point is mxapp.js; each run executes one command and prints one line of JSON to stdout; the project ships a built-in Node runtime, so the system Node is not required.
Contents of the backend service zip (contains BOTH the backend service and the format conversion program mxcadassembly — the complete superset; if only the conversion program is needed, download the standalone MxConvert package instead — see the "Link List" in the Entry Guide):
Windows (the backend service zip extracts to a single top-level dir MxServiceCode_TryVersion\, with two subdirectories inside):
MxServiceCode_TryVersion\ ← Top-level dir after extraction (same name as the zip)
├── MxServiceCode\
│ ├── NODE.JS后台程序开发.doc ← Official tutorial: how to do backend development based on this project (NOT an API doc)
│ ├── MxServiceCode.sln ← Solution file
│ └── MxServiceCode\ ← Project directory (all commands run here)
│ ├── bin\node.exe ← Built-in Node runtime
│ ├── Mx2DNode.node ← Native module (core CAD capabilities)
│ ├── mxapp.js ← Entry point (command line)
│ ├── package.json ← npm run build for compilation
│ ├── src\ ← TS sources (mxcad\ = API classes, sample\ = feature samples, MxCommand.ts = command registration)
│ ├── test.bat ← Test script
│ ├── empty_template.dwg ← Blank template
│ ├── A3.dwg / BT.DWG ← Title block frame / title block sample blocks
│ └── t1.dwg / tree.dwg ← Test drawings
└── MxCAD\
└── Release\ ← Format conversion program directory (mxcadassembly.exe + fonts\ + runtime deps, etc.)Linux (the backend service zip extracts to a single top-level dir MxServiceCode_TryVersion\, with two subdirectories inside):
MxServiceCode_TryVersion\ ← Top-level dir after extraction (same name as the zip)
├── MxServiceCode\
│ ├── NODE.JS后台程序开发.doc ← Official tutorial
│ └── MxServiceCode\ ← Project directory (no .sln; the built-in runtime is `node`, not bin\node.exe;
│ also contains start_demo_MxServiceCode.sh, start_demo_systemlib_MxServiceCode.sh, Linux启动说明.txt)
└── Linux\
└── MxCAD\ ← Format conversion program directory (mxcadassembly + fonts\ + runtime deps, etc.)II. Program Acquisition & Directory Structure
2.1 Download & Placement (fixed temp path; download once, reuse across sessions)
Download URLs: follow the "Link List" in the Entry Guide (take the "backend service" row for the target machine's platform; the Linux package is built for Ubuntu 20.04 x86_64). Trial version — mind the license expiry.
Fixed temp path: Windows = %TEMP%\MxCAD\, Linux = /tmp/MxCAD/. Follow the check steps in the Entry Guide: first determine what the task needs (conversion program only / backend service needed), then inspect what is in the temp path — nothing there → download the matching zip per need (conversion program only → standalone MxConvert package; backend service needed → MxServiceCode package, which includes the conversion program) and extract it to the temp path; conversion program only present → if only the conversion program is needed, run the expiry check (see "Deployment and Startup Notes") and use it; if the backend is needed, clear and re-download the backend package; backend package already extracted → run the expiry check + integrity verification, and if incomplete, clear and re-download. The temp path MUST be cleared before any re-download (each package has a fixed structure; the backend package is the complete superset). Do not scan other directories on the user's machine; after the system cleans the temp dir, just re-download.
All commands run in MxServiceCode\MxServiceCode (the project directory) under the temp path.
2.2 Basic Usage (Linux first use requires permission setup)
chmod 777 start_demo_MxServiceCode.sh
./start_demo_MxServiceCode.sh # the script already chmods node, Mx2DNode.node, mxcadassembly, etc.If it fails, use ./start_demo_systemlib_MxServiceCode.sh instead (uses the native libraries in the systemLib directory).
⚠️ Built-in Node version limitation (tested):
bin\node.exeis v10.9.0 and supports CommonJS only — ESM (importsyntax /.mjs) throwsSyntaxErrordirectly; there is nofetch, no optional chaining, or other newer features. Helper scripts written for the built-in node must use CommonJS (require) +.js; when you need ESM, use the system Node.
III. Local Reference Docs (must read)
| Doc | Content | When to read |
|---|---|---|
| 1.MxServiceCodeCommandReference.md | Full reference for the 12 CLI commands (params/return values/call examples) + fileparam JSON passing + how to register a new command | When calling an existing command |
| 2.Mx2DNodeSecondaryDevAPIReference.md | All backend parametric drawing/data extraction APIs (Mx2DDraw, MxBackstage, McDbDatabase, McDb* entities, selection sets, geometry objects) | When developing a new command / custom logic |
| 3.DeploymentAndStartup.md | Directory structure, invocation, Linux permissions, standalone mxcadassembly calls and expiry check, logs, secondary development workflow | When deploying / troubleshooting |
IV. Task → Command Selection Quick Reference
Before calling any existing command, check against this table that "the command's contract covers the requirement" — the command name is NOT the selection criterion. When no existing command covers the task, go straight to secondary development (see the example in section 9 of "Mx2DNodeSecondaryDevAPIReference.md"); do not "try running" a command whose functionality doesn't match.
| What you want to do | Which path | Notes |
|---|---|---|
| Extract text / block attributes | getcaddata (existing) | ⚠️ TEXT + INSERT attributes only, no geometry entities of any kind |
| Extract polyline vertices on a specified layer | getPolylineTheSpecifiedLayer (existing) | ⚠️ The layer name is hardcoded in GetDwgData.ts; to use across drawings you must change the source and recompile |
| Extract line / circle / other geometry entity data | Secondary development | No existing command; example in section 9 of "Mx2DNodeSecondaryDevAPIReference.md" (modelSpace().getAllEntity() + instanceof McDbXxx) |
| Extract the layer list | getAllLayer (existing) | Outputs <filename>_layers.json |
| DWG→mxweb conversion | mxcadassembly standalone call | ⚠️ The convert command is deprecated and unusable; the outpath directory must pre-exist |
| Batch cutting by title block frames | frameCut2 (existing) | ⚠️ frameCut (v1) depends on the 1337 service and is unavailable in the standalone edition |
| Export the whole drawing to PDF | Mx_Custom_ExportPdf (existing) | Auto-scales to the sheet size |
| Merge multiple DWGs | margeDwg (existing) | Can filter by layer |
| Compare the block tables of two drawings | compare_dwg (existing) | |
| Parametric drawing (generate a new drawing) | Secondary development (testParamDraw can serve as a starting template) | See sections 2 and 9 of "Mx2DNodeSecondaryDevAPIReference.md" |
| Read/write extended data (xdata) | Secondary development | mxtest_getxdata is only a debug example (hardcoded paths; do not use in production) |
V. Task → Doc Lookup Guide
| Task Type | Doc(s) to Read |
|---|---|
| Calling an existing command (conversion/data extraction/cutting/merge/PDF export/layers/compare) | "MxServiceCodeCommandReference.md" |
| Secondary development: a new command or custom processing logic | "Mx2DNodeSecondaryDevAPIReference.md" + the project's src\sample\ sample code |
| Environment deployment / startup failure / Linux permissions / log investigation | "Deployment and Startup Notes" |
| Format conversion parameters (DWG/DXF/MXWEB/PDF/JPG, cut_dwg, print_to_pdf) | Official "Drawing Conversion Program Tutorial": link |
| Getting started with backend development | The bundled NODE.JS后台程序开发.doc (teaches development based on this project; not an API doc) |
VI. Capability Boundaries (based on hands-on testing of the 1.0 trial version)
Capabilities present
- DWG/DXF open and save
- Format conversion: DWG→mxweb, etc. (via standalone
mxcadassemblycall; see "Deployment and Startup Notes" section 3) - Parametric drawing: lines, arcs, circles, ellipses, points, text, MText, images, hatches, blocks, title block frames/title blocks, five dimension types
- Data extraction: text, block attributes, polylines, layers, xdata extended data
- Selection sets and filters (by type/layer/window/crossing)
- Entity editing: properties, xdata, explode, intersectWith, getArea
- Drawing merge (with layer filtering), batch cutting by title block frames, drawing comparison
- Export: PDF, JPG, mxweb (the frontend display format)
- System variable read/write (LTSCALE, etc.)
Development-mode conventions
- New CAD interface features going forward: developed by the AI on top of this project (
src\sample\pattern + Mx2DNode API) - After modifying the source, you MUST recompile with
npm run build(the runtime executes the .js)
Limitations
- The
convertcommand is unusable: its wgh output format is deprecated and the native module has removedwriteWebGLFile(running it reportscode:-4). The mxcad frontend only accepts mxweb; usemxcadassemblydirectly for DWG→mxweb (see "MxServiceCodeCommandReference.md" detailed 1) - The
frameCut(v1) command depends on a service on port 1337, which the standalone MxServiceCode does not provide — useframeCut2instead (it calls mxcadassembly directly and is functionally equivalent) - Trial version (TryVersion): mind the license expiry and the open-count limit
- Debug commands such as
mxtest_getxdatacontain hardcoded paths and must not be used directly in production - The layer filter value of
getPolylineTheSpecifiedLayeris hardcoded in the source; modify it for the target drawing before use
