AutoCAD RealDWG is a software development toolkit (SDK) provided by Autodesk that allows developers to read, write, and create DWG and DXF files (AutoCAD's native drawing file formats) without needing AutoCAD installed.
The target of this project is to create one web-version of AutoCAD RealDWG by providing the similar API. For now, it supports reading DWG and DXF file only. In the future, it will support write DWG and DXF too.
To support reading both DXF and DWG files (and potentially other formats in the future), this project provides a flexible mechanism for registering and unregistering file converters. This is managed by the AcDbDatabaseConverterManager class.
AcDbDatabaseConverterManager maintains a registry of these converters, allowing you to register or unregister converters for specific file types at runtime.AcDbDatabase.read().Both @mlightcad/dxf-json-converter and @mlightcad/libredwg-converter are designed to run their parsers in a Web Worker only. This is not a technical or architectural limitation of the converters themselves; it is a deliberate licensing choice. The upstream parsers are copyleft (GPL/LGPL), so keeping them in a separate worker bundle helps isolate that code from the main application and makes license compliance easier for MIT-licensed apps built on RealDWG-Web.
Register DXF and DWG converters before reading files:
import {
AcDbDatabaseConverterManager,
AcDbFileType
} from '@mlightcad/data-model'
import { AcDbDxfConverter } from '@mlightcad/dxf-json-converter'
import { AcDbLibreDwgConverter } from '@mlightcad/libredwg-converter'
// DXF converter (GPL parser is loaded in a separate Web Worker for license isolation)
const dxfConverter = new AcDbDxfConverter({
convertByEntityType: false,
useWorker: true,
parserWorkerUrl: './assets/dxf-parser-worker.js'
})
AcDbDatabaseConverterManager.instance.register(
AcDbFileType.DXF,
dxfConverter
)
// DWG converter (copyleft parser is loaded in a separate Web Worker for license isolation)
const dwgConverter = new AcDbLibreDwgConverter({
convertByEntityType: false,
useWorker: true,
parserWorkerUrl: './assets/libredwg-parser-worker.js'
})
AcDbDatabaseConverterManager.instance.register(
AcDbFileType.DWG,
dwgConverter
)
Deploy dxf-parser-worker.js and libredwg-parser-worker.js from each converter package's dist/ folder to a public URL (see example vite config).
To unregister a converter for a file type:
import { AcDbDatabaseConverterManager, AcDbFileType } from '@mlightcad/data-model';
// Unregister the DWG converter
AcDbDatabaseConverterManager.instance.unregister(AcDbFileType.DWG);
To get the converter for a specific file type (returns undefined if not registered):
const converter = AcDbDatabaseConverterManager.instance.get(AcDbFileType.DXF);
Once a File object is selected via an HTML file input control, you can read and parse the DWG/DXF file using the following code.
const buffer = await file.arrayBuffer();
const fileExtension = file.name.split('.').pop()?.toLocaleLowerCase();
const database = new AcDbDatabase();
// The following step is very important. The working database must be set before parsing DWG/DXF file
acdbHostApplicationServices().workingDatabase = database;
const options: AcDbOpenDatabaseOptions = {
minimumChunkSize: 1000,
readOnly: true
};
await database.read(
buffer,
options,
fileExtension == 'dwg' ? AcDbFileType.DWG : AcDbFileType.DXF
);
For a complete example, see the example project.
This mechanism allows you to:
This design ensures the system is open for extension and can easily adapt to new requirements or file formats in the future.
AutoCAD holds an absolute dominant position in the 2D CAD field. A large number of vertical applications and third-party plugins have been developed based on AutoCAD ObjectARX, and there are many software engineers familiar with AutoCAD ObjectARX. Therefore, this project mimics the architecture of AutoCAD ObjectARX and adopts similar API interfaces to AutoCAD ObjectARX.
This module provides a DWG file converter for the RealDWG-Web ecosystem, enabling reading and conversion of DWG files into the drawing database. It is powered by the libdxfrw library compiled to WebAssembly and is designed to be registered with the converter manager for DWG file support.
This module provides a DWG file converter for the RealDWG-Web ecosystem, enabling reading and conversion of DWG files into the drawing database. It is powered by the LibreDWG library compiled to WebAssembly and is designed to be registered with the converter manager for DWG file support.
DWG parsing is provided through a dedicated Web Worker bundle (libredwg-parser-worker.js). Worker-only usage is a licensing choice, not a platform constraint: it keeps the copyleft LibreDWG parser separate from the main application bundle so that MIT-licensed apps can integrate DWG support more safely.
This module provides a DXF file converter for the RealDWG-Web ecosystem. It is based on @mlightcad/dxf-json and is designed to be registered with the converter manager for DXF file support.
DXF parsing is provided through a dedicated Web Worker bundle (dxf-parser-worker.js). Worker-only usage is a licensing choice, not a platform constraint: it keeps the GPL-licensed @mlightcad/dxf-json parser separate from the main application bundle. The main @mlightcad/data-model package does not depend on dxf-json.
This module provides geometric entities, operations, and transformations. It consists of two kinds of classes.
The key classes in this module are as follows.
The same drawing database structure is used in this project so that it is easier for AutoCAD ObjectARX developers to develop their own application based on SDK of this project. Please refer to AutoCAD Database Overview to get more information on AutoCAD drawing database structure.
This module contains the core classes for interacting with AutoCAD's database and entities (e.g., lines, circles, blocks, etc.).
The key classes in this module are as follows.
Please refer to AcDb classes in AutoCAD ObjectARX Reference Guide to get more details on those classes.
The differnt API interfaces from AutoCAD ObjectARX are used in this module because of the following reasons.
This module provides the graphics interface to control how AutoCAD entities are displayed on the screen.
The key classes in this module are as follows.
Contributions are welcome! Please open issues or pull requests for bug fixes, new features, or suggestions. For bug reports, providing a link to the problematic drawing will help in reproducing and fixing the issue.
This project is generally licensed under the MIT License. However, this license does not apply to the following packages contained within this repository:
@mlightcad/dxf-json-converter (GPL-3.0)@mlightcad/libredwg-converter (GPL-3.0)@mlightcad/libdxfrw-converter (GPL-2.0)These packages depend on upstream GPL-licensed parsers (@mlightcad/dxf-json, @mlightcad/libredwg-web, @mlightcad/libdxfrw-web). Please refer to each package's license for details.
The MIT-licensed core (@mlightcad/data-model, @mlightcad/geometry-engine, @mlightcad/graphic-interface, @mlightcad/common) does not depend on any GPL parser. GPL copyleft therefore does not automatically apply to your application merely because you use the RealDWG-Web SDK—provided that GPL parser code runs only inside separate Web Worker bundles.
For @mlightcad/dxf-json-converter and @mlightcad/libredwg-converter, the recommended integration is:
const dxfConverter = new AcDbDxfConverter({
useWorker: true,
parserWorkerUrl: './assets/dxf-parser-worker.js'
})
const dwgConverter = new AcDbLibreDwgConverter({
useWorker: true,
parserWorkerUrl: './assets/libredwg-parser-worker.js'
})
Deploy the worker scripts (dxf-parser-worker.js, libredwg-parser-worker.js) from each converter package's dist/ folder as static assets (see example vite config).
How this limits copyleft propagation
| Component | License | Worker isolation |
|---|---|---|
Core SDK (data-model, etc.) |
MIT | N/A — no GPL dependency |
dxf-json-converter / libredwg-converter (main bundle) |
GPL | Orchestrates parsing; GPL parser execution stays in worker |
dxf-parser-worker.js / libredwg-parser-worker.js |
GPL | Separate bundle; loaded at runtime; communicates via postMessage |
libdxfrw-converter |
GPL-2.0 | No worker isolation — parser runs on the main thread |
When useWorker: true is configured and the worker scripts are deployed separately:
postMessage (file bytes in, parsed JSON model out)—a runtime boundary rather than static linking of GPL code into the MIT core.Important caveats
@mlightcad/dxf-json-converter can parse on the main thread when useWorker: false; that mode links GPL parser code into the same JavaScript context as your app. Use useWorker: true in production if you want worker-based isolation.@mlightcad/libredwg-converter requires a Web Worker; it cannot run on the main thread.@mlightcad/libdxfrw-converter is different. It does not provide a worker-based parser bundle; using it loads GPL libdxfrw code on the main thread. Prefer @mlightcad/libredwg-converter with worker mode if copyleft isolation matters for your deployment.