Skip to content
On this page

[mxcad_2d API documentation] (../README. md)/[2d] (../modules/2d. md)/McDbDatabase

Class: McDbDatabase

2d.McDbDatabase

Represents a database. All information in the graph is stored in this object. Call the mxcad. getDatabase() function to get the database of the control.

Hierarchy

Table of contents

Constructors

Properties

Accessors

Methods

Constructors

constructor

new McDbDatabase(imp?)

Constructor.

Parameters

NameTypeDescription
imp?AnyInternal implementation object

Overrides

McRxObject.constructor

Properties

imp

imp: any = 0

Internal implementation object.

Inherited from

McRxObject.imp

Accessors

blockTable

get blockTable(): McDbBlockTable

Get block table

Returns

McDbBlockTable

Example

ts
import { MxCpp, McDbDatabase } from "mxcad"

const dataBase:McDbDatabase = MxCpp.getCurrentMxCAD().getDatabase();
let blkTable = dataBase.blockTable;

currentSpace

get currentSpace(): McDbBlockTableRecord

Return the current space block table record

Returns

McDbBlockTableRecord

Block table record

Example

ts
import { MxCpp, McDbDatabase } from "mxcad"

const dataBase:McDbDatabase = MxCpp.getCurrentMxCAD().getDatabase();
let currentBlkRec = dataBase.currentSpace;

dimStyleTable

get dimStyleTable(): McDbDimStyleTable

Retrieve the annotation style sheet.

Returns

McDbDimStyleTable

Linear table.


dxf0

get dxf0(): string

Obtain the type name of the object's DXF group code, which is the same as the DXF group code in AutoCAD. For example, the type name of the line is McDbLine, and the group code value for DXF0 is: LINE and DXF0 group code values can be used for type filtering when constructing sets.

Returns

string

Inherited from

McRxObject.dxf0


layerTable

get layerTable(): McDbLayerTable

Get layer table

Returns

McDbLayerTable

Example

ts
import { MxCpp, McDbDatabase } from "mxcad"

const dataBase:McDbDatabase = MxCpp.getCurrentMxCAD().getDatabase();
let layerTable = dataBase.layerTable;

linetypeTable

get linetypeTable(): McDbLinetypeTable

Get line type table

Returns

McDbLinetypeTable

Example

ts
import { MxCpp, McDbDatabase } from "mxcad"

const dataBase:McDbDatabase = MxCpp.getCurrentMxCAD().getDatabase();
let lineTypeTable = dataBase.linetypeTable;

objectName

get objectName(): string

Get the object name.

Returns

string

Return object name

Example

ts
import { McRxObject } from 'mxcad';

let obj = new McRxObject();
console.log(obj.objectName);

Inherited from

McRxObject.objectName


textStyleTable

get textStyleTable(): McDbTextStyleTable

Get Text Style Sheet

Returns

McDbTextStyleTable

Example

ts
import { MxCpp, McDbDatabase } from "mxcad"

const dataBase:McDbDatabase = MxCpp.getCurrentMxCAD().getDatabase();
let textStyleTable = dataBase.textStyleTable;

ucsMatrix

get ucsMatrix(): McGeMatrix3d

Obtain the UCS user coordinate system transformation matrix

Returns

McGeMatrix3d

Example

ts

set ucsMatrix(val): void

Set UCS user coordinate system transformation matrix

Parameters

NameType
valMcGeMatrix3d

Returns

void

Example

ts

Methods

CreateGroup

CreateGroup(ids, name?): boolean

Create a group from a pile of objects

Parameters

NameTypeDefault value
idsMcObjectId[]undefined
namestring""

Returns

boolean

McDbDictionary


GetGroupDictionary

GetGroupDictionary(): McDbDictionary

Obtain the group dictionary object of the drawing.

Returns

McDbDictionary

McDbDictionary

Example

ts
___

### SetCurrentlyTextStyleId

▸ **SetCurrentlyTextStyleId**(`id`): `boolean`

Set the current text style id

#### Parameters

| Name | Type |
| :------ | :------ |
| `id` | [`McObjectId`](2d.McObjectId.md) |

#### Returns

`boolean`

___

### getBlockTable

▸ **getBlockTable**(): [`McDbBlockTable`](2d.McDbBlockTable.md)

Retrieve the block table.

#### Returns

[`McDbBlockTable`](2d.McDbBlockTable.md)

Block table.

**`Example`**

```ts
  import { MxCpp, McDbDatabase } from "mxcad"
  let mxcad = MxCpp.App.getCurrentMxCAD();
  let blockTable = mxcad.getDatabase().getBlockTable();
  let aryId = blockTable.getAllRecordId();
  aryId.forEach((id) => {
      let blkRec = id.getMcDbBlockTableRecord();
      if (blkRec === null) return;
      console.log(blkRec);
      console.log("blkRec.name:" + blkRec.name);
      console.log("blkRec.origin:" + blkRec.origin);
  });

getCurrentlyColorIndex

getCurrentlyColorIndex(): number

Retrieve the current color index.

Returns

number

Current Color Index (ColorIndexType).

Example

ts
import { MxCpp, McDbDatabase } from "mxcad"

const dataBase:McDbDatabase = MxCpp.getCurrentMxCAD().getDatabase();
const colorIndex = dataBase.getCurrentlyColorIndex();

getCurrentlyDimStyleId

getCurrentlyDimStyleId(): McObjectId

Return the current annotation style id

Returns

McObjectId


getCurrentlyDrawColor

getCurrentlyDrawColor(): Color

Get the color used in the current drawing

Returns

Color

Example

ts
import { MxCpp, McDbDatabase } from "mxcad"

const dataBase:McDbDatabase = MxCpp.getCurrentMxCAD().getDatabase();
const color = dataBase.getCurrentlyDrawColor();

getCurrentlyLayerId

getCurrentlyLayerId(): McObjectId

Return the current layer ID

Returns

McObjectId


getCurrentlyLayerName

getCurrentlyLayerName(): string

Get the current layer name.

Returns

string

Current layer name.

Example

ts
import { MxCpp, McDbDatabase } from "mxcad"

const dataBase:McDbDatabase = MxCpp.getCurrentMxCAD().getDatabase();
const layerName = dataBase.getCurrentlyLayerName();

getCurrentlyLineTypeName

getCurrentlyLineTypeName(): string

Get the current line type name.

Returns

string

The current line type name.

Example

ts
import { MxCpp, McDbDatabase } from "mxcad"

const dataBase:McDbDatabase = MxCpp.getCurrentMxCAD().getDatabase();
const name = dataBase.getCurrentlyLineTypeName();

getCurrentlyLineTypeScale

getCurrentlyLineTypeScale(): number

Get the current line type scale.

Returns

number

Current line type scale.

Example

ts
import { MxCpp, McDbDatabase } from "mxcad"

const dataBase:McDbDatabase = MxCpp.getCurrentMxCAD().getDatabase();
let currentLTS = dataBase.getCurrentlyLineTypeScale();

getCurrentlyLineWeight

getCurrentlyLineWeight(): LineWeight

Return the current line weight used

Returns

LineWeight


getCurrentlyLinetypeId

getCurrentlyLinetypeId(): McObjectId

Return the current line type ID

Returns

McObjectId


getCurrentlyTextStyleId

getCurrentlyTextStyleId(): McObjectId

Return the current text style id

Returns

McObjectId


getCurrentlyTextStyleName

getCurrentlyTextStyleName(): string

Get the current text style name.

Returns

string

The current text style name.

Example

ts
import { MxCpp, McDbDatabase } from "mxcad"

const dataBase:McDbDatabase = MxCpp.getCurrentMxCAD().getDatabase();
const textStyName = dataBase.getCurrentlyTextStyleName();

getCurrentlyTrueColor

getCurrentlyTrueColor(): McCmColor

Retrieve the current CAD color.

Returns

McCmColor

Current CAD color.

Example

ts
import { MxCpp, McDbDatabase } from "mxcad"

const dataBase:McDbDatabase = MxCpp.getCurrentMxCAD().getDatabase();
const color = dataBase.getCurrentlyTrueColor();

getDimStyleTable

getDimStyleTable(): McDbDimStyleTable

Retrieve the annotation style sheet.

Returns

McDbDimStyleTable

Linear table.


getEntitiesInTheGroup

getEntitiesInTheGroup(id): McObjectId[]

Get all object IDs in the group where the object is located

Parameters

NameType
idMcObjectId

Returns

McObjectId[]

McDbDictionary

Example

ts
___

### getImp

▸ **getImp**(): `any`

Retrieve internal implementation objects.

#### Returns

`any`

Internal implementation object.

**`Example`**

```ts
import { McRxObject } from 'mxcad';

let obj = new McRxObject();
let imp = obj.getImp();

Inherited from

McRxObject.getImp


getJson

getJson(): string

Retrieve a string in JSON format.

Returns

string

A string in JSON format.

Example

ts
import { McRxObject } from 'mxcad';

let obj = new McRxObject();
const json = obj.getJson()

Inherited from

McRxObject.getJson


getLayerTable

getLayerTable(): McDbLayerTable

Retrieve the layer table.

Returns

McDbLayerTable

Layer table.

Example

ts
import { MxCADUiPrEntity, MxCpp } from "mxcad";
//Hide the layer where the target object is located
  async function Mx_SelectEntitHideLayer() {
     let selEntity1 = new MxCADUiPrEntity();

SelElement1.setMessage ("Select Objects to Hide")
     let id = await selEntity1.go();
     if (!id.isValid()) return;

     let ent = id.getMcDbEntity();
     let mxcad = MxCpp.getCurrentMxCAD();
     let layerTable = mxcad.getDatabase().getLayerTable();
     let layerId = layerTable.get(ent.layer);
     let layerRec = layerId.getMcDbLayerTableRecord();
     if (layerRec === null) return;
     layerRec.isOff = true;
     mxcad.updateLayerDisplayStatus();
     mxcad.updateDisplay()
   }

getLinetypeTable

getLinetypeTable(): McDbLinetypeTable

Retrieve the line type table.

Returns

McDbLinetypeTable

Linear table.

Example

ts
import { MxCpp } from "mxcad"
//Get all line types
   let mxcad = MxCpp.App.getCurrentMxCAD();
   let linetypeTable = mxcad.getDatabase().getLinetypeTable();
   let aryId = linetypeTable.getAllRecordId();
   aryId.forEach((id) => {
       let linetypeRec = id.getMcDbLinetypeTableRecord();
       if (linetypeRec === null) return;
       console.log(linetypeRec);
   });

getNamedObjectsDictionary

getNamedObjectsDictionary(): McDbDictionary

Obtain the dictionary object of the drawing.

Returns

McDbDictionary

McDbDictionary

Example

ts
import { MxCpp, McDbDatabase } from "mxcad"
//Write extension records
  let mxcad = MxCpp.getCurrentMxCAD();
  let dict = mxcad.getDatabase().getNamedObjectsDictionary();

  let sName = "MyDict";
  let idDict = dict.getAt(sName);
  if (idDict.isNull()) {
      let newDict = new McDbDictionary;
      idDict = dict.addObject(sName, newDict);
   }
   let myDict = idDict.getMcDbDictionary();
   if (myDict) {

       let xrec = new McDbXrecord();
       let data = new MxCADResbuf();
       data.AddString("TestData");
       xrec.setData(data);
       myDict.addObject("MyRecord", xrec);
       console.log("write xrecord ok");
   }

getTextStyleTable

getTextStyleTable(): McDbTextStyleTable

Retrieve the text style sheet.

Returns

McDbTextStyleTable

Text style sheet.

Example

ts
//Get all text styles
 import { MxCpp } from "mxcad"
 let mxcad = MxCpp.getCurrentMxCAD();
 let textSyleTable = mxcad.getDatabase().getTextStyleTable();
 let aryId = textSyleTable.getAllRecordId();
 aryId.forEach((id) => {
     let textSyleRec = id.getMcDbTextStyleTableRecord();
     if (textSyleRec === null) return;
     let out: any = {};
     out.name = textSyleRec.name;
     out.font = textSyleRec.font();
     out.fileName = textSyleRec.fileName;
     out.bigFontFileName = textSyleRec.bigFontFileName;
     out.textSize = textSyleRec.textSize;
     out.xScale = textSyleRec.xScale;
     console.log(out);
 });

handleToIdIndex

handleToIdIndex(sHandle): McObjectId

Return the object ID based on the handle of the object

Parameters

NameType
sHandlestring

Returns

McObjectId

Example

ts
import { MxCpp, McDbDatabase } from "mxcad"

const dataBase:McDbDatabase = MxCpp.getCurrentMxCAD().getDatabase();
//Pass in the handle and obtain the corresponding object ID
const handle = "ABCD1234"; //  Assuming this is a valid handle
const objectId = dataBase.handleToIdIndex(handle);
//Ensure that the obtained object ID is valid
if (objectId) {
  console.log("success", objectId);
} else {
  console.log("error")
}

initTempObject

initTempObject(imp): void

Initialize temporary objects.

Parameters

NameTypeDescription
'imp''any'Internal implementation object

Returns

void

Example

ts
import { McRxObject } from 'mxcad';

let obj = new McRxObject();
obj.initTempObject()

Inherited from

McRxObject.initTempObject


insert

insert(database, sBlkName): McObjectId

Insert block

Parameters

NameType
databaseMcDbDatabase
sBlkNamestring

Returns

McObjectId

Example

ts

isKindOf

isKindOf(sObjectName): boolean

Determine object type

Parameters

NameTypeDescription
SOrtNamestringType Name

Returns

boolean

Return whether the object is of the target type

Example

ts
import { McRxObject } from 'mxcad';

let obj = new McRxObject();
let isKind = obj.isKindOf('SomeObjectType');
console.log(isKind); //  Output: True or false

Inherited from

McRxObject.isKindOf


isModifyed

isModifyed(): boolean

Has the current database been modified

Returns

boolean

Return Boolean value

Example

ts
import { MxCpp, McDbDatabase } from "mxcad"

const dataBase:McDbDatabase = MxCpp.getCurrentMxCAD().getDatabase();
const res = dataBase.isModifyed();
if(res){
Console.log ("Modified")
}else{
Console.log ("unmodified")
}

isNull

isNull(): any

Determine if it is an empty object

Returns

any

Example

ts
import { McRxObject } from 'mxcad';

let obj = new McRxObject();
console.log(obj.isNull()); //  Output: True or false

Inherited from

McRxObject.isNull


readFile

readFile(sFilePath): boolean

Read files.

Parameters

NameType
sFilePathstring

Returns

boolean

Example

ts

resetModificationStatus

resetModificationStatus(): void

Reset the current database modification status to unmodified status

Returns

void

Example

ts
import { MxCpp, McDbDatabase } from "mxcad"

const dataBase:McDbDatabase = MxCpp.getCurrentMxCAD().getDatabase();
dataBase.resetModificationStatus();

saveAs

saveAs(sFilePath): boolean

Save the file.

Parameters

NameType
sFilePathstring

Returns

boolean

Example

ts

setCurrentlyColorIndex

setCurrentlyColorIndex(colorIndex): any

Set the current color index (ColorIndexType).

Parameters

NameTypeDescription
ColorIndexNumberColor Index

Returns

any

Example

ts
import { MxCpp, McDbDatabase } from "mxcad"

const dataBase:McDbDatabase = MxCpp.getCurrentMxCAD().getDatabase();
const colorIndex = dataBase.getCurrentlyColorIndex();

setCurrentlyDimStyleId

setCurrentlyDimStyleId(id): boolean

Set the current annotation style id

Parameters

NameType
idMcObjectId

Returns

boolean


setCurrentlyLayerId

setCurrentlyLayerId(id): boolean

Set the current annotation style id

Parameters

NameType
idMcObjectId

Returns

boolean


setCurrentlyLayerName

setCurrentlyLayerName(sName): void

Set the current layer name.

Parameters

NameTypeDescription
SNamestringlayer name

Returns

void

Example

ts
import { MxCpp, McDbDatabase } from "mxcad"

const dataBase:McDbDatabase = MxCpp.getCurrentMxCAD().getDatabase();
DataBase. setCurrentlyLayerName ("Test Layer");

setCurrentlyLineTypeName

setCurrentlyLineTypeName(sName): void

Set the current line type name.

Parameters

NameTypeDescription
SNamestringLine type name

Returns

void

Example

ts
import { MxCpp, McDbDatabase } from "mxcad"

const dataBase:McDbDatabase = MxCpp.getCurrentMxCAD().getDatabase();
DataBase. setCurrentlyLineTypeName ("test line type");

setCurrentlyLineTypeScale

setCurrentlyLineTypeScale(val): number

Set the current line type scale.

Parameters

NameTypeDescription
ValnumberLine proportion

Returns

number

Current line type scale.

Example

ts
import { MxCpp, McDbDatabase } from "mxcad"

const dataBase:McDbDatabase = MxCpp.getCurrentMxCAD().getDatabase();
dataBase.setCurrentlyLineTypeScale(0.8);

setCurrentlyLineWeight

setCurrentlyLineWeight(lineWeight): void

Set the current line weight used

Parameters

NameType
lineWeightLineWeight

Returns

void


setCurrentlyLinetypeId

setCurrentlyLinetypeId(id): boolean

Set the current annotation style id

Parameters

NameType
idMcObjectId

Returns

boolean


setCurrentlyTextStyle

setCurrentlyTextStyle(sName): void

Set the current text style name.

Parameters

NameTypeDescription
SNamestringText style name

Returns

void

Example

ts
import { MxCpp, McDbDatabase } from "mxcad"

const dataBase:McDbDatabase = MxCpp.getCurrentMxCAD().getDatabase();
DataBase.setCurrentlyStyle ("Test Text Style");

setCurrentlyTrueColor

setCurrentlyTrueColor(color): any

Set the current CAD color.

Parameters

NameTypeDescription
Color[McCMColor] (2d. McCmColor. md)CAD color

Returns

any

Example

ts
import { MxCpp, McDbDatabase, McCmColor } from "mxcad"

const dataBase:McDbDatabase = MxCpp.getCurrentMxCAD().getDatabase();
const color = new McCmColor(255, 0, 0);
dataBase.setCurrentlyTrueColor(color);

setJson

setJson(str): boolean

Set a string in JSON format.

Parameters

NameTypeDescription
StrstringJSON formatted string

Returns

boolean

Is the setting successful.

Example

ts
import { McRxObject } from 'mxcad';

let obj = new McRxObject();
const res = obj.setJson('{"key": "value"}');
console.log(res)

Inherited from

McRxObject.setJson


wblock

wblock(database, aryId, ptBase?): boolean

Write a block

Parameters

NameType
databaseMcDbDatabase
aryIdMcObjectId[]
ptBase?McGePoint3d

Returns

boolean

Example

ts