mxcad_2d API 文档 / 2d / McDbDictionary
Class: McDbDictionary
2d.McDbDictionary
McDbDictionary 是数据库中的命名字典对象,用于存放键值映射关系,以及嵌套字典和扩展记录数据。
Description
该类可视为一个键值映射表,将字符串名称映射到对象实例,用于保存图纸中的自定义数据、扩展数据和字典嵌套结构。 通过它可以完成:
- 获取所有对象名和对象 ID;
- 向字典中新增对象;
- 按名称查找和删除对象;
- 嵌套保存多个字典和扩展记录;
- 扩展图纸数据模型。
使用方式:
- 从数据库中获取命名对象字典
MxCpp.getCurrentMxCAD().getDatabase().getNamedObjectsDictionary(); - 调用 addObject()、getAt()、remove() 管理键值;
- 继续通过对象 ID 获取具体的字典或扩展记录对象;
- 用于自定义数据存储和扩展数据管理。
总结:在实际开发中,McDbDictionary 是图纸自定义数据存储和扩展信息管理的核心容器,适合保存各种命名对象和嵌套字典。
Example
import { McDbDictionary, McDbXrecord } from "mxcad"
//遍历字典
// 获取数据库中的命名对象字典内容。
function MxTest_GetNamedObjectsDictionary() {
// 获取当前CAD对象
let mxcad = MxCpp.getCurrentMxCAD();
// 获取数据库中的字典对象
let dict = mxcad.getDatabase().getNamedObjectsDictionary();
// 获取字典中所有的对象名
let aryName = dict.getAllObjectName();
// 遍历对象名
aryName.forEach((name) => {
console.log(name);
let id = dict.getAt(name);
let obj = id.getMcDbObject();
if (obj instanceof McDbDictionary) {
let dict: McDbDictionary = obj;
console.log(dict);
MxTest_DictionaryData(dict);// 递归遍历字典对象
}
})
}
function MxTest_DictionaryData(dict: McDbDictionary) {
let aryName = dict.getAllObjectName();
aryName.forEach((name) => {
console.log(name);
let id = dict.getAt(name);
let obj = id.getMcDbObject();
if (obj instanceof McDbDictionary) {
let dict: McDbDictionary = obj;
console.log(dict);
MxTest_DictionaryData(dict);
}
else if (obj instanceof McDbXrecord) {
let xrec: McDbXrecord = obj;
let data = xrec.getData()
data.PrintData();
}
})
}Hierarchy
↳
McDbDictionary
Table of contents
Constructors
Properties
Accessors
Methods
- addObject
- assertObjectModification
- clone
- createExtensionDictionary
- erase
- getAllObject
- getAllObjectName
- getAt
- getDatabase
- getDatabaseIndexId
- getExtensionDictionary
- getGripEditBasePointsIndex
- getGripPoints
- getHandle
- getImp
- getJson
- getObjectID
- getOwnerID
- initTempObject
- isErased
- isHaveExtensionDictionary
- isKindOf
- isNull
- moveGripPointsAt
- remove
- setJson
- setName
- unErase
Constructors
constructor
• new McDbDictionary(imp?)
构造函数。
Parameters
| Name | Type | Description |
|---|---|---|
imp? | any | 内部实现对象。 |
Overrides
Properties
imp
• imp: any = 0
内部实现对象。
Inherited from
Accessors
dxf0
• get dxf0(): string
得到对象的DXF组码的类型名,这个和AutoCAD中的DXF组码是一样。 比如直线的类型名为:McDbLine,DXF0组码值: LINE,DXF0组码值可以用来构造集时的类型过滤。
Returns
string
Inherited from
McDbObject.dxf0
objectName
• get objectName(): string
获取对象名称。
Returns
string
返回对象名
Inherited from
McDbObject.objectName
Methods
addObject
▸ addObject(sName, obj): McObjectId
向字典中添加对象
Parameters
| Name | Type | Description |
|---|---|---|
sName | string | 对象名称 |
obj | McDbObject | 对象 |
Returns
对象ID
assertObjectModification
▸ assertObjectModification(autoUndo?): number
设置对象被改变的状态,可自动触发更新显示函数,更新显示。 比如块表记录更新了,需要通知块引用更新显示,可以调用该函数。
Parameters
| Name | Type | Default value | Description |
|---|---|---|---|
autoUndo | boolean | false | 这次修改是否要自动支持撤销,默认为false |
Returns
number
Inherited from
McDbObject.assertObjectModification
clone
▸ clone(): null | McDbObject
克隆对象。
Returns
null | McDbObject
克隆出的对象。
Inherited from
createExtensionDictionary
▸ createExtensionDictionary(): boolean
创建对象的扩展字典数据.
Returns
boolean
Inherited from
McDbObject.createExtensionDictionary
erase
▸ erase(): boolean
删除对象。
Returns
boolean
是否删除成功。
Inherited from
getAllObject
▸ getAllObject(): McObjectId[]
获取字典中的所有对象。
Returns
对象ID数组
getAllObjectName
▸ getAllObjectName(): McGeStringArray
获取字典中所有的对象名。
Returns
对象名数组
Example
import { MxCpp, McDbDictionary } from "mxcad";
let mxcad = MxCpp.getCurrentMxCAD();
let dict:McDbDictionary = mxcad.getDatabase().getNamedObjectsDictionary();
const aryName = dict.getAllObjectName();
console.log(aryName);getAt
▸ getAt(sName, isGetErased?): McObjectId
获取字典中指定对象
Parameters
| Name | Type | Default value | Description |
|---|---|---|---|
sName | string | undefined | 对象名称 |
isGetErased | boolean | false | 是否获取已删除的对象 |
Returns
对象ID
getDatabase
▸ getDatabase(): McDbDatabase
得到对象所在的数据库
Returns
返回数据库
Inherited from
getDatabaseIndexId
▸ getDatabaseIndexId(): number
获取对象的索引ID
Returns
number
Inherited from
getExtensionDictionary
▸ getExtensionDictionary(): McDbDictionary
得到对象的扩展字典数据.
Returns
扩展字典数据
Inherited from
McDbObject.getExtensionDictionary
getGripEditBasePointsIndex
▸ getGripEditBasePointsIndex(): number[]
获取对象的夹点对应的编辑基点索引。
Returns
number[]
Inherited from
McDbObject.getGripEditBasePointsIndex
getGripPoints
▸ getGripPoints(): McGePoint3dArray
获取对象的夹点数组
Returns
Inherited from
getHandle
▸ getHandle(): string
得到对象句柄
Returns
string
返回对象句柄
Inherited from
getImp
▸ getImp(): any
获取内部实现对象。
Returns
any
内部实现对象。
Inherited from
getJson
▸ getJson(): string
获取 JSON 格式的字符串。
Returns
string
JSON 格式的字符串。
Inherited from
getObjectID
▸ getObjectID(): McObjectId
获取对象 ID。
Returns
对象 ID。
Inherited from
getOwnerID
▸ getOwnerID(): number
得到对象拥用者的id
Returns
number
Inherited from
initTempObject
▸ initTempObject(imp): void
初始化临时对象。
Parameters
| Name | Type | Description |
|---|---|---|
imp | any | 内部实现对象。 |
Returns
void
Inherited from
isErased
▸ isErased(): boolean
对象是否已经删除
Returns
boolean
Inherited from
isHaveExtensionDictionary
▸ isHaveExtensionDictionary(): boolean
是否有扩展字典数据.
Returns
boolean
Inherited from
McDbObject.isHaveExtensionDictionary
isKindOf
▸ isKindOf(sObjectName): boolean
判断对象类型
Parameters
| Name | Type | Description |
|---|---|---|
sObjectName | string | 类型名 |
Returns
boolean
返回对象是否是目标类型
Inherited from
isNull
▸ isNull(): any
判断是否为空对象
Returns
any
Inherited from
moveGripPointsAt
▸ moveGripPointsAt(iIndex, dXOffset, dYOffset, dZOffset): any
移动对象的夹点
Parameters
| Name | Type | Description |
|---|---|---|
iIndex | number | 索引 |
dXOffset | number | X轴偏移量 |
dYOffset | number | Y轴偏移量 |
dZOffset | number | Z轴偏移量 |
Returns
any
Inherited from
remove
▸ remove(sName): boolean
移除指定对象
Parameters
| Name | Type | Description |
|---|---|---|
sName | string | 对象名称 |
Returns
boolean
布尔值
setJson
▸ setJson(str): boolean
设置 JSON 格式的字符串。
Parameters
| Name | Type | Description |
|---|---|---|
str | string | JSON 格式的字符串。 |
Returns
boolean
是否设置成功。
Inherited from
setName
▸ setName(sOldName, sNewName): boolean
修改字典中key的值,到新的值,如果新的值,在字典中已经存在,就会设置失败。 sNewName为空,会自动创建一个匿名名称。
Parameters
| Name | Type |
|---|---|
sOldName | string |
sNewName | string |
Returns
boolean
是否成功
unErase
▸ unErase(): boolean
反删除对象。
Returns
boolean
