[mxcad_2d API documentation] (../README. md)/[2d] (../modules/2d. md)/McDbBlockTable
Class: McDbBlockTable
2d.McDbBlockTable
McDbBlockTable is a block table in the database, responsible for managing all block definitions in the current drawing.
Description
This class is used to maintain and access the set of block definitions in drawings, including traversal, addition, search, and determining whether block records exist. It can accomplish: -Obtain all block record IDs; -Add a new named block definition; -Search for block records by name; -Determine whether the block exists; -Provide entry points for subsequent block insertions and block references.
Usage:
- Retrieve the block table
MxCpp. getCurrentMxCAD(). getBlockTable()from the database; - Call getAllRecordId() to view all block table record objects;
- Use add()/get()/has() to manage block definitions;
- Retrieve McDbBlockTableRecord from the returned McObjectid and continue editing the block content.
Summary: In practical development, McDbBlockTable is the core entry point for block management, suitable for creating and retrieving block definitions, supporting block insertion and dynamic block development.
Example
//Traverse all blocks in the drawing
import { MxCpp, McDbBlockTable } from "mxcad"
//Retrieve the current CAD object
let mxcad = MxCpp.getCurrentMxCAD();
//Get block table object
let blockTable: McDbBlockTable = mxcad.getDatabase().getBlockTable();
//Retrieve all record object IDs from the block table
let aryId = blockTable.getAllRecordId();
//Traverse the record object ID to obtain the details of the block table record object
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);
});Hierarchy
↳
McDbBlockTable
Table of contents
Constructors
Properties
Accessors
Methods
- add
- assertObjectModification
- clone
- createExtensionDictionary
- erase
- get
- getAllRecordId
- getDatabase
- getDatabaseIndexId
- getExtensionDictionary
- getGripEditBasePointsIndex
- getGripPoints
- getHandle
- getImp
- getJson
- getObjectID
- getOwnerID
- has
- initTempObject
- isErased
- isHaveExtensionDictionary
- isKindOf
- isNull
- moveGripPointsAt
- setJson
- unErase
Constructors
constructor
• new McDbBlockTable(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
add
▸ add(rec): McObjectId
Add block records to the block table.
Parameters
| Name | Type | Description |
|---|---|---|
| Rec | string \ | [McDbBlockTableRecord] (2d. McDbBlockTableRecord. md) |
Returns
Add block record object ID.
Example
import { MxCpp, McDbBlockTable } from "mxcad"
let mxcad = MxCpp.App.getCurrentMxCAD();
let blockTable: McDbBlockTable = mxcad.getDatabase().getBlockTable();
const blkRec = new McDbBlockTableRecord();
const objId = blockTable.add(blkRec);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
get
▸ get(sName, skipDeleted?): McObjectId
Search for block records in the block table.
Parameters
| Name | Type | Default value | Description |
|---|---|---|---|
| SName | string | undefined | Block record name |
| SkipDeleted | boolean | true | Do you want to skip deleted tile records |
Returns
Block record object ID.
getAllRecordId
▸ getAllRecordId(skipDeleted?): McObjectId[]
Retrieve the IDs of all block records in the block table.
Parameters
| Name | Type | Default value | Description |
|---|---|---|---|
| SkipDeleted | boolean | true | Do you want to skip deleted tile records |
Returns
Ret block record ID array.
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
has
▸ has(sName): boolean
Check if there is a block record with the specified name in the block table.
Parameters
| Name | Type | Description |
|---|---|---|
| SName | string | Block record name |
Returns
boolean
Boolean value.
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
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
unErase
▸ unErase(): boolean
Anti delete object.
Returns
boolean
