The data-model package provides the core classes for interacting with AutoCAD's database and entities. This package mimics AutoCAD ObjectARX's AcDb (Database) classes and implements the drawing database structure that AutoCAD developers are familiar with.
npm install @mlightcad/data-modelThe data-model package provides the core classes for interacting with AutoCAD's database and entities. This package mimics AutoCAD ObjectARX's AcDb (Database) classes and implements the drawing database structure that AutoCAD developers are familiar with.
This package contains the core classes for defining and manipulating AutoCAD entities (e.g., lines, circles, blocks), handling entity attributes and geometric data, and storing and retrieving data from the drawing database. It uses the same drawing database structure as AutoCAD ObjectARX, making it easier for AutoCAD developers to build applications based on this SDK.
- Database Management: Complete AutoCAD database structure with tables and records
- Entity Support: All major AutoCAD entity types (lines, circles, polylines, blocks, etc.)
- File Conversion: Support for reading DXF and DWG files with extensible converter system
- Symbol Tables: Layer, linetype, text style, and dimension style management
- Block Management: Block table and block reference handling
- Dimension Support: Comprehensive dimension entity types
- Layout Management: Paper space and model space layout handling
``bash`
npm install @mlightcad/data-model
typescript
import { AcDbDatabase } from '@mlightcad/data-model';// Create a new database
const database = new AcDbDatabase();
// Get symbol tables
const layerTable = database.getLayerTable();
const blockTable = database.getBlockTable();
const linetypeTable = database.getLinetypeTable();
`$3
`typescript
import { AcDbLine, AcDbCircle, AcGePoint3d } from '@mlightcad/data-model';// Create a line entity
const startPoint = new AcGePoint3d(0, 0, 0);
const endPoint = new AcGePoint3d(10, 10, 0);
const line = new AcDbLine(startPoint, endPoint);
// Create a circle entity
const center = new AcGePoint3d(0, 0, 0);
const radius = 5;
const circle = new AcDbCircle(center, radius);
// Set entity properties
line.setColor(1); // Red
line.setLayer('0');
circle.setLinetype('CONTINUOUS');
`$3
`typescript
import { AcDbLayerTableRecord } from '@mlightcad/data-model';// Create a new layer
const layerRecord = new AcDbLayerTableRecord();
layerRecord.setName('MyLayer');
layerRecord.setColor(2); // Yellow
layerRecord.setLinetype('DASHED');
// Add layer to database
const layerTable = database.getLayerTable();
layerTable.add(layerRecord);
`$3
`typescript
import { AcDbBlockReference, AcGePoint3d } from '@mlightcad/data-model';// Create a block reference
const insertionPoint = new AcGePoint3d(0, 0, 0);
const blockRef = new AcDbBlockReference(insertionPoint, 'MyBlock');
// Set block properties
blockRef.setScale(2.0);
blockRef.setRotation(Math.PI / 4);
// Add to model space
const modelSpace = database.getModelSpace();
modelSpace.appendEntity(blockRef);
`$3
`typescript
import { AcDbDatabaseConverterManager, AcDbFileType } from '@mlightcad/data-model';// Get the DXF converter
const converter = AcDbDatabaseConverterManager.instance.get(AcDbFileType.DXF);
// Read a DXF file
const database = await converter.read('drawing.dxf');
// Register a custom converter
class MyDwgConverter extends AcDbDatabaseConverter {
async read(filePath: string): Promise {
// Custom DWG reading logic
}
}
AcDbDatabaseConverterManager.instance.register(AcDbFileType.DWG, new MyDwgConverter());
`$3
`typescript
import { AcDbAlignedDimension, AcGePoint3d } from '@mlightcad/data-model';// Create an aligned dimension
const defPoint1 = new AcGePoint3d(0, 0, 0);
const defPoint2 = new AcGePoint3d(10, 0, 0);
const textPosition = new AcGePoint3d(5, 5, 0);
const dimension = new AcDbAlignedDimension(defPoint1, defPoint2, textPosition);
dimension.setDimensionText('10.0');
dimension.setDimensionStyle('Standard');
`$3
`typescript
import { AcDbLayoutManager } from '@mlightcad/data-model';// Get layout manager
const layoutManager = database.getLayoutManager();
// Get current layout
const currentLayout = layoutManager.getCurrentLayout();
// Switch to model space
layoutManager.setCurrentLayout('Model');
// Create a new layout
const newLayout = layoutManager.createLayout('MyLayout');
newLayout.setPlotType('Extents');
newLayout.setPlotCentered(true);
``- @mlightcad/dxf-json: For DXF file parsing
- @mlightcad/common: For common utilities (peer dependency)
- @mlightcad/geometry-engine: For geometric operations (peer dependency)
- @mlightcad/graphic-interface: For graphics interface (peer dependency)
- uid: For unique ID generation
For detailed API documentation, visit the RealDWG-Web documentation.
This package is part of the RealDWG-Web monorepo. Please refer to the main project README for contribution guidelines.