mxcad_2d API 文档 / 2d / McDbDatabase
Class: McDbDatabase
2d.McDbDatabase
表示数据库,图形中的所有信息都存放在该对象中,调用mxcad.getDatabase()函数得到控件的数据库。
Hierarchy
↳
McDbDatabase
Table of contents
Constructors
Properties
Accessors
Methods
- CreateGroup
- GetGroupDictionary
- SetCurrentlyTextStyleId
- getBlockTable
- getCurrentlyColorIndex
- getCurrentlyDimStyleId
- getCurrentlyDrawColor
- getCurrentlyLayerId
- getCurrentlyLayerName
- getCurrentlyLineTypeName
- getCurrentlyLineTypeScale
- getCurrentlyLinetypeId
- getCurrentlyTextStyleId
- getCurrentlyTextStyleName
- getCurrentlyTrueColor
- getDimStyleTable
- getEntitiesInTheGroup
- getImp
- getJson
- getLayerTable
- getLinetypeTable
- getNamedObjectsDictionary
- getTextStyleTable
- handleToIdIndex
- initTempObject
- isKindOf
- isModifyed
- isNull
- resetModificationStatus
- setCurrentlyColorIndex
- setCurrentlyDimStyleId
- setCurrentlyLayerId
- setCurrentlyLayerName
- setCurrentlyLineTypeName
- setCurrentlyLineTypeScale
- setCurrentlyLinetypeId
- setCurrentlyTextStyle
- setCurrentlyTrueColor
- setJson
- wblock
Constructors
constructor
• new McDbDatabase(imp?
)
构造函数。
Parameters
Name | Type | Description |
---|---|---|
imp? | any | 内部实现对象。 |
Overrides
Properties
imp
• imp: any
= 0
内部实现对象。
Inherited from
Accessors
blockTable
• get
blockTable(): McDbBlockTable
获取块表
Returns
Example
import { MxCpp, McDbDatabase } from "mxcad"
const dataBase:McDbDatabase = MxCpp.getCurrentMxCAD().getDatabase();
let blkTable = dataBase.blockTable;
currentSpace
• get
currentSpace(): McDbBlockTableRecord
返回当前空间块表记录
Returns
块表记录
Example
import { MxCpp, McDbDatabase } from "mxcad"
const dataBase:McDbDatabase = MxCpp.getCurrentMxCAD().getDatabase();
let currentBlkRec = dataBase.currentSpace;
dimStyleTable
• get
dimStyleTable(): McDbDimStyleTable
获取标注样式表。
Returns
线型表。
dxf0
• get
dxf0(): string
得到对象的DXF组码的类型名,这个和AutoCAD中的DXF组码是一样。 比如直线的类型名为:McDbLine,DXF0组码值: LINE,DXF0组码值可以用来构造集时的类型过滤。
Returns
string
Inherited from
McRxObject.dxf0
layerTable
• get
layerTable(): McDbLayerTable
获取层表
Returns
Example
import { MxCpp, McDbDatabase } from "mxcad"
const dataBase:McDbDatabase = MxCpp.getCurrentMxCAD().getDatabase();
let layerTable = dataBase.layerTable;
linetypeTable
• get
linetypeTable(): McDbLinetypeTable
获取线型表
Returns
Example
import { MxCpp, McDbDatabase } from "mxcad"
const dataBase:McDbDatabase = MxCpp.getCurrentMxCAD().getDatabase();
let lineTypeTable = dataBase.linetypeTable;
objectName
• get
objectName(): string
获取对象名称。
Returns
string
返回对象名
Example
import { McRxObject } from 'mxcad';
let obj = new McRxObject();
console.log(obj.objectName);
Inherited from
McRxObject.objectName
textStyleTable
• get
textStyleTable(): McDbTextStyleTable
获取文字样式表
Returns
Example
import { MxCpp, McDbDatabase } from "mxcad"
const dataBase:McDbDatabase = MxCpp.getCurrentMxCAD().getDatabase();
let textStyleTable = dataBase.textStyleTable;
Methods
CreateGroup
▸ CreateGroup(ids
, name?
): boolean
把一堆对象创建一个组
Parameters
Name | Type | Default value |
---|---|---|
ids | McObjectId [] | undefined |
name | string | "" |
Returns
boolean
McDbDictionary
GetGroupDictionary
▸ GetGroupDictionary(): McDbDictionary
得到图纸的组字典对象。
Returns
McDbDictionary
Example
___
### 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
import { MxCpp, McDbDatabase } from "mxcad"
const dataBase:McDbDatabase = MxCpp.getCurrentMxCAD().getDatabase();
const colorIndex = dataBase.getCurrentlyColorIndex();
getCurrentlyDimStyleId
▸ getCurrentlyDimStyleId(): McObjectId
返回当前标注样式id.
Returns
getCurrentlyDrawColor
▸ getCurrentlyDrawColor(): Color
获取当前绘图使用的颜色
Returns
Color
Example
import { MxCpp, McDbDatabase } from "mxcad"
const dataBase:McDbDatabase = MxCpp.getCurrentMxCAD().getDatabase();
const color = dataBase.getCurrentlyDrawColor();
getCurrentlyLayerId
▸ getCurrentlyLayerId(): McObjectId
返回当前层id.
Returns
getCurrentlyLayerName
▸ getCurrentlyLayerName(): string
获取当前层名称。
Returns
string
当前层名称。
Example
import { MxCpp, McDbDatabase } from "mxcad"
const dataBase:McDbDatabase = MxCpp.getCurrentMxCAD().getDatabase();
const layerName = dataBase.getCurrentlyLayerName();
getCurrentlyLineTypeName
▸ getCurrentlyLineTypeName(): string
获取当前线型名称。
Returns
string
当前线型名称。
Example
import { MxCpp, McDbDatabase } from "mxcad"
const dataBase:McDbDatabase = MxCpp.getCurrentMxCAD().getDatabase();
const name = dataBase.getCurrentlyLineTypeName();
getCurrentlyLineTypeScale
▸ getCurrentlyLineTypeScale(): number
获取当前线型比例。
Returns
number
当前线型比例。
Example
import { MxCpp, McDbDatabase } from "mxcad"
const dataBase:McDbDatabase = MxCpp.getCurrentMxCAD().getDatabase();
let currentLTS = dataBase.getCurrentlyLineTypeScale();
getCurrentlyLinetypeId
▸ getCurrentlyLinetypeId(): McObjectId
返回当前线型id.
Returns
getCurrentlyTextStyleId
▸ getCurrentlyTextStyleId(): McObjectId
返回当前文字样式id.
Returns
getCurrentlyTextStyleName
▸ getCurrentlyTextStyleName(): string
获取当前文字样式名称。
Returns
string
当前文字样式名称。
Example
import { MxCpp, McDbDatabase } from "mxcad"
const dataBase:McDbDatabase = MxCpp.getCurrentMxCAD().getDatabase();
const textStyName = dataBase.getCurrentlyTextStyleName();
getCurrentlyTrueColor
▸ getCurrentlyTrueColor(): McCmColor
获取当前CAD颜色。
Returns
当前CAD颜色。
Example
import { MxCpp, McDbDatabase } from "mxcad"
const dataBase:McDbDatabase = MxCpp.getCurrentMxCAD().getDatabase();
const color = dataBase.getCurrentlyTrueColor();
getDimStyleTable
▸ getDimStyleTable(): McDbDimStyleTable
获取标注样式表。
Returns
线型表。
getEntitiesInTheGroup
▸ getEntitiesInTheGroup(id
): McObjectId
[]
得到对象所在组中的所有对象id
Parameters
Name | Type |
---|---|
id | McObjectId |
Returns
McDbDictionary
Example
___
### getImp
▸ **getImp**(): `any`
获取内部实现对象。
#### Returns
`any`
内部实现对象。
**`Example`**
```ts
import { McRxObject } from 'mxcad';
let obj = new McRxObject();
let imp = obj.getImp();
Inherited from
getJson
▸ getJson(): string
获取 JSON 格式的字符串。
Returns
string
JSON 格式的字符串。
Example
import { McRxObject } from 'mxcad';
let obj = new McRxObject();
const json = obj.getJson()
Inherited from
getLayerTable
▸ getLayerTable(): McDbLayerTable
获取层表。
Returns
层表。
Example
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
线型表。
Example
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
Example
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
文字样式表。
Example
//获取所有文字样式
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
Name | Type |
---|---|
sHandle | string |
Returns
Example
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
Name | Type | Description |
---|---|---|
imp | any | 内部实现对象。 |
Returns
void
Example
import { McRxObject } from 'mxcad';
let obj = new McRxObject();
obj.initTempObject()
Inherited from
isKindOf
▸ isKindOf(sObjectName
): boolean
判断对象类型
Parameters
Name | Type | Description |
---|---|---|
sObjectName | string | 类型名 |
Returns
boolean
返回对象是否是目标类型
Example
import { McRxObject } from 'mxcad';
let obj = new McRxObject();
let isKind = obj.isKindOf('SomeObjectType');
console.log(isKind); // 输出: true 或 false
Inherited from
isModifyed
▸ isModifyed(): boolean
当前数据库是否被修改
Returns
boolean
返回布尔值
Example
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
import { McRxObject } from 'mxcad';
let obj = new McRxObject();
console.log(obj.isNull()); // 输出: true 或 false
Inherited from
resetModificationStatus
▸ resetModificationStatus(): void
把当前数据库修改状态重置成未修改状态
Returns
void
Example
import { MxCpp, McDbDatabase } from "mxcad"
const dataBase:McDbDatabase = MxCpp.getCurrentMxCAD().getDatabase();
dataBase.resetModificationStatus();
setCurrentlyColorIndex
▸ setCurrentlyColorIndex(colorIndex
): any
设置当前颜色索引(ColorIndexType)。
Parameters
Name | Type | Description |
---|---|---|
colorIndex | number | 颜色索引。 |
Returns
any
Example
import { MxCpp, McDbDatabase } from "mxcad"
const dataBase:McDbDatabase = MxCpp.getCurrentMxCAD().getDatabase();
const colorIndex = dataBase.getCurrentlyColorIndex();
setCurrentlyDimStyleId
▸ setCurrentlyDimStyleId(id
): boolean
设置当前标注样式id.
Parameters
Name | Type |
---|---|
id | McObjectId |
Returns
boolean
setCurrentlyLayerId
▸ setCurrentlyLayerId(id
): boolean
设置当前标注样式id.
Parameters
Name | Type |
---|---|
id | McObjectId |
Returns
boolean
setCurrentlyLayerName
▸ setCurrentlyLayerName(sName
): void
设置当前层名称。
Parameters
Name | Type | Description |
---|---|---|
sName | string | 层名称。 |
Returns
void
Example
import { MxCpp, McDbDatabase } from "mxcad"
const dataBase:McDbDatabase = MxCpp.getCurrentMxCAD().getDatabase();
dataBase.setCurrentlyLayerName("测试图层");
setCurrentlyLineTypeName
▸ setCurrentlyLineTypeName(sName
): void
设置当前线型名称。
Parameters
Name | Type | Description |
---|---|---|
sName | string | 线型名称。 |
Returns
void
Example
import { MxCpp, McDbDatabase } from "mxcad"
const dataBase:McDbDatabase = MxCpp.getCurrentMxCAD().getDatabase();
dataBase.setCurrentlyLineTypeName("测试线型");
setCurrentlyLineTypeScale
▸ setCurrentlyLineTypeScale(val
): number
设置当前线型比例。
Parameters
Name | Type | Description |
---|---|---|
val | number | 线型比例。 |
Returns
number
当前线型比例。
Example
import { MxCpp, McDbDatabase } from "mxcad"
const dataBase:McDbDatabase = MxCpp.getCurrentMxCAD().getDatabase();
dataBase.setCurrentlyLineTypeScale(0.8);
setCurrentlyLinetypeId
▸ setCurrentlyLinetypeId(id
): boolean
设置当前标注样式id.
Parameters
Name | Type |
---|---|
id | McObjectId |
Returns
boolean
setCurrentlyTextStyle
▸ setCurrentlyTextStyle(sName
): void
设置当前文字样式名称。
Parameters
Name | Type | Description |
---|---|---|
sName | string | 文字样式名称。 |
Returns
void
Example
import { MxCpp, McDbDatabase } from "mxcad"
const dataBase:McDbDatabase = MxCpp.getCurrentMxCAD().getDatabase();
dataBase.setCurrentlyTextStyle("测试文字样式");
setCurrentlyTrueColor
▸ setCurrentlyTrueColor(color
): any
设置当前CAD颜色。
Parameters
Name | Type | Description |
---|---|---|
color | McCmColor | CAD颜色。 |
Returns
any
Example
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
Name | Type | Description |
---|---|---|
str | string | JSON 格式的字符串。 |
Returns
boolean
是否设置成功。
Example
import { McRxObject } from 'mxcad';
let obj = new McRxObject();
const res = obj.setJson('{"key": "value"}');
console.log(res)
Inherited from
wblock
▸ wblock(database
, aryId
, ptBase?
): boolean
写块
Parameters
Name | Type |
---|---|
database | McDbDatabase |
aryId | McObjectId [] |
ptBase? | McGePoint3d |
Returns
boolean
Example