Module @mlightcad/data-model - v1.1.1

@mlightcad/data-model

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.

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
npm install @mlightcad/data-model
  • AcDbDatabase: Main database class that contains all drawing data
  • AcDbObject: Base class for all database-resident objects
  • AcDbHostApplicationServices: Services provided by the host application
  • AcDbSymbolTable: Base class for symbol tables
  • AcDbSymbolTableRecord: Base class for symbol table records
  • AcDbLayerTable, AcDbLayerTableRecord: Layer management
  • AcDbLinetypeTable, AcDbLinetypeTableRecord: Linetype management
  • AcDbTextStyleTable, AcDbTextStyleTableRecord: Text style management
  • AcDbDimStyleTable, AcDbDimStyleTableRecord: Dimension style management
  • AcDbBlockTable, AcDbBlockTableRecord: Block management
  • AcDbViewportTable, AcDbViewportTableRecord: Viewport management
  • AcDbEntity: Base class for all drawable objects
  • AcDbLine: Line entity
  • AcDbCircle: Circle entity
  • AcDbArc: Arc entity
  • AcDbPolyline: Polyline entity
  • AcDbText, AcDbMText: Text and multiline text entities
  • AcDbBlockReference: Block reference entity
  • AcDbPoint: Point entity
  • AcDbEllipse: Ellipse entity
  • AcDbSpline: Spline curve entity
  • AcDbHatch: Hatch pattern entity
  • AcDbTable: Table entity
  • AcDbRasterImage: Raster image entity
  • AcDbLeader: Leader entity
  • AcDbRay, AcDbXline: Construction line entities
  • AcDbTrace, AcDbWipeout: Filled area entities
  • AcDbDimension: Base class for dimension entities
  • AcDbAlignedDimension: Aligned dimension
  • AcDbRadialDimension: Radial dimension
  • AcDbDiametricDimension: Diametric dimension
  • AcDb3PointAngularDimension: 3-point angular dimension
  • AcDbArcDimension: Arc dimension
  • AcDbOrdinateDimension: Ordinate dimension
  • AcDbDictionary: Dictionary object for storing key-value pairs
  • AcDbRasterImageDef: Raster image definition
  • AcDbLayout: Layout object for paper space
  • AcDbLayoutDictionary: Layout dictionary management
  • AcDbLayoutManager: Layout manager for switching between layouts
  • AcDbDatabaseConverter: Base class for file format converters
  • AcDbDatabaseConverterManager: Manages registered file converters
  • AcDbDxfConverter: DXF file converter
  • AcDbBatchProcessing: Batch processing utilities
  • AcDbObjectConverter: Object conversion utilities
  • AcDbConstants: Database constants
  • AcDbObjectIterator: Iterator for database objects
  • AcDbAngleUnits: Angle unit utilities
  • AcDbUnitsValue: Unit value handling
  • AcDbOsnapMode: Object snap modes
  • AcDbRenderingCache: Rendering cache management
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();
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');
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);
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);
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<AcDbDatabase> {
// Custom DWG reading logic
}
}

AcDbDatabaseConverterManager.instance.register(AcDbFileType.DWG, new MyDwgConverter());
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');
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.

Enumerations

AcDbAngleUnits
AcDbDimArrowType
AcDbDimTextHorizontal
AcDbDimTextVertical
AcDbDimVerticalJustification
AcDbDimZeroSuppression
AcDbDimZeroSuppressionAngular
AcDbFileType
AcDbHatchPatternType
AcDbHatchStyle
AcDbLeaderAnnotationType
AcDbLineSpacingStyle
AcDbOsnapMode
AcDbRasterImageClipBoundaryType
AcDbRasterImageImageDisplayOpt
AcDbTextHorizontalMode
AcDbTextVerticalMode
AcDbUnitsValue
AcGiArrowType
AcGiDefaultLightingType
AcGiMTextAttachmentPoint
AcGiMTextFlowDirection
AcGiOrthographicType
AcGiRenderMode

Classes

AcCmColor
AcCmEventDispatcher
AcCmEventManager
AcCmLoader
AcCmLoadingManager
AcCmObject
AcCmPerformanceCollector
AcCmTask
AcCmTaskScheduler
AcDb3PointAngularDimension
AcDbAlignedDimension
AcDbArc
AcDbArcDimension
AcDbBatchProcessing
AcDbBlockReference
AcDbBlockTable
AcDbBlockTableRecord
AcDbCircle
AcDbCurve
AcDbDatabase
AcDbDatabaseConverter
AcDbDatabaseConverterManager
AcDbDiametricDimension
AcDbDictionary
AcDbDimension
AcDbDimStyleTable
AcDbDimStyleTableRecord
AcDbDxfConverter
AcDbEllipse
AcDbEntity
AcDbHatch
AcDbHostApplicationServices
AcDbLayerTable
AcDbLayerTableRecord
AcDbLayout
AcDbLayoutDictionary
AcDbLayoutManager
AcDbLeader
AcDbLine
AcDbLinetypeTable
AcDbLinetypeTableRecord
AcDbMText
AcDbObject
AcDbObjectIterator
AcDbOrdinateDimension
AcDbPoint
AcDbPolyline
AcDbRadialDimension
AcDbRasterImage
AcDbRasterImageDef
AcDbRay
AcDbRenderingCache
AcDbSpline
AcDbSymbolTable
AcDbSymbolTableRecord
AcDbTable
AcDbText
AcDbTextStyleTable
AcDbTextStyleTableRecord
AcDbTrace
AcDbViewport
AcDbViewportTable
AcDbViewportTableRecord
AcDbWipeout
AcDbXline
AcGeArea2d
AcGeBox2d
AcGeBox3d
AcGeCatmullRomCurve3d
AcGeCircArc2d
AcGeCircArc3d
AcGeCurve2d
AcGeEllipseArc2d
AcGeEllipseArc3d
AcGeEuler
AcGeLine2d
AcGeLine3d
AcGeLoop2d
AcGeMatrix2d
AcGeMatrix3d
AcGeNurbsCurve
AcGePlane
AcGePoint2d
AcGePoint3d
AcGePolyline2d
AcGeQuaternion
AcGeShape2d
AcGeSpline3d
AcGeTol
AcGeVector2d
AcGeVector3d
AcGiViewport
AcTrStringUtil

Interfaces

AcCmBaseEvent
AcCmEvent
AcCmObjectAttributeChangedEventArgs
AcCmObjectChangedEventArgs
AcCmObjectOptions
AcCmPerformanceEntry
AcDbConvertDatabasePerformanceData
AcDbDatabaseConverterManagerEventArgs
AcDbDictionaries
AcDbDimStyleTableRecordAttrs
AcDbEntityEventArgs
AcDbFontInfo
AcDbFontLoader
AcDbHeaderSysVarEventArgs
AcDbLayerEventArgs
AcDbLayerModifiedEventArgs
AcDbLayerTableRecordAttrs
AcDbLayoutEventArgs
AcDbObjectAttrs
AcDbOpenDatabaseOptions
AcDbProgressdEventArgs
AcDbSymbolTableRecordAttrs
AcDbTableCell
AcDbTables
AcGeIndexNode
AcGePolyline2dVertex
AcGeVector2dLike
AcGeVector3dLike
AcGiArrowStyle
AcGiBaseLineStyle
AcGiBaseTextStyle
AcGiEntity
AcGiHatchPatternLine
AcGiHatchStyle
AcGiHatchType
AcGiImageStyle
AcGiLineArrowStyle
AcGiLineStyle
AcGiLineTypePatternElement
AcGiMTextData
AcGiPointStyle
AcGiRenderer
AcGiTextStyle
AcGiView

Type Aliases

AcCmAttributes
AcCmCompleteCallback
AcCmEventListener
AcCmLoaderProgressCallback
AcCmOnErrorCallback
AcCmOnLoadCallback
AcCmOnProgressCallback
AcCmOnStartCallback
AcCmStringKey
AcCmUrlModifier
AcDbConversionProgressCallback
AcDbConversionStage
AcDbConversionStageStatus
AcDbObjectId
AcGeBoundaryEdgeType
AcGeKnotParameterizationType
AcGeLoop2dType
AcGePoint
AcGePoint2dLike
AcGePoint3dLike
AcGePointLike
AcGeVector
AcGeVectorLike
AcGiFontMapping
CatmullRomCurveType

Variables

AcCmErrors
AcGeGeometryUtil
AcGeMathUtil
ByBlock
ByLayer
DEBUG_MODE
DEFAULT_LINE_TYPE
DEFAULT_TOL
DefaultLoadingManager
DEG2RAD
FLOAT_TOL
log
ORIGIN_POINT_2D
ORIGIN_POINT_3D
RAD2DEG
TAU

Functions

acdbHostApplicationServices
basisFunction
calculateCurveLength
ceilPowerOfTwo
clamp
clone
damp
defaults
degToRad
euclideanModulo
evaluateNurbsPoint
floorPowerOfTwo
generateChordKnots
generateSqrtChordKnots
generateUniformKnots
generateUUID
has
interpolateControlPoints
intPartLength
inverseLerp
isBetween
isBetweenAngle
isEmpty
isEqual
isImperialUnits
isMetricUnits
isPointInPolygon
isPolygonIntersect
isPowerOfTwo
lerp
mapLinear
normalizeAngle
pingpong
radToDeg
randFloat
randFloatSpread
randInt
relativeEps
seededRandom
setLogLevel
smootherstep
smoothstep