Skip to content
On this page

mxcad_2d API 文档 / 2d / McDbDatabase

Class: McDbDatabase

2d.McDbDatabase

表示数据库,图形中的所有信息都存放在该对象中,调用mxcad.getDatabase()函数得到控件的数据库。

Hierarchy

Table of contents

Constructors

Properties

Accessors

Methods

Constructors

constructor

new McDbDatabase(imp?)

构造函数。

Parameters

NameTypeDescription
imp?any内部实现对象。

Overrides

McRxObject.constructor

Properties

imp

imp: any = 0

内部实现对象。

Inherited from

McRxObject.imp

Accessors

blockTable

get blockTable(): McDbBlockTable

获取块表

Returns

McDbBlockTable

Example

ts
import { MxCpp, McDbDatabase } from "mxcad"

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

currentSpace

get currentSpace(): McDbBlockTableRecord

返回当前空间块表记录

Returns

McDbBlockTableRecord

块表记录

Example

ts
import { MxCpp, McDbDatabase } from "mxcad"

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

dimStyleTable

get dimStyleTable(): McDbDimStyleTable

获取标注样式表。

Returns

McDbDimStyleTable

线型表。


dxf0

get dxf0(): string

得到对象的DXF组码的类型名,这个和AutoCAD中的DXF组码是一样。 比如直线的类型名为:McDbLine,DXF0组码值: LINE,DXF0组码值可以用来构造集时的类型过滤。

Returns

string

Inherited from

McRxObject.dxf0


layerTable

get layerTable(): McDbLayerTable

获取层表

Returns

McDbLayerTable

Example

ts
import { MxCpp, McDbDatabase } from "mxcad"

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

linetypeTable

get linetypeTable(): McDbLinetypeTable

获取线型表

Returns

McDbLinetypeTable

Example

ts
import { MxCpp, McDbDatabase } from "mxcad"

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

objectName

get objectName(): string

获取对象名称。

Returns

string

返回对象名

Example

ts
import { McRxObject } from 'mxcad';

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

Inherited from

McRxObject.objectName


textStyleTable

get textStyleTable(): McDbTextStyleTable

获取文字样式表

Returns

McDbTextStyleTable

Example

ts
import { MxCpp, McDbDatabase } from "mxcad"

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

Methods

CreateGroup

CreateGroup(ids, name?): boolean

把一堆对象创建一个组

Parameters

NameTypeDefault value
idsMcObjectId[]undefined
namestring""

Returns

boolean

McDbDictionary


GetGroupDictionary

GetGroupDictionary(): McDbDictionary

得到图纸的组字典对象。

Returns

McDbDictionary

McDbDictionary

Example

ts
___

### SetCurrentlyTextStyleId

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

设置当前文字样式id.

#### Parameters

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

#### Returns

`boolean`

___

### getBlockTable

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

获取块表。

#### Returns

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

块表。

**`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

获取当前颜色索引。

Returns

number

当前颜色索引(ColorIndexType)。

Example

ts
import { MxCpp, McDbDatabase } from "mxcad"

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

getCurrentlyDimStyleId

getCurrentlyDimStyleId(): McObjectId

返回当前标注样式id.

Returns

McObjectId


getCurrentlyDrawColor

getCurrentlyDrawColor(): Color

获取当前绘图使用的颜色

Returns

Color

Example

ts
import { MxCpp, McDbDatabase } from "mxcad"

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

getCurrentlyLayerId

getCurrentlyLayerId(): McObjectId

返回当前层id.

Returns

McObjectId


getCurrentlyLayerName

getCurrentlyLayerName(): string

获取当前层名称。

Returns

string

当前层名称。

Example

ts
import { MxCpp, McDbDatabase } from "mxcad"

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

getCurrentlyLineTypeName

getCurrentlyLineTypeName(): string

获取当前线型名称。

Returns

string

当前线型名称。

Example

ts
import { MxCpp, McDbDatabase } from "mxcad"

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

getCurrentlyLineTypeScale

getCurrentlyLineTypeScale(): number

获取当前线型比例。

Returns

number

当前线型比例。

Example

ts
import { MxCpp, McDbDatabase } from "mxcad"

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

getCurrentlyLinetypeId

getCurrentlyLinetypeId(): McObjectId

返回当前线型id.

Returns

McObjectId


getCurrentlyTextStyleId

getCurrentlyTextStyleId(): McObjectId

返回当前文字样式id.

Returns

McObjectId


getCurrentlyTextStyleName

getCurrentlyTextStyleName(): string

获取当前文字样式名称。

Returns

string

当前文字样式名称。

Example

ts
import { MxCpp, McDbDatabase } from "mxcad"

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

getCurrentlyTrueColor

getCurrentlyTrueColor(): McCmColor

获取当前CAD颜色。

Returns

McCmColor

当前CAD颜色。

Example

ts
import { MxCpp, McDbDatabase } from "mxcad"

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

getDimStyleTable

getDimStyleTable(): McDbDimStyleTable

获取标注样式表。

Returns

McDbDimStyleTable

线型表。


getEntitiesInTheGroup

getEntitiesInTheGroup(id): McObjectId[]

得到对象所在组中的所有对象id

Parameters

NameType
idMcObjectId

Returns

McObjectId[]

McDbDictionary

Example

ts
___

### getImp

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

获取内部实现对象。

#### Returns

`any`

内部实现对象。

**`Example`**

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

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

Inherited from

McRxObject.getImp


getJson

getJson(): string

获取 JSON 格式的字符串。

Returns

string

JSON 格式的字符串。

Example

ts
import { McRxObject } from 'mxcad';

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

Inherited from

McRxObject.getJson


getLayerTable

getLayerTable(): McDbLayerTable

获取层表。

Returns

McDbLayerTable

层表。

Example

ts
import { MxCADUiPrEntity, MxCpp } from "mxcad";
  //隐藏目标对象所在图层
  async function Mx_SelectEntitHideLayer() {
     let selEntity1 = new MxCADUiPrEntity();

     selEntity1.setMessage("选择要隐藏的对象")
     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

获取线型表。

Returns

McDbLinetypeTable

线型表。

Example

ts
import { MxCpp } from "mxcad"
   //得所有线型
   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

得到图纸的字典对象。

Returns

McDbDictionary

McDbDictionary

Example

ts
import { MxCpp, McDbDatabase } from "mxcad"
  // 写扩展记录
  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

获取文字样式表。

Returns

McDbTextStyleTable

文字样式表。

Example

ts
//获取所有文字样式
 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

根据对象的句柄返回对象id.

Parameters

NameType
sHandlestring

Returns

McObjectId

Example

ts
import { MxCpp, McDbDatabase } from "mxcad"

const dataBase:McDbDatabase = MxCpp.getCurrentMxCAD().getDatabase();
// 传入句柄并获取相应的对象 ID
const handle = "ABCD1234"; // 假设这是一个有效的句柄
const objectId = dataBase.handleToIdIndex(handle);
// 确保获取的对象 ID 是有效的
if (objectId) {
  console.log("success", objectId);
} else {
  console.log("error")
}

initTempObject

initTempObject(imp): void

初始化临时对象。

Parameters

NameTypeDescription
impany内部实现对象。

Returns

void

Example

ts
import { McRxObject } from 'mxcad';

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

Inherited from

McRxObject.initTempObject


isKindOf

isKindOf(sObjectName): boolean

判断对象类型

Parameters

NameTypeDescription
sObjectNamestring类型名

Returns

boolean

返回对象是否是目标类型

Example

ts
import { McRxObject } from 'mxcad';

let obj = new McRxObject();
let isKind = obj.isKindOf('SomeObjectType');
console.log(isKind); // 输出: true 或 false

Inherited from

McRxObject.isKindOf


isModifyed

isModifyed(): boolean

当前数据库是否被修改

Returns

boolean

返回布尔值

Example

ts
import { MxCpp, McDbDatabase } from "mxcad"

const dataBase:McDbDatabase = MxCpp.getCurrentMxCAD().getDatabase();
const res = dataBase.isModifyed();
if(res){
  console.log("已修改")
}else{
  console.log("未修改")
}

isNull

isNull(): any

判断是否为空对象

Returns

any

Example

ts
import { McRxObject } from 'mxcad';

let obj = new McRxObject();
console.log(obj.isNull()); // 输出: true 或 false

Inherited from

McRxObject.isNull


resetModificationStatus

resetModificationStatus(): void

把当前数据库修改状态重置成未修改状态

Returns

void

Example

ts
import { MxCpp, McDbDatabase } from "mxcad"

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

setCurrentlyColorIndex

setCurrentlyColorIndex(colorIndex): any

设置当前颜色索引(ColorIndexType)。

Parameters

NameTypeDescription
colorIndexnumber颜色索引。

Returns

any

Example

ts
import { MxCpp, McDbDatabase } from "mxcad"

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

setCurrentlyDimStyleId

setCurrentlyDimStyleId(id): boolean

设置当前标注样式id.

Parameters

NameType
idMcObjectId

Returns

boolean


setCurrentlyLayerId

setCurrentlyLayerId(id): boolean

设置当前标注样式id.

Parameters

NameType
idMcObjectId

Returns

boolean


setCurrentlyLayerName

setCurrentlyLayerName(sName): void

设置当前层名称。

Parameters

NameTypeDescription
sNamestring层名称。

Returns

void

Example

ts
import { MxCpp, McDbDatabase } from "mxcad"

const dataBase:McDbDatabase = MxCpp.getCurrentMxCAD().getDatabase();
dataBase.setCurrentlyLayerName("测试图层");

setCurrentlyLineTypeName

setCurrentlyLineTypeName(sName): void

设置当前线型名称。

Parameters

NameTypeDescription
sNamestring线型名称。

Returns

void

Example

ts
import { MxCpp, McDbDatabase } from "mxcad"

const dataBase:McDbDatabase = MxCpp.getCurrentMxCAD().getDatabase();
dataBase.setCurrentlyLineTypeName("测试线型");

setCurrentlyLineTypeScale

setCurrentlyLineTypeScale(val): number

设置当前线型比例。

Parameters

NameTypeDescription
valnumber线型比例。

Returns

number

当前线型比例。

Example

ts
import { MxCpp, McDbDatabase } from "mxcad"

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

setCurrentlyLinetypeId

setCurrentlyLinetypeId(id): boolean

设置当前标注样式id.

Parameters

NameType
idMcObjectId

Returns

boolean


setCurrentlyTextStyle

setCurrentlyTextStyle(sName): void

设置当前文字样式名称。

Parameters

NameTypeDescription
sNamestring文字样式名称。

Returns

void

Example

ts
import { MxCpp, McDbDatabase } from "mxcad"

const dataBase:McDbDatabase = MxCpp.getCurrentMxCAD().getDatabase();
dataBase.setCurrentlyTextStyle("测试文字样式");

setCurrentlyTrueColor

setCurrentlyTrueColor(color): any

设置当前CAD颜色。

Parameters

NameTypeDescription
colorMcCmColorCAD颜色。

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

设置 JSON 格式的字符串。

Parameters

NameTypeDescription
strstringJSON 格式的字符串。

Returns

boolean

是否设置成功。

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

写块

Parameters

NameType
databaseMcDbDatabase
aryIdMcObjectId[]
ptBase?McGePoint3d

Returns

boolean

Example

ts