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

获取块表

Example

ts
import { MxCpp, McDbDatabase } from "mxcad"

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

Returns

McDbBlockTable


currentSpace

get currentSpace(): McDbBlockTableRecord

返回当前空间块表记录

Example

ts
import { MxCpp, McDbDatabase } from "mxcad"

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

Returns

McDbBlockTableRecord

块表记录


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

获取层表

Example

ts
import { MxCpp, McDbDatabase } from "mxcad"

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

Returns

McDbLayerTable


linetypeTable

get linetypeTable(): McDbLinetypeTable

获取线型表

Example

ts
import { MxCpp, McDbDatabase } from "mxcad"

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

Returns

McDbLinetypeTable


objectName

get objectName(): string

获取对象名称。

Example

ts
import { McRxObject } from 'mxcad';

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

Returns

string

返回对象名

Inherited from

McRxObject.objectName


textStyleTable

get textStyleTable(): McDbTextStyleTable

获取文字样式表

Example

ts
import { MxCpp, McDbDatabase } from "mxcad"

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

Returns

McDbTextStyleTable

Methods

CreateGroup

CreateGroup(ids, name?): boolean

把一堆对象创建一个组

Example

ts
#### Parameters

| Name | Type | Default value |
| :------ | :------ | :------ |
| `ids` | [`McObjectId`](2d.McObjectId.md)[] | `undefined` |
| `name` | `string` | `""` |

#### Returns

`boolean`

McDbDictionary

___

### GetGroupDictionary

▸ **GetGroupDictionary**(): [`McDbDictionary`](2d.McDbDictionary.md)

得到图纸的组字典对象。

**`Example`**

```ts
#### Returns

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

McDbDictionary

___

### SetCurrentlyTextStyleId

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

设置当前文字样式id.

#### Parameters

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

#### Returns

`boolean`

___

### getBlockTable

▸ **getBlockTable**(): [`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);
  });

Returns

McDbBlockTable

块表。


getCurrentlyColorIndex

getCurrentlyColorIndex(): number

获取当前颜色索引。

Example

ts
import { MxCpp, McDbDatabase } from "mxcad"

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

Returns

number

当前颜色索引(ColorIndexType)。


getCurrentlyDimStyleId

getCurrentlyDimStyleId(): McObjectId

返回当前标注样式id.

Returns

McObjectId


getCurrentlyDrawColor

getCurrentlyDrawColor(): Color

获取当前绘图使用的颜色

Example

ts
import { MxCpp, McDbDatabase } from "mxcad"

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

Returns

Color


getCurrentlyLayerId

getCurrentlyLayerId(): McObjectId

返回当前层id.

Returns

McObjectId


getCurrentlyLayerName

getCurrentlyLayerName(): string

获取当前层名称。

Example

ts
import { MxCpp, McDbDatabase } from "mxcad"

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

Returns

string

当前层名称。


getCurrentlyLineTypeName

getCurrentlyLineTypeName(): string

获取当前线型名称。

Example

ts
import { MxCpp, McDbDatabase } from "mxcad"

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

Returns

string

当前线型名称。


getCurrentlyLineTypeScale

getCurrentlyLineTypeScale(): number

获取当前线型比例。

Example

ts
import { MxCpp, McDbDatabase } from "mxcad"

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

Returns

number

当前线型比例。


getCurrentlyLinetypeId

getCurrentlyLinetypeId(): McObjectId

返回当前线型id.

Returns

McObjectId


getCurrentlyTextStyleId

getCurrentlyTextStyleId(): McObjectId

返回当前文字样式id.

Returns

McObjectId


getCurrentlyTextStyleName

getCurrentlyTextStyleName(): string

获取当前文字样式名称。

Example

ts
import { MxCpp, McDbDatabase } from "mxcad"

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

Returns

string

当前文字样式名称。


getCurrentlyTrueColor

getCurrentlyTrueColor(): McCmColor

获取当前CAD颜色。

Example

ts
import { MxCpp, McDbDatabase } from "mxcad"

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

Returns

McCmColor

当前CAD颜色。


getDimStyleTable

getDimStyleTable(): McDbDimStyleTable

获取标注样式表。

Returns

McDbDimStyleTable

线型表。


getEntitiesInTheGroup

getEntitiesInTheGroup(id): McObjectId[]

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

Example

ts
#### Parameters

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

#### Returns

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

McDbDictionary

___

### getImp

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

获取内部实现对象。

**`Example`**

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

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

Returns

any

内部实现对象。

Inherited from

McRxObject.getImp


getJson

getJson(): string

获取 JSON 格式的字符串。

Example

ts
import { McRxObject } from 'mxcad';

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

Returns

string

JSON 格式的字符串。

Inherited from

McRxObject.getJson


getLayerTable

getLayerTable(): 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()
   }

Returns

McDbLayerTable

层表。


getLinetypeTable

getLinetypeTable(): 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);
   });

Returns

McDbLinetypeTable

线型表。


getNamedObjectsDictionary

getNamedObjectsDictionary(): 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");
   }

Returns

McDbDictionary

McDbDictionary


getTextStyleTable

getTextStyleTable(): 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);
 });

Returns

McDbTextStyleTable

文字样式表。


handleToIdIndex

handleToIdIndex(sHandle): McObjectId

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

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")
}

Parameters

NameType
sHandlestring

Returns

McObjectId


initTempObject

initTempObject(imp): void

初始化临时对象。

Example

ts
import { McRxObject } from 'mxcad';

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

Parameters

NameTypeDescription
impany内部实现对象。

Returns

void

Inherited from

McRxObject.initTempObject


isKindOf

isKindOf(sObjectName): boolean

判断对象类型

Example

ts
import { McRxObject } from 'mxcad';

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

Parameters

NameTypeDescription
sObjectNamestring类型名

Returns

boolean

返回对象是否是目标类型

Inherited from

McRxObject.isKindOf


isModifyed

isModifyed(): 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("未修改")
}

Returns

boolean

返回布尔值


isNull

isNull(): any

判断是否为空对象

Example

ts
import { McRxObject } from 'mxcad';

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

Returns

any

Inherited from

McRxObject.isNull


resetModificationStatus

resetModificationStatus(): void

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

Example

ts
import { MxCpp, McDbDatabase } from "mxcad"

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

Returns

void


setCurrentlyColorIndex

setCurrentlyColorIndex(colorIndex): any

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

Example

ts
import { MxCpp, McDbDatabase } from "mxcad"

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

Parameters

NameTypeDescription
colorIndexnumber颜色索引。

Returns

any


setCurrentlyDimStyleId

setCurrentlyDimStyleId(id): boolean

设置当前标注样式id.

Parameters

NameType
idMcObjectId

Returns

boolean


setCurrentlyLayerId

setCurrentlyLayerId(id): boolean

设置当前标注样式id.

Parameters

NameType
idMcObjectId

Returns

boolean


setCurrentlyLayerName

setCurrentlyLayerName(sName): void

设置当前层名称。

Example

ts
import { MxCpp, McDbDatabase } from "mxcad"

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

Parameters

NameTypeDescription
sNamestring层名称。

Returns

void


setCurrentlyLineTypeName

setCurrentlyLineTypeName(sName): void

设置当前线型名称。

Example

ts
import { MxCpp, McDbDatabase } from "mxcad"

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

Parameters

NameTypeDescription
sNamestring线型名称。

Returns

void


setCurrentlyLineTypeScale

setCurrentlyLineTypeScale(val): number

设置当前线型比例。

Example

ts
import { MxCpp, McDbDatabase } from "mxcad"

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

Parameters

NameTypeDescription
valnumber线型比例。

Returns

number

当前线型比例。


setCurrentlyLinetypeId

setCurrentlyLinetypeId(id): boolean

设置当前标注样式id.

Parameters

NameType
idMcObjectId

Returns

boolean


setCurrentlyTextStyle

setCurrentlyTextStyle(sName): void

设置当前文字样式名称。

Example

ts
import { MxCpp, McDbDatabase } from "mxcad"

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

Parameters

NameTypeDescription
sNamestring文字样式名称。

Returns

void


setCurrentlyTrueColor

setCurrentlyTrueColor(color): any

设置当前CAD颜色。

Example

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

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

Parameters

NameTypeDescription
colorMcCmColorCAD颜色。

Returns

any


setJson

setJson(str): boolean

设置 JSON 格式的字符串。

Example

ts
import { McRxObject } from 'mxcad';

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

Parameters

NameTypeDescription
strstringJSON 格式的字符串。

Returns

boolean

是否设置成功。

Inherited from

McRxObject.setJson