Skip to content

[mxcad_2d API documentation] (../README. md)/[2d] (../modules/2d. md)/McDbBlockTableRecord

Class: McDbBlockTableRecord ​

2d.McDbBlockTableRecord

McDbBlockTableRecord is a block table record object used to manage entity collections, base points, and block properties in block definitions.

Description

This class represents a block definition record in CAD, mainly used to maintain the entity content, block base points, and block names inside the block. It can accomplish: -Add entity objects to the block; -Obtain the object IDs of all entities in the block; -Set the base point, bounding box, and name of the block; -As the source of block reference definition, it can be displayed and inserted through McDbBlockReference in the future.

Summary of usage:

  1. Create an instance of McDbBlockTableRecord;
  2. Call appendAcDbEntity () to add the entity to the block;
  3. Set the base point and name of the block through attributes such as origin and name;
  4. Add the block record to the block table and create a block reference display using McDbBlockReference.

Example

ts
//Add Block
   import { MxCpp, McDbBlockTableRecord, McDbBlockReference, McDbLine, McCmColor } from "mxcad"

   let mxcad = MxCpp.getCurrentMxCAD();
   let blkTable =  mxcad.getDatabase().getBlockTable();
   let blkRecId = blkTable.add(new McDbBlockTableRecord());

//Retrieve the newly added block record again based on the Object ID
   let blkTableRecord:McDbBlockTableRecord = blkRecId.getMcDbBlockTableRecord()

//Add two line segments and assign specific attributes to each segment in the block record, such as the starting and ending points
   const line = new McDbLine(80, 80, 0, -80, -80, 0)
   line.trueColor = new McCmColor(255, 0, 0)
   const line1 = new McDbLine(-80, 80, 0, 80, -80, 0)
   blkTableRecord.appendAcDbEntity(line);
   blkTableRecord.appendAcDbEntity(line1);

//The base point for setting the block is usually the point inside the bounding box, which can be arbitrarily specified
   blkTableRecord.origin = new McGePoint3d(0,0,0);

//Instantaneous block reference here requires setting the Object Id obtained from the block record we just added
   let blkRef = new McDbBlockReference();
   blkRef.blockTableRecordId = blkRecId;
//Finally, set the position to render the image block
   blkRef.position = new McGePoint3d(0,0,0);

   mxcad.drawEntity(blkRef);
ts
//Change the color of the block
   import { McDbBlockTableRecord, MxCADResbuf, MxCpp, McCmColor} from "mxcad";
   
//Select the block object and modify its color.
   async function Mx_BlkColor() {
//Select target block
       let filter = new MxCADResbuf();
filter.AddMcDbEntityTypes("INSERT");//  Set filters and select block objects
       const getBlockEvent = new MxCADUiPrEntity()
GetBlockEvent. setMessage ('Select the block that needs to modify the base point');
       getBlockEvent.setFilter(filter);
       const block_id = await getBlockEvent.go();
       if (!block_id.id) return;
//Block entity
       const blkRef = block_id.getMcDbEntity() as McDbBlockReference;
       let blkRec = blkRef.blockTableRecordId.getMcDbBlockTableRecord();
Mx_ModyfBlockRecordEntityColor(blkRec);//  Set the block color type to follow the block

//Set block color
       const getColor = new MxCADUiPrInt();
GetColor.setMessage ('Enter color index (0~256)');
       let colorNum = await getColor.go() || 0;
       let color = new McCmColor();
       color.setColorIndex(colorNum);
       blkRef.trueColor = color;
       const mxcad = MxCpp.getCurrentMxCAD();
       mxcad.updateDisplay()
   }
//Set block color type
   function Mx_ModyfBlockRecordEntityColor(blkRec: McDbBlockTableRecord) {
       blkRec.getAllEntityId().forEach(id => {
           let ent = id.getMcDbEntity();
           ent.colorIndex = ColorIndexType.kByblock;
           if (ent instanceof McDbBlockReference) {
               let blkref = ent as McDbBlockReference;
               Mx_ModyfBlockRecordEntityColor(blkref.blockTableRecordId.getMcDbBlockTableRecord());
           }
       })
   }

Hierarchy ​

Table of contents ​

Constructors ​

Properties ​

Accessors ​

Methods ​

Constructors ​

constructor ​

• new McDbBlockTableRecord(imp?)

Constructor.

Parameters ​

NameTypeDescription
imp?AnyInternal implementation object

Overrides ​

McDbObject.constructor

Properties ​

imp ​

• imp: any = 0

Internal implementation object.

Inherited from ​

McDbObject.imp

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


name ​

• get name(): string

Get or set the name.

Returns ​

string

• set name(val): void

Parameters ​

NameType
valstring

Returns ​

void


objectName ​

• get objectName(): string

Get the object name.

Returns ​

string

Return object name

Inherited from ​

McDbObject.objectName


origin ​

• get origin(): McGePoint3d

Block origin

Returns ​

McGePoint3d

3D point vector

• set origin(origin): void

Parameters ​

NameType
originMcGePoint3d

Returns ​

void

Methods ​

appendAcDbEntity ​

▸ appendAcDbEntity(pEntity): McObjectId

Add corresponding entities to the block

Parameters ​

NameTypeDescription
PEntity[McDbEntity] (2d. McDbEntity. md)Entity

Returns ​

McObjectId

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 ​

NameTypeDefault valueDescription
AutoUndobooleanfalseShould 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 ​

McDbObject.clone


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 ​

McDbObject.erase


getAllEntityId ​

▸ getAllEntityId(skipDeleted?): McObjectId[]

Get the object IDs of all entities in the block

Parameters ​

NameTypeDefault value
skipDeletedbooleantrue

Returns ​

McObjectId[]


getBoundingBox ​

▸ getBoundingBox(): Object

Obtain the minimum outsourcing of the block, and obtain the maximum and minimum points of the block

Returns ​

Object

minPt: Minimum point | maxPt: Maximum point | ret: Was it successfully obtained

NameType
maxPtMcGePoint3d
minPtMcGePoint3d
retboolean

getDatabase ​

▸ getDatabase(): McDbDatabase

Get the database where the object is located

Returns ​

McDbDatabase

Return to database

Inherited from ​

McDbObject.getDatabase


getDatabaseIndexId ​

▸ getDatabaseIndexId(): number

Get the index ID of the object

Returns ​

number

Inherited from ​

McDbObject.getDatabaseIndexId


getExtensionDictionary ​

▸ getExtensionDictionary(): McDbDictionary

Obtain the extended dictionary data of the object

Returns ​

McDbDictionary

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 ​

McGePoint3dArray

Inherited from ​

McDbObject.getGripPoints


getHandle ​

▸ getHandle(): string

Obtain object handle

Returns ​

string

Return object handle

Inherited from ​

McDbObject.getHandle


getImp ​

▸ getImp(): any

Retrieve internal implementation objects.

Returns ​

any

Internal implementation object.

Inherited from ​

McDbObject.getImp


getJson ​

▸ getJson(): string

Retrieve a string in JSON format.

Returns ​

string

A string in JSON format.

Inherited from ​

McDbObject.getJson


getMinMaxDrawOrder ​

▸ getMinMaxDrawOrder(): Object

Return the minimum and maximum display order of all objects in the block table record

Returns ​

Object

minDrawOrder: Minimum Display Order | maxDrawOrder: Maximum Display Order

NameType
maxDrawOrdernumber
minDrawOrdernumber

getObjectID ​

▸ getObjectID(): McObjectId

Get the object ID.

Returns ​

McObjectId

Object ID.

Inherited from ​

McDbObject.getObjectID


getOwnerID ​

▸ getOwnerID(): number

Obtain the ID of the object owner

Returns ​

number

Inherited from ​

McDbObject.getOwnerID


initTempObject ​

▸ initTempObject(imp): void

Initialize temporary objects.

Parameters ​

NameTypeDescription
'imp''any'Internal implementation object

Returns ​

void

Inherited from ​

McDbObject.initTempObject


invalidBoundingBoxBuffer ​

▸ invalidBoundingBoxBuffer(): void

Invalidate the bounding box buffer, force recalculation or update of bounding box information

Returns ​

void


isErased ​

▸ isErased(): boolean

Has the object been deleted

Returns ​

boolean

Inherited from ​

McDbObject.isErased


isHaveExtensionDictionary ​

▸ isHaveExtensionDictionary(): boolean

Is there any extended dictionary data available

Returns ​

boolean

Inherited from ​

McDbObject.isHaveExtensionDictionary


isKindOf ​

▸ isKindOf(sObjectName): boolean

Determine object type

Parameters ​

NameTypeDescription
SOrtNamestringType Name

Returns ​

boolean

Return whether the object is of the target type

Inherited from ​

McDbObject.isKindOf


isNull ​

▸ isNull(): any

Determine if it is an empty object

Returns ​

any

Inherited from ​

McDbObject.isNull


moveGripPointsAt ​

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

Grips for moving objects

Parameters ​

NameTypeDescription
IIndexNumberIndex
DXOffsetnumberX-axis offset
DYOffsetnumberY-axis offset
DZOffsetnumberZ-axis offset

Returns ​

any

Inherited from ​

McDbObject.moveGripPointsAt


setJson ​

▸ setJson(str): boolean

Set a string in JSON format.

Parameters ​

NameTypeDescription
StrstringJSON formatted string

Returns ​

boolean

Is the setting successful.

Inherited from ​

McDbObject.setJson


unErase ​

▸ unErase(): boolean

Anti delete object.

Returns ​

boolean

Inherited from ​

McDbObject.unErase