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.To register a converter for a file type:
import { AcDbDatabaseConverterManager, AcDbFileType } from '@mlightcad/data-model';
import { AcDbLibreDwgConverter } from '@mlightcad/libredwg-converter';
const converter = new AcDbLibreDwgConverter({
convertByEntityType: false,
useWorker: true,
parserWorkerUrl: './assets/libredwg-parser-worker.js'
})
AcDbDatabaseConverterManager.instance.register(
AcDbFileType.DWG,
converter
)
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:
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.
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.