mxcad_2d API 文档 / 2d / McObjectId
Class: McObjectId
2d.McObjectId
McObjectId 是 MxCAD 中对象实例的标识符,负责描述某个 CAD 对象在数据库中的引用。
Description
该类用于表示一个对象的 ID,并携带对象类型信息,便于在底层数据库和 TypeScript 侧之间建立桥接。 通过它可以完成:
- 判断对象 ID 是否有效或为空;
- 删除对象、查询对象状态;
- 把对象 ID 转换成对应的 McDbObject / McDbEntity / McDbCurve 等对象;
- 通过类型判断确认对象是否属于某个 CAD 类。
使用方式:
- 通过对象操作结果或绘制命令获取 McObjectId;
- 调用 isValid()、isNull()、isKindOf() 进行判定;
- 结合 getMcDbObject()、getMcDbEntity() 等方法获取真实对象实例并继续编辑。
总结:在实际开发中,McObjectId 是 CAD 对象访问的入口,通常用来拿到数据库中的对象引用,然后继续执行选择、查询、删除、转换等操作。
Example
import { MxCpp, McDbLine, McGePoint3d } from "mxcad";
async function testObjectId() {
const mxcad = MxCpp.getCurrentMxCAD();
const line = new McDbLine(new McGePoint3d(0, 0, 0), new McGePoint3d(100, 0, 0));
const id = mxcad.drawEntity(line);
if (!id || id.isNull()) {
console.log("对象创建失败");
return;
}
console.log("对象是否有效:", id.isValid());
console.log("对象是否为空:", id.isNull());
console.log("对象是否为直线:", id.isKindOf("McDbLine"));
const ent = id.getMcDbEntity();
if (ent) {
console.log("实体类型:", ent.objectName);
}
}Table of contents
Constructors
Properties
Methods
- clone
- erase
- getMcDbBlockTableRecord
- getMcDbCurve
- getMcDbCustomEntity
- getMcDbDictionary
- getMcDbDimStyleTableRecord
- getMcDbDimension
- getMcDbEntity
- getMcDbGroup
- getMcDbLayerTableRecord
- getMcDbLinetypeTableRecord
- getMcDbObject
- getMcDbRasterImageDef
- getMcDbTextStyleTableRecord
- getMcDbXrecord
- getMxDbEntity
- getObjectName
- isErase
- isKindOf
- isNull
- isValid
Constructors
constructor
• new McObjectId(id?, type?)
创建一个McObjectId实例。
Parameters
| Name | Type | Default value | Description |
|---|---|---|---|
id | number | 0 | 对象的唯一标识符。 |
type | McObjectIdType | McObjectIdType.kInvalid | 对象的类型。 |
Properties
id
• id: number
对象ID
type
• type: McObjectIdType
对象类型
Methods
clone
▸ clone(): null | McDbObject
克隆对象
Returns
null | McDbObject
返回克隆后的数据库对象
erase
▸ erase(isErase?): void
删除对象。
Parameters
| Name | Type | Default value | Description |
|---|---|---|---|
isErase | boolean | true | 是否删除 |
Returns
void
getMcDbBlockTableRecord
▸ getMcDbBlockTableRecord(): null | McDbBlockTableRecord
返回 MxCAD 块表记录对象。
Returns
null | McDbBlockTableRecord
getMcDbCurve
▸ getMcDbCurve(): null | McDbCurve
返回MxCAD McDbCurve 对象。
Returns
null | McDbCurve
getMcDbCustomEntity
▸ getMcDbCustomEntity(): null | McDbCustomEntity
获取自定义实体
Returns
null | McDbCustomEntity
getMcDbDictionary
▸ getMcDbDictionary(): null | McDbDictionary
获取数据库中的字典信息
Returns
null | McDbDictionary
getMcDbDimStyleTableRecord
▸ getMcDbDimStyleTableRecord(): null | McDbDimStyleTableRecord
返回 MxCAD 标注样表记录对象。
Returns
null | McDbDimStyleTableRecord
getMcDbDimension
▸ getMcDbDimension(): null | McDbDimension
返回MxCAD McDbDimension 对象。
Returns
null | McDbDimension
getMcDbEntity
▸ getMcDbEntity(): null | McDbEntity
返回MxCAD McDbEntity 对象。
Returns
null | McDbEntity
getMcDbGroup
▸ getMcDbGroup(): null | McDbGroup
返回MxCAD McDbGroup 对象。
Returns
null | McDbGroup
getMcDbLayerTableRecord
▸ getMcDbLayerTableRecord(): null | McDbLayerTableRecord
返回 MxCAD 图层表记录对象。
Returns
null | McDbLayerTableRecord
getMcDbLinetypeTableRecord
▸ getMcDbLinetypeTableRecord(): null | McDbLinetypeTableRecord
返回 MxCAD 线型表记录对象。
Returns
null | McDbLinetypeTableRecord
getMcDbObject
▸ getMcDbObject(): null | McDbObject
返回MxCAD McDbObject对象。
Returns
null | McDbObject
返回一个数据库对象
getMcDbRasterImageDef
▸ getMcDbRasterImageDef(): null | McDbRasterImageDef
获取栅格图像信息
Returns
null | McDbRasterImageDef
getMcDbTextStyleTableRecord
▸ getMcDbTextStyleTableRecord(): null | McDbTextStyleTableRecord
返回 MxCAD 文字样式表记录对象。
Returns
null | McDbTextStyleTableRecord
getMcDbXrecord
▸ getMcDbXrecord(): null | McDbXrecord
获取扩展记录信息
Returns
null | McDbXrecord
getMxDbEntity
▸ getMxDbEntity(): null | MxDbEntity
返回MxDraw对象。
Returns
null | MxDbEntity
getObjectName
▸ getObjectName(): string
返回id指向的对象名称.
Returns
string
isErase
▸ isErase(): boolean
id是指向的对像,是否是删除状态.
Returns
boolean
布尔值
isKindOf
▸ isKindOf(className): boolean
判断一个对象的类型
Parameters
| Name | Type | Description |
|---|---|---|
className | string | 类型名 |
Returns
boolean
isNull
▸ isNull(): boolean
id是否为NULL.
Returns
boolean
布尔值
isValid
▸ isValid(): boolean
id是否有效.
Returns
boolean
布尔值
