Creates a new AcDbDatabase instance.
ReadonlyeventsEvents that can be triggered by the database.
These events allow applications to respond to various database operations such as entity modifications, layer changes, and progress updates.
Fired when an object in the dictionary is removed
Fired when an object is set to the dictionary
Fired when an entity is appended to the database
Fired when an entity is erased from the database
Fired when an entity is modified in the database
Fired when a layer is appended to the database
Fired when a layer is erased from the database
Fired when a layer is modified in the database
Fired when AcDbDatabase.read or AcDbDatabase.openUri fails
Fired during database opening operations to report progress
ReadonlyhatchReverse index + live rebuild for associative hatch boundary soft-pointers (DXF 97/330).
ReadonlytransactionManages transactions and undo/redo for this database.
The zero (0) base angle with respect to the current UCS in radians.
The direction of positive angles.
When true, annotative objects that do not support the current annotation
scale are still displayed (ANNOALLVISIBLE). Defaults to true, matching
AutoCAD's initial value.
Gets the attributes object for this AcDbObject.
The AcCmObject instance containing all attributes
Angular unit display and entry format for the drawing (AutoCAD system variable AUNITS).
This does not change how angles are stored internally (radians in geometry); it controls how angles are formatted in the UI and how numeric angle input is interpreted, together with angbase (ANGBASE) and angdir (ANGDIR).
Integer code matching AcDbAngleUnits:
| Value | Meaning |
|---|---|
0 |
Decimal degrees ??e.g. 45.5 |
1 |
Degrees/minutes/seconds ??e.g. 45d30'15" |
2 |
Gradians ??e.g. 50g (400 grads = full circle) |
3 |
Radians ??e.g. 0.785398... |
4 |
Surveyor's units ??quadrant bearing notation (e.g. N 45d30'15" E) |
Prefer assigning AcDbAngleUnits enum members for readability instead of raw integers.
Sets AUNITS ??the angular unit display format (see aunits getter for value meanings).
Integer 0??4per {@link AcDbAngleUnits}, orundefined/nullcoerced to0` by the setter chain.
Angular display precision for the drawing (AUPREC): how many decimal places (or equivalent) are used when showing angles, in conjunction with aunits.
AutoCAD typically uses integers in the range 0??; behavior for other values is implementation-defined in this library (stored as-is).
Sets AUPREC ??angular display precision (see auprec getter).
Current annotation scale name (CANNOSCALE), e.g. "1:100".
The line type scaling for new objects relative to the ltscale setting. A line created with celtscale = 2 in a drawing with ltscale set to 0.5 would appear the same as a line created with celtscale = 1 in a drawing with ltscale = 1.
The linetype of new objects as they are created.
The layer of new objects as they are created.
The transparency level of new objects as they are created.
Can be ByLayer, ByBlock, or a value from 0 to 90 (percentage).
First chamfer distance when CHAMMODE is 0 (CHAMFERA).
Second chamfer distance when CHAMMODE is 0 (CHAMFERB).
Chamfer length when CHAMMODE is 1 (CHAMFERC).
Chamfer angle in degrees when CHAMMODE is 1 (CHAMFERD).
Gets or sets class definitions from the drawing (DXF CLASSES / DWG class table).
Proxy entities resolve their application class ID (group code 91) against this list (IDs start at 500 for the first entry).
The layer of new objects as they are created.
The multileader style name used for newly created MLEADER entities.
The multiline scale used for newly created MLINE entities.
The multiline style name used for newly created MLINE entities.
Whether hatch objects are included in drawing comparison (COMPAREHATCH).
0: Hatch objects are excluded (AutoCAD default)1: Hatch objects are includedOffset between a change-set boundary and the revision cloud (COMPARERCMARGIN). AutoCAD range is 1–25; default is 5.
Whether text objects are included in drawing comparison (COMPARETEXT).
0: Text objects are excluded1: Text objects are included (AutoCAD default)Decimal-place geometric tolerance used when comparing two drawings (COMPARETOLERANCE). AutoCAD range is 0–14; default is 6.
Gets the object ID of the AcDbBlockTableRecord of the current space.
The current space can be either model space or paper space.
The object ID of the current space
Sets the current space by object ID.
The object ID of the block table record to set as current space
Gets the database in which this object is resident.
When an object isn't added to a database, this property returns the current working database. After it is added to a database, it will be set automatically. You should never set this value manually.
The database this object belongs to
Sets the database for this object.
This is typically set automatically when the object is added to a database. Manual setting should be avoided unless you know what you're doing.
The database to associate with this object
The dimension style name for new dimension objects ($DIMSTYLE).
Display tessellation side count for a full circle.
Configured via AcDbOpenDatabaseOptions.circleSides when the database is opened. Defaults to ACDB_DRAW_CIRCLE_SIDES_DRAFT.
Whether entities on non-plottable layers should be drawn.
Configured via AcDbOpenDatabaseOptions.drawNoPlotLayers when the
database is opened. Defaults to true.
Gets the drawing code page name ($DWGCODEPAGE), when known.
Populated from the HEADER when a DXF/DWG is read. Used by dxfOut
for pre-R2007 targets; R2007+ always writes UTF-8.
Sets the drawing code page name written as $DWGCODEPAGE for legacy DXF.
Code page token such as ANSI_1252 or ANSI_936
Name of the current drawing file (DWGNAME), including extension.
Read-only through the system-variable API; updated when a drawing is opened or via setDwgName after save.
Gets the objectId of the extension dictionary owned by this object.
If the object does not have an extension dictionary, this returns undefined.
In ObjectARX terms, this is equivalent to AcDbObject::extensionDictionary().
The extension dictionary objectId, or undefined
Sets the objectId of the extension dictionary owned by this object.
This does not create or delete the dictionary object itself ??it only establishes or clears the ownership relationship.
Passing undefined removes the association.
The extension dictionary objectId, or undefined
The current Model Space EXTMAX value
The current Model Space EXTMIN value
Current 2D fillet radius (FILLETRAD). Saved in the drawing.
Formatter for linear distances, point coordinates, and angles using this database's LUNITS, AUNITS, and related system variables.
The default layer used for newly created hatches and fills.
The default transparency string used for newly created hatches and fills.
Gets the drawing-units value for automatic scaling of blocks, images, or xrefs.
This is the current INSUNITS value for the database.
The insertion units value
Sets the drawing-units value for automatic scaling.
The new insertion units value
Returns true if this object is temporary and not yet committed to the database.
A temporary object is identified by its objectId starting with the TEMP prefix.
The most recent failure from read or openUri, or null after a successful open.
Useful when a caller catches no exception (for example a viewer that returns false)
but still needs to distinguish worker out-of-memory from other parse failures.
Gets the Layer Properties Manager filter tree for this database.
The current AcLyLayerFilterTree.
Mirrors AutoCAD .NET Database.LayerFilters / ObjectARX AcLy* filters.
This is the property/group filter tree, not the flat
objects.layerFilter dictionary used by AcDbLayerFilter /
AcDbLayerIndex.
Like AutoCAD, treat this value as retrieved by value: mutate the tree, then assign it back via the setter if your workflow expects that pattern.
Sets the Layer Properties Manager filter tree for this database.
New filter tree.
Gets the line type scale factor.
The line type scale factor
Sets the line type scale factor.
The new line type scale factor
Linear unit display and entry format for coordinates and lengths (LUNITS).
This does not set real-world drawing units for inserts (see insunits); it controls how linear distances are shown and parsed (scientific, decimal, engineering, and so on).
Integer code matching AcDbLinearUnits:
| Value | Meaning |
|---|---|
1 |
Scientific |
2 |
Decimal |
3 |
Engineering (feet + decimal inches) |
4 |
Architectural (feet + fractional inches) |
5 |
Fractional |
6 |
Windows desktop (processing / computational format) |
Prefer assigning AcDbLinearUnits enum members instead of raw integers.
Sets LUNITS ??linear display format (see lunits getter).
Integer per AcDbLinearUnits, or coerced default AcDbLinearUnits.Decimal when undefined/null.
Linear display precision for the drawing (LUPREC): number of decimal places (or equivalent) used when showing linear distances, together with lunits.
AutoCAD typically uses integers in the range 0??; initial value is commonly 4. Values outside that range are stored as-is by this library.
Sets LUPREC ??linear display precision (see luprec getter).
Gets the flag whether to display line weight.
The flag whether to display line weight.
Legacy drawing measurement system (MEASUREMENT): 0 = English, 1 = metric.
When INSUNITS is unitless, this selects the default real-world unit family for labels.
Whether TEXT / MTEXT / ATTRIB are truly mirrored by MIRROR (MIRRTEXT).
0: keep text readable after mirror (AutoCAD default)1: mirror textAngle between the WCS Y axis and grid north (NORTHDIRECTION), in
radians. Saved in the drawing. AutoCAD initial value is 0.0.
Gets the object ID.
AutoCAD uses 64-bit integers to represent handles, which exceed the maximum integer value of JavaScript. Therefore, strings are used to represent object handles.
The object ID as a string
Sets the object ID.
The new object ID
Gets all nongraphical objects in this drawing database.
Object containing all nongraphical objects in the database
Orthogonal mode flag (ORTHOMODE). When on, cursor movement is constrained to horizontal or vertical relative to the current UCS.
Running Object Snap (OSNAP) mode bitmask.
Gets the object ID of the owner of this object.
The owner object ID
Sets the object ID of the owner of this object.
The new owner object ID
Point display mode. Please get more details on value of this property from this page.
Point display size.
0: Specifies an absolute size
PSLTSCALE: paper space linetype scaling.
Gets all tables in this drawing database.
Object containing all the symbol tables in the database
The text style name for new text objects.
TILEMODE: whether the Model tab or a paper-space layout is active.
0: Paper space (named layout) active1: Model space active (AutoCAD default)Named UCS used as the base for orthographic UCS settings (UCSBASE). Empty string means World. Saved in the drawing.
Current UCS name for the active viewport (UCSNAME). Empty when the UCS is unnamed. Read-only through AcDbSysVarManager.setVar; assign here when restoring UCS state (for example from DXF HEADER).
Origin of the current UCS in WCS (UCSORG). Read-only through AcDbSysVarManager.setVar; assign here when restoring UCS state.
X direction of the current UCS (UCSXDIR). Read-only through AcDbSysVarManager.setVar; assign here when restoring UCS state.
Y direction of the current UCS (UCSYDIR). Read-only through AcDbSysVarManager.setVar; assign here when restoring UCS state.
Controls how feet-inch and fractional linear values are delimited (UNITMODE).
0: Report format (for example 1'-3 1/2")1: Input format (for example 1'-3-1/2", fewer spaces)Gets the version of the database.
The version of the database
Sets the version of the database.
The version value of the database
Whether the current UCS coincides with the WCS (WORLDUCS). Read-only through AcDbSysVarManager.setVar; kept in sync when ucsorg / ucsxdir / ucsydir change. Not written to the DXF HEADER.
ProtectedassignAssociates this object with a database. Subclasses may override database
and call this helper to avoid super setter restrictions.
Begins suppressing database events until endEventBatch is called.
Adds the records and objects this object references to deps.
Used by the clone engine to bring every layer, linetype, style, block
definition and style object that a cloned object needs into the
destination database. Overrides should call super.
Dependency collector.
Create default layer, line type, dimension type, text style and layout.
Creates the extension dictionary for this object if it does not already exist.
This method closely mirrors the behavior of
AcDbObject::createExtensionDictionary() in ObjectARX.
The objectId of the extension dictionary
Creates an extension dictionary for owner and registers it in this database.
Used by AcDbObject.createExtensionDictionary. Returns the existing dictionary id when one is already attached.
Clones this object for AcDbDatabase.deepCloneObjects.
Mirrors AcDbObject::deepClone() in ObjectARX. The returned object is a
detached copy with a temporary id; the caller appends it to its owner,
which assigns the real handle. The pair this.objectId -> clone.objectId
is recorded in idMap, and is updated by the clone engine once the clone
has a committed handle.
The clone does not share this object's extension dictionary: AutoCAD would clone it too, but extension dictionaries are not cloned yet, so the clone simply drops it instead of pointing into the source database.
Subclasses that own other objects override this to clone them as well.
The object that will own the clone, if known.
Id mapping of the current clone operation.
True when this object was explicitly asked to be cloned.
The detached clone.
Clones objects within this database.
Mirrors AcDbDatabase::deepCloneObjects() in ObjectARX. Every entity in
objectIds is cloned and appended to the block table record ownerId.
Records the entities reference by name (layers, linetypes, styles, blocks)
are shared with the originals, except anonymous blocks such as dimension
blocks, which are copied so each clone owns its own definition.
Ids of the entities to clone.
Id of the block table record that receives the clones.
Receives the source-to-clone id pairs.
Accepted for ObjectARX compatibility; translation always runs before this method returns.
Ids of the clones, in the order of objectIds.
Reads this object from a DXF filer (ObjectARX dxfIn).
Reads common handle/owner fields, then delegates to dxfInFields. XData (group 1001+) is consumed when present after object fields.
Group-102 control strings ({ACAD_XDICTIONARY, {ACAD_REACTORS, …) are
consumed here so subclass readers still see handle/owner/subclass markers
that follow them. Many real DXF writers emit these blocks on LAYER and
entity records; skipping them would leave name/layer unset.
ProtecteddxfConsumes a DXF group-102 control-string block that was already opened
(the opening 102 value is startValue, typically {ACAD_XDICTIONARY
or {ACAD_REACTORS).
For {ACAD_XDICTIONARY, the first soft-owner handle (360) is stored as
extensionDictionary. Other control strings are skipped until the
matching closing 102 / }.
Reads object-specific DXF fields (ObjectARX dxfInFields).
Subclasses should override, call super.dxfInFields(filer) first when
appropriate, then consume their subclass marker and fields in an
order-independent loop.
Per the AutoCAD DXF specification, readers must ignore undefined group
codes and must not assume field order. Within a subclass loop the
correct unknown-code behavior is break (skip and continue). Use
pushBackItem only to hand a group-100 subclass marker (or XData) to
another reader — never to abort on an unrecognized optional code.
ProtecteddxfConsume XData pairs starting at group 1001 until end of object.
Exports the current database into DXF (ASCII string or binary bytes).
The fileName parameter is kept for ObjectARX API parity. In this web
implementation the method returns the DXF payload instead of writing the
filesystem directly.
Optional_fileName: stringKept for ObjectARX parity. Ignored in this implementation.
Numeric precision used by the DXF filer.
Target DXF/DWG version name or value.
Legacy boolean thumbnail flag, or options with
saveThumbnailImage and format: 'ascii' | 'binary'.
ASCII DXF string, or Uint8Array when format is 'binary'.
ProtecteddxfWrites the extension-dictionary pointer; see AcDbDxfFiler.writeExtensionDictionary.
Writes DXF fields for this object.
The instance (for chaining).
ProtecteddxfWrites the 102 {ACAD_REACTORS group. AutoCAD puts it before the
extension dictionary group. Only reactors that are OBJECTS-section
records of the current export are written, so no handle dangles.
ProtecteddxfEmit all attached XData buffers (DXF groups 1000–1071).
Ends the outermost event batch, flushing entityAppended notifications in
chunks so converters can report ENTITY progress while the viewer adds/renders.
Nested batches still require matching endEventBatch / endEventBatchChunked calls; only the outermost close flushes.
Max entities per entityAppended dispatch
OptionalonChunk: (flushed: number, total: number) => void | Promise<void>Called after each chunk with (flushed, total)
Returns VPORT *Active, creating it with AutoCAD UCSICON default (3)
when missing. ObjectARX keeps UCSICON / UCSFOLLOW / UCSVP on
the viewport record, not on AcDbDatabase.
Gets the value of the specified attribute.
This method will throw an exception if the specified attribute doesn't exist. Use getAttrWithoutException() if you want to handle missing attributes gracefully.
The name of the attribute to retrieve
The value of the specified attribute
Gets the value of the specified attribute without throwing an exception.
This method returns undefined if the specified attribute doesn't exist, making it safer for optional attributes.
The name of the attribute to retrieve
The value of the specified attribute, or undefined if it doesn't exist
Returns ids of objects hard-owned by this object through a pointer other
than a dictionary entry or the extension dictionary (DXF group 360), e.g.
the action body and dependencies of an AcDbAssocAction.
DXF export follows these ids so owned objects are written with their owner. Defaults to none.
Looks up a database-resident object by its object ID.
Uses the global handle registry maintained by registerObjectHandle.
Object identifier to resolve
Reserved for erased-object support
The matching object, or undefined if not found
Returns the top-level named object dictionaries owned by this database.
Retrieves the XData associated with this object for a given application ID.
Extended Entity Data (XData) allows applications to attach arbitrary, application-specific data to an AcDbObject. Each XData entry is identified by a registered application name (AppId) and stored as an AcDbResultBuffer.
This method is conceptually equivalent to AcDbObject::xData() in ObjectARX,
but simplified to return the entire result buffer for the specified AppId.
The application ID (registered AppId name) that owns the XData
The AcDbResultBuffer associated with the AppId, or undefined
if no XData exists for that AppId
Imported XData stays compact until the first call for that AppId. The call materializes an AcDbResultBuffer and keeps it, so later reads and in-place edits use that buffer. DXF output order does not change. Avoid calling this while importing when the compact form should be retained.
Initializes generateHandle from a DXF/DWG $HANDSEED value.
$HANDSEED is the next handle AutoCAD would assign; internal _maxHandle
is kept one below that value.
Hexadecimal handle seed from the drawing header
Inserts the model space of sourceDb into this database.
Mirrors the AcDbDatabase::insert() overloads in ObjectARX, which
PASTECLIP and PASTEBLOCK use:
sourceDb are cloned into
this model space and transformed. Returns the ids of the new entities.sourceDb. Returns the id of the new block
table record.Records with a name this database already has are not imported: the
existing definition wins (DRC_Ignore), as in AutoCAD.
Database to insert.
OptionalpreserveSourceDb: booleanInserts the model space of sourceDb into this database.
Mirrors the AcDbDatabase::insert() overloads in ObjectARX, which
PASTECLIP and PASTEBLOCK use:
sourceDb are cloned into
this model space and transformed. Returns the ids of the new entities.sourceDb. Returns the id of the new block
table record.Records with a name this database already has are not imported: the
existing definition wins (DRC_Ignore), as in AutoCAD.
Database to insert.
OptionalpreserveSourceDb: booleanReturns whether entities on the given layer should be drawn under the current drawNoPlotLayers setting.
Layer off/freeze visibility is handled separately by the viewer; this only reflects the no-plot policy.
Returns true when the transaction manager is actively recording changes.
Shortcut for AcDbDatabaseTransactionManager.isRecording.
Iterates the XData of one application without materializing it.
Behaves like getXData for readers, but never converts the compact imported form into an AcDbResultBuffer. Use this on hot paths that only read XData (for example drawing dimension-style overrides), so a drawing keeps its lossless compact representation and pays no per-entity allocation. Use getXData when the returned values may be edited.
The application ID (registered AppId name) that owns the XData
The typed values of that AppId, or an empty iterable when absent
Dispatches or queues a dictionary-object-erased notification.
Object removed from a named dictionary
Dictionary key that previously referenced the object
Dispatches or queues a dictionary-object-set notification.
Object inserted or replaced in a named dictionary
Dictionary key under which the object is stored
Dispatches or queues an entity-appended notification.
One entity or batch of entities added to model/paper space
Dispatches or queues an entity-erased notification.
One entity or batch of entities removed from model/paper space
ProtectednotifyXDataProtectedonCalled when this object is re-associated with a different database.
Subclasses that cache database-derived state (for example a dimension style resolved from the style table) override this to drop that cache.
The database that this object now belongs to.
ProtectedonXDataCalled whenever XData for an AppId changes.
Subclasses that cache values derived from XData (for example the effective
dimension style assembled from ACAD/DSTYLE) override this to drop the
stale cache instead of re-parsing the stream on every read.
Opens an entity for read through the active transaction when present.
Editor shortcut; see openObject.
Opens an entity for write through the active transaction when present.
Editor shortcut; see openObject.
Opens a database object for read through the active transaction when present.
Editor shortcut; see openObject.
Opens a database object for write through the active transaction when present.
Editor shortcut; see openObject.
Read AutoCAD DXF or DWG drawing specified by the URL into the database object. The method automatically detects the file type based on the URL extension:
Input the URL linked to one AutoCAD DXF or DWG file
Input options to read drawing data
Reads drawing data from a string, ArrayBuffer, or typed-array view.
This method parses the provided data and populates the database with the resulting entities, tables, and objects. The method supports both DXF and DWG file formats.
The drawing data as a string, ArrayBuffer, or ArrayBufferView
fetch / File / fs.readFile)Options for reading the database
The type of file being read (defaults to DXF)
// Reading a DXF file (string)
const database = new AcDbDatabase();
await database.read(dxfString, { readOnly: true }, AcDbFileType.DXF);
// Reading a DXF file (Uint8Array / ArrayBuffer)
await database.read(
new TextEncoder().encode(dxfString),
{ readOnly: true },
AcDbFileType.DXF
);
// Reading a DWG file (ArrayBuffer)
await database.read(dwgArrayBuffer, { readOnly: true }, AcDbFileType.DWG);
Removes the XData associated with the specified application ID.
After removal, calls to getXData() for the same AppId will return undefined.
If no XData exists for the given AppId, this method has no effect.
This mirrors the behavior of clearing XData for a specific application in ObjectARX rather than removing all XData from the object.
The application ID whose XData should be removed
Restores internal state from a detached clone while preserving identity fields.
Clone produced by clone or clonePreservingIdentity.
Runs a database mutation as one undoable operation.
Editor shortcut: skips creating a new undo mark when the transaction manager
is already recording (nested editor operations). Otherwise wraps fn in
AcDbDatabaseTransactionManager.runUndoable.
Sets the value of an attribute.
The name of the attribute to set
Optionalval: AcDbObjectAttrs[A]The value to assign to the attribute
Lossless parser/import fast path.
Each 1001 group starts an AppId. That AppId stays in the compact list
until getXData, setXData, or removeXData touches it. Replacing an
AppId keeps its DXF position; a new AppId is appended.
getXData materializes that AppId into an AcDbResultBuffer and keeps
the buffer afterwards, so later reads observe in-place edits. Calling it
during import gives up the compact representation for that AppId.
Attaches or replaces XData for this object.
If XData already exists for the given AppId, it is replaced by the provided AcDbResultBuffer. The caller is responsible for ensuring that:
This method is conceptually similar to AcDbObject::setXData() in ObjectARX.
The result buffer containing the XData to attach
Rewrites references held by a freshly cloned object so that they point at the destination database.
This is the "translation" phase of an ObjectARX deep clone. It is called
on the clone (not on the source) after every dependency and every entity
of the operation has been cloned, so idMap holds the final names and
ids, including those of other cloned entities. References to entities
that were not cloned along (the annotation of a leader, ...) should be
dropped, as AutoCAD does. Overrides should call super.
Id mapping of the current clone operation.
Writes the given entities, and everything they depend on, into a new database.
Mirrors the AcDbDatabase::wblock(pOutputDb, outObjIds, basePoint)
overload in ObjectARX, which COPYCLIP uses to fill the clipboard. The new
database gets default data (layer 0, Continuous, Standard styles) and the
entities keep their coordinates. The new database has no INSBASE header
variable, so callers that need a base point keep it themselves.
OptionalobjectIds: string[]Ids of the entities to write. Defaults to all of model space.
The new database.
Clones this object for AcDbDatabase.wblockCloneObjects.
Mirrors AcDbObject::wblockClone() in ObjectARX. The default
implementation is the same as deepClone; the difference between
the two operations (cross-database record handling) lives in the clone
engine.
The object that will own the clone, if known.
Id mapping of the current clone operation.
True when this object was explicitly asked to be cloned.
The detached clone.
Clones objects from this database into another database.
Mirrors AcDbDatabase::wblockCloneObjects() in ObjectARX: it is called on
the source database, idMap.destDb names the destination and ownerId is
a block table record of the destination. Every layer, linetype, text
style, dimension style, block definition (recursively), MLINE/MLEADER
style and image definition the entities need is cloned too. When the
destination already has a record with the same name, drc decides what
happens (see AcDbDuplicateRecordCloning).
Ids of the entities to clone.
Id of the destination block table record.
Id mapping; idMap.destDb must be set.
Duplicate record handling.
Accepted for ObjectARX compatibility; translation always runs before this method returns.
Ids of the clones in the destination, in the order of objectIds.
The base class for all objects that reside in a drawing database.
This class provides the fundamental functionality for all database objects, including attribute management, object identification, and database association. It serves as the foundation for entities, tables, and other database objects.
Example