[mxcad_2d API documentation] (../README. md)/[2d] (../modules/2d. md)/McDbDictionary
Class: McDbDictionary
2d.McDbDictionary
McDbDictionary is a named dictionary object in a database used to store key value mapping relationships, nested dictionaries, and extended record data.
Description
This class can be viewed as a key value mapping table that maps string names to object instances, used to store custom data, extended data, and nested dictionary structures in drawings. It can accomplish: -Retrieve all object names and object IDs; -Add objects to the dictionary; -Search and delete objects by name; -Nesting multiple dictionaries and extended records; -Expand the drawing data model.
Usage:
- Retrieve the named object dictionary
MxCpp. getCurrentMxCAD(). getDB2(). getNamedObjectionsDictionaryfrom the database; - Call addObject (), getAt (), remove() to manage key values;
- Continue to obtain specific dictionaries or extended record objects through object IDs;
- Used for custom data storage and extended data management.
Summary: In practical development, McDbDictionary is the core container for custom data storage and extended information management of drawings, suitable for storing various named objects and nested dictionaries.
Example
import { McDbDictionary, McDbXrecord } from "mxcad"
//Traverse the dictionary
//Retrieve the contents of the named object dictionary from the database.
function MxTest_GetNamedObjectsDictionary() {
//Retrieve the current CAD object
let mxcad = MxCpp.getCurrentMxCAD();
//Retrieve dictionary objects from the database
let dict = mxcad.getDatabase().getNamedObjectsDictionary();
//Retrieve all object names from the dictionary
let aryName = dict.getAllObjectName();
//Traverse object names
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);// Recursive traversal of dictionary objects
}
})
}
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?)
Constructor.
Parameters
| Name | Type | Description |
|---|---|---|
imp? | Any | Internal implementation object |
Overrides
Properties
imp
• imp: any = 0
Internal implementation object.
Inherited from
Accessors
dxf0
• get dxf0(): string
Obtain the type name of the object's DXF group code, which is the same as the DXF group code in AutoCAD. For example, the type name of the line is McDbLine, and the group code value for DXF0 is: LINE and DXF0 group code values can be used for type filtering when constructing sets.
Returns
string
Inherited from
McDbObject.dxf0
objectName
• get objectName(): string
Get the object name.
Returns
string
Return object name
Inherited from
McDbObject.objectName
Methods
addObject
▸ addObject(sName, obj): McObjectId
Add objects to the dictionary
Parameters
| Name | Type | Description |
|---|---|---|
| SName | string | Object Name |
| Obj | [McDbObject] (2d. McDbObject. md) | Object |
Returns
Object ID
assertObjectModification
▸ assertObjectModification(autoUndo?): number
Setting the state of the object to be changed can automatically trigger the update display function to update the display. For example, if the block table record is updated and the block reference needs to be notified to update the display, this function can be called.
Parameters
| Name | Type | Default value | Description |
|---|---|---|---|
| AutoUndo | boolean | false | Should this modification automatically support undo? Default is false |
Returns
number
Inherited from
McDbObject.assertObjectModification
clone
▸ clone(): null | McDbObject
Clone objects.
Returns
null | McDbObject
The cloned object.
Inherited from
createExtensionDictionary
▸ createExtensionDictionary(): boolean
Create extended dictionary data for objects
Returns
boolean
Inherited from
McDbObject.createExtensionDictionary
erase
▸ erase(): boolean
Delete object.
Returns
boolean
Whether the deletion was successful.
Inherited from
getAllObject
▸ getAllObject(): McObjectId[]
Retrieve all objects from the dictionary.
Returns
Object ID array
getAllObjectName
▸ getAllObjectName(): McGeStringArray
Retrieve all object names from the dictionary.
Returns
Object name array
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
Retrieve the specified object from the dictionary
Parameters
| Name | Type | Default value | Description |
|---|---|---|---|
| SName | string | undefined | Object name |
| Is it possible to retrieve deleted objects |
Returns
Object ID
getDatabase
▸ getDatabase(): McDbDatabase
Get the database where the object is located
Returns
Return to database
Inherited from
getDatabaseIndexId
▸ getDatabaseIndexId(): number
Get the index ID of the object
Returns
number
Inherited from
getExtensionDictionary
▸ getExtensionDictionary(): McDbDictionary
Obtain the extended dictionary data of the object
Returns
Expand dictionary data
Inherited from
McDbObject.getExtensionDictionary
getGripEditBasePointsIndex
▸ getGripEditBasePointsIndex(): number[]
Retrieve the edit base point index corresponding to the grip of the object.
Returns
number[]
Inherited from
McDbObject.getGripEditBasePointsIndex
getGripPoints
▸ getGripPoints(): McGePoint3dArray
Get the grip array of the object
Returns
Inherited from
getHandle
▸ getHandle(): string
Obtain object handle
Returns
string
Return object handle
Inherited from
getImp
▸ getImp(): any
Retrieve internal implementation objects.
Returns
any
Internal implementation object.
Inherited from
getJson
▸ getJson(): string
Retrieve a string in JSON format.
Returns
string
A string in JSON format.
Inherited from
getObjectID
▸ getObjectID(): McObjectId
Get the object ID.
Returns
Object ID.
Inherited from
getOwnerID
▸ getOwnerID(): number
Obtain the ID of the object owner
Returns
number
Inherited from
initTempObject
▸ initTempObject(imp): void
Initialize temporary objects.
Parameters
| Name | Type | Description |
|---|---|---|
| 'imp' | 'any' | Internal implementation object |
Returns
void
Inherited from
isErased
▸ isErased(): boolean
Has the object been deleted
Returns
boolean
Inherited from
isHaveExtensionDictionary
▸ isHaveExtensionDictionary(): boolean
Is there any extended dictionary data available
Returns
boolean
Inherited from
McDbObject.isHaveExtensionDictionary
isKindOf
▸ isKindOf(sObjectName): boolean
Determine object type
Parameters
| Name | Type | Description |
|---|---|---|
| SOrtName | string | Type Name |
Returns
boolean
Return whether the object is of the target type
Inherited from
isNull
▸ isNull(): any
Determine if it is an empty object
Returns
any
Inherited from
moveGripPointsAt
▸ moveGripPointsAt(iIndex, dXOffset, dYOffset, dZOffset): any
Grips for moving objects
Parameters
| Name | Type | Description |
|---|---|---|
| IIndex | Number | Index |
| DXOffset | number | X-axis offset |
| DYOffset | number | Y-axis offset |
| DZOffset | number | Z-axis offset |
Returns
any
Inherited from
remove
▸ remove(sName): boolean
Remove specified object
Parameters
| Name | Type | Description |
|---|---|---|
| SName | string | Object Name |
Returns
boolean
Boolean value
setJson
▸ setJson(str): boolean
Set a string in JSON format.
Parameters
| Name | Type | Description |
|---|---|---|
| Str | string | JSON formatted string |
Returns
boolean
Is the setting successful.
Inherited from
setName
▸ setName(sOldName, sNewName): boolean
Modify the value of the key in the dictionary to a new value. If the new value already exists in the dictionary, the setting will fail. If sNewName is empty, an anonymous name will be automatically created.
Parameters
| Name | Type |
|---|---|
sOldName | string |
sNewName | string |
Returns
boolean
Whether it is successful
unErase
▸ unErase(): boolean
Anti delete object.
Returns
boolean
