Skip to content

mxcad_2d API 文档 / 2d / McDbObject

Class: McDbObject ​

2d.McDbObject

McDbObject 是数据库对象的基础类,负责承载 CAD 数据库中各类对象的通用能力。

Description

该类用于表示图数据库中的一个对象实体,并提供通用的对象操作接口。 通过它可以完成:

  • 获取对象 ID、句柄、数据库、拥有者以及扩展字典;
  • 删除、反删除、克隆对象;
  • 判断对象是否已删除;
  • 触发对象修改事件,更新图形显示;
  • 作为所有数据库实体对象的公共基类,为派生类提供统一行为。

使用方式:

  1. 先从对象 ID 或数据库中获取某个 McDbObject;
  2. 调用 getObjectID()、getDatabase()、getHandle() 等方法读取对象元信息;
  3. 使用 erase()、clone()、assertObjectModification() 等方法进行对象操作;
  4. 进一步根据对象类型转换到具体实体对象继续编辑。

总结:在实际开发中,McDbObject 主要用于统一管理数据库对象的通用属性和基础操作,是所有 CAD 实体对象的基础抽象层。

Example

ts
import { MxCpp, McDbLine, McGePoint3d } from "mxcad";

async function testDbObject() {
  const mxcad = MxCpp.getCurrentMxCAD();
  const line = new McDbLine(new McGePoint3d(0, 0, 0), new McGePoint3d(200, 0, 0));
  const id = mxcad.drawEntity(line);
  if (!id || id.isNull()) return;

  const obj = id.getMcDbObject();
  if (!obj) return;

  const objectId = obj.getObjectID();
  console.log("对象 ID:", objectId);
  console.log("对象句柄:", obj.getHandle());
  console.log("对象所在数据库:", obj.getDatabase());

  const isErased = obj.isErased();
  console.log("是否已删除:", isErased);
}

Hierarchy ​

Table of contents ​

Constructors ​

Properties ​

Accessors ​

Methods ​

Constructors ​

constructor ​

• new McDbObject(imp?)

构造函数。

Parameters ​

NameTypeDescription
imp?any内部实现对象。

Overrides ​

McRxObject.constructor

Properties ​

imp ​

• imp: any = 0

内部实现对象。

Inherited from ​

McRxObject.imp

Accessors ​

dxf0 ​

• get dxf0(): string

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

Returns ​

string

Inherited from ​

McRxObject.dxf0


objectName ​

• get objectName(): string

获取对象名称。

Returns ​

string

返回对象名

Inherited from ​

McRxObject.objectName

Methods ​

assertObjectModification ​

▸ assertObjectModification(autoUndo?): number

设置对象被改变的状态,可自动触发更新显示函数,更新显示。 比如块表记录更新了,需要通知块引用更新显示,可以调用该函数。

Parameters ​

NameTypeDefault valueDescription
autoUndobooleanfalse这次修改是否要自动支持撤销,默认为false

Returns ​

number


clone ​

▸ clone(): null | McDbObject

克隆对象。

Returns ​

null | McDbObject

克隆出的对象。


createExtensionDictionary ​

▸ createExtensionDictionary(): boolean

创建对象的扩展字典数据.

Returns ​

boolean


erase ​

▸ erase(): boolean

删除对象。

Returns ​

boolean

是否删除成功。


getDatabase ​

▸ getDatabase(): McDbDatabase

得到对象所在的数据库

Returns ​

McDbDatabase

返回数据库


getDatabaseIndexId ​

▸ getDatabaseIndexId(): number

获取对象的索引ID

Returns ​

number


getExtensionDictionary ​

▸ getExtensionDictionary(): McDbDictionary

得到对象的扩展字典数据.

Returns ​

McDbDictionary

扩展字典数据


getGripEditBasePointsIndex ​

▸ getGripEditBasePointsIndex(): number[]

获取对象的夹点对应的编辑基点索引。

Returns ​

number[]


getGripPoints ​

▸ getGripPoints(): McGePoint3dArray

获取对象的夹点数组

Returns ​

McGePoint3dArray


getHandle ​

▸ getHandle(): string

得到对象句柄

Returns ​

string

返回对象句柄


getImp ​

▸ getImp(): any

获取内部实现对象。

Returns ​

any

内部实现对象。

Inherited from ​

McRxObject.getImp


getJson ​

▸ getJson(): string

获取 JSON 格式的字符串。

Returns ​

string

JSON 格式的字符串。

Inherited from ​

McRxObject.getJson


getObjectID ​

▸ getObjectID(): McObjectId

获取对象 ID。

Returns ​

McObjectId

对象 ID。


getOwnerID ​

▸ getOwnerID(): number

得到对象拥用者的id

Returns ​

number


initTempObject ​

▸ initTempObject(imp): void

初始化临时对象。

Parameters ​

NameTypeDescription
impany内部实现对象。

Returns ​

void

Inherited from ​

McRxObject.initTempObject


isErased ​

▸ isErased(): boolean

对象是否已经删除

Returns ​

boolean


isHaveExtensionDictionary ​

▸ isHaveExtensionDictionary(): boolean

是否有扩展字典数据.

Returns ​

boolean


isKindOf ​

▸ isKindOf(sObjectName): boolean

判断对象类型

Parameters ​

NameTypeDescription
sObjectNamestring类型名

Returns ​

boolean

返回对象是否是目标类型

Inherited from ​

McRxObject.isKindOf


isNull ​

▸ isNull(): any

判断是否为空对象

Returns ​

any

Inherited from ​

McRxObject.isNull


moveGripPointsAt ​

▸ moveGripPointsAt(iIndex, dXOffset, dYOffset, dZOffset): any

移动对象的夹点

Parameters ​

NameTypeDescription
iIndexnumber索引
dXOffsetnumberX轴偏移量
dYOffsetnumberY轴偏移量
dZOffsetnumberZ轴偏移量

Returns ​

any


setJson ​

▸ setJson(str): boolean

设置 JSON 格式的字符串。

Parameters ​

NameTypeDescription
strstringJSON 格式的字符串。

Returns ​

boolean

是否设置成功。

Inherited from ​

McRxObject.setJson


unErase ​

▸ unErase(): boolean

反删除对象。

Returns ​

boolean