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.AcDbDatabaseConverterManager registers the built-in MIT AcDbNativeDxfConverter when the singleton is created. You only need to register a DXF converter if you want to replace that default.@mlightcad/libredwg-converter) before calling AcDbDatabase.read() on DWG files.@mlightcad/libredwg-converter runs its LibreDWG parser in a Web Worker. That is a deliberate licensing choice: the upstream parser is copyleft (GPL), so keeping it in a separate worker bundle helps isolate that code from the main application. The built-in AcDbNativeDxfConverter does not need a worker — it is MIT-licensed and runs on the main thread.
Deprecated GPL converters (@mlightcad/dxf-json-converter, @mlightcad/libdxfrw-converter) have moved to the separate dwg-dxf-converter repository and are no longer documented here.
DXF works out of the box. Register a DWG converter before reading DWG files:
import {
AcDbDatabaseConverterManager,
AcDbFileType
} from '@mlightcad/data-model'
import { AcDbLibreDwgConverter } from '@mlightcad/libredwg-converter'
// 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 libredwg-parser-worker.js and its sibling libredwg-web.wasm from @mlightcad/libredwg-converter's dist/ folder to the same public directory (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 in this repository, or the customer-facing demo realdwg-web-example.
When using a viewer such as @mlightcad/cad-simple-viewer, fonts are loaded from a
baseUrl (default: jsDelivr CDN). If the CDN is unreachable, @mlightcad/data-model
continues parsing DWG/DXF entities by default; text may fall back until fonts load.
For self-hosted fonts, templates, fonts.json, and server setup, see
Self Hosted Fonts and Templates
in the cad-viewer wiki.
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 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.
@mlightcad/data-model ships a built-in MIT DXF converter, AcDbNativeDxfConverter. It is registered by default when AcDbDatabaseConverterManager is created, streams DXF pairs into the database on the main thread, and requires no Web Worker or extra parser assets.
Deprecated GPL alternatives (@mlightcad/dxf-json-converter, @mlightcad/libdxfrw-converter) live in the separate dwg-dxf-converter repository.
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.). It also includes the built-in MIT DXF converter AcDbNativeDxfConverter, which is registered by default for AcDbFileType.DXF.
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.
@mlightcad/dwg-converter is not part of this public repository and is never
built or published by public GitHub CI. Maintainers who need it locally can clone
it into the workspace:
pnpm setup:private
pnpm install
pnpm --filter @mlightcad/dwg-converter build
Override the clone URL with DWG_CONVERTER_REPO_URL if needed. The directory
packages/dwg-converter is gitignored so it cannot be committed here. Local
pnpm install may temporarily add that package to pnpm-lock.yaml — do not
commit those lockfile changes; public CI must keep a lockfile without it.
Customers install the same package from GitHub Packages (not public npm). Do
not point the whole @mlightcad scope at GitHub Packages—only authenticate, then
install with an explicit registry:
# .npmrc
registry=https://registry.npmjs.org/
//npm.pkg.github.com/:_authToken=${GITHUB_TOKEN}
pnpm add @mlightcad/data-model
pnpm add @mlightcad/dwg-converter --registry https://npm.pkg.github.com
Publishing @mlightcad/dwg-converter happens only from its private repository CI.
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 @mlightcad/libredwg-converter (GPL-3.0) in this repository.
Deprecated GPL converters (@mlightcad/dxf-json-converter, @mlightcad/libdxfrw-converter) live in the separate dwg-dxf-converter repository. Please refer to that repository and each package's license for details.
For DXF files, use the built-in AcDbNativeDxfConverter in @mlightcad/data-model:
AcDbDatabaseConverterManager is enough to call AcDbDatabase.read(..., AcDbFileType.DXF).For DWG, register a separate converter package (prefer @mlightcad/libredwg-converter with worker mode).
The MIT-licensed core (@mlightcad/data-model, @mlightcad/geometry-engine, @mlightcad/graphic-interface, @mlightcad/common) does not depend on any GPL parser. Reading DXF through AcDbNativeDxfConverter stays entirely under MIT.
GPL copyleft therefore does not automatically apply to your application merely because you use the RealDWG-Web SDK—provided that any GPL parser code you do use runs only inside separate Web Worker bundles.
For DWG via @mlightcad/libredwg-converter, the recommended integration is:
const dwgConverter = new AcDbLibreDwgConverter({
useWorker: true,
parserWorkerUrl: './assets/libredwg-parser-worker.js'
})
Deploy libredwg-parser-worker.js and its sibling libredwg-web.wasm from @mlightcad/libredwg-converter's dist/ folder as static assets in the same directory (see example vite config).
How this limits copyleft propagation
| Component | License | Worker isolation |
|---|---|---|
Core SDK (data-model, including AcDbNativeDxfConverter) |
MIT | N/A — no GPL dependency |
libredwg-converter (main bundle) |
GPL | Orchestrates parsing; GPL parser execution stays in worker |
libredwg-parser-worker.js + libredwg-web.wasm |
GPL | Separate worker + wasm assets; loaded at runtime; communicates via postMessage |
When useWorker: true is configured and the worker script is 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
AcDbNativeDxfConverter for DXF to avoid GPL entirely for that format.@mlightcad/libredwg-converter requires a Web Worker; it cannot run on the main thread.