mxcad_2d API 文档 / 2d / McDbBlockTableRecord
Class: McDbBlockTableRecord
2d.McDbBlockTableRecord
数据库的块表记录对象,实现了对图块的属性相关操作函数。
Example
// 添加图块
import { MxCpp, McDbBlockTableRecord, McDbBlockReference, McDbLine, McCmColor } from "mxcad"
let mxcad = MxCpp.getCurrentMxCAD();
let blkTable = mxcad.getDatabase().getBlockTable();
let blkRecId = blkTable.add(new McDbBlockTableRecord());
// 根据ObjectId再次得到刚刚添加的图块记录
let blkTableRecord:McDbBlockTableRecord = blkRecId.getMcDbBlockTableRecord()
// 添加两条线段再图块记录中 这里每条线段的具体属性比如开始点和结束点自行赋值
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);
// 设置图块的基点 一般是包围盒内的点, 可以任意指定
blkTableRecord.origin = new McGePoint3d(0,0,0);
// 实例化块参照 这里需要设置我们刚刚添加图块记录得到的ObjectId
let blkRef = new McDbBlockReference();
blkRef.blockTableRecordId = blkRecId;
// 最后设置位置 渲染图块
blkRef.position = new McGePoint3d(0,0,0);
mxcad.drawEntity(blkRef);
// 改块颜色
import { McDbBlockTableRecord, MxCADResbuf, MxCpp, McCmColor} from "mxcad";
async function Mx_BlkColor() {
// 选择目标块
let filter = new MxCADResbuf();
filter.AddMcDbEntityTypes("INSERT");// 设置过滤器,选择块对象
const getBlockEvent = new MxCADUiPrEntity()
getBlockEvent.setMessage('选择需要修改基点的块');
getBlockEvent.setFilter(filter);
const block_id = await getBlockEvent.go();
if (!block_id.id) return;
// 块实体
const blkRef = block_id.getMcDbEntity() as McDbBlockReference;
let blkRec = blkRef.blockTableRecordId.getMcDbBlockTableRecord();
Mx_ModyfBlockRecordEntityColor(blkRec);// 设置块颜色类型为随块
// 设置块颜色
const getColor = new MxCADUiPrInt();
getColor.setMessage('输入颜色索引(0~256)');
let colorNum = await getColor.go() || 0;
let color = new McCmColor();
color.setColorIndex(colorNum);
blkRef.trueColor = color;
const mxcad = MxCpp.getCurrentMxCAD();
mxcad.updateDisplay()
}
// 设置块颜色类型
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
↳
McDbBlockTableRecord
Table of contents
Constructors
Properties
Accessors
Methods
- appendAcDbEntity
- assertObjectModification
- clone
- createExtensionDictionary
- erase
- getAllEntityId
- getBoundingBox
- getDatabase
- getDatabaseIndexId
- getExtensionDictionary
- getGripPoints
- getHandle
- getImp
- getJson
- getMinMaxDrawOrder
- getObjectID
- getOwnerID
- initTempObject
- invalidBoundingBoxBuffer
- isErased
- isHaveExtensionDictionary
- isKindOf
- isNull
- moveGripPointsAt
- setJson
- unErase
Constructors
constructor
• new McDbBlockTableRecord(imp?
)
构造函数。
Parameters
Name | Type | Description |
---|---|---|
imp? | any | 内部实现对象。 |
Example
import { McDbBlockTableRecord } from "mxcad";
const blkRec = new McDbBlockTableRecord();
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
name
• get
name(): string
获取或设置名称。
Returns
string
Example
// 假设blkRec为一个有效的块表记录对象
blkRec.name = "测试图块名";
console.log(blkRec.name);//测试图块名
• set
name(val
): void
Parameters
Name | Type |
---|---|
val | string |
Returns
void
objectName
• get
objectName(): string
获取对象名称。
Returns
string
返回对象名
Example
import { McRxObject } from 'mxcad';
let obj = new McRxObject();
console.log(obj.objectName);
Inherited from
McDbObject.objectName
origin
• get
origin(): McGePoint3d
图块原点
Returns
三维点向量
Example
import { McDbBlockTableRecord, McGePoint3d } from "mxcad";
const blkRec = new McDbBlockTableRecord();
blkRec.origin = new McGePoint3d(0,0,0);
console.log("图块原点", blkRec.origin)//(0,0,0)
• set
origin(origin
): void
Parameters
Name | Type |
---|---|
origin | McGePoint3d |
Returns
void
Methods
appendAcDbEntity
▸ appendAcDbEntity(pEntity
): McObjectId
给图块添加对应实体
Parameters
Name | Type | Description |
---|---|---|
pEntity | McDbEntity | 实体 |
Returns
对象id
Example
import { McDbBlockTableRecord, McDbLine } from "mxcad";
const line = new McDbLine(-80, 80, 0, 80, -80, 0);
const blkRec = new McDbBlockTableRecord();
const objId = blkRec.appendAcDbEntity(line)
assertObjectModification
▸ assertObjectModification(autoUndo?
): number
设置对象被改变的状态,可自动触发更新显示函数,更新显示。 比如块表记录更新了,需要通知块引用更新显示,可以调用该函数。
Parameters
Name | Type | Default value |
---|---|---|
autoUndo | boolean | false |
Returns
number
Example
//假设obj为一个数据库对象
obj.assertObjectModification()
Inherited from
McDbObject.assertObjectModification
clone
▸ clone(): null
| McDbObject
克隆对象。
Returns
null
| McDbObject
克隆出的对象。
Example
//假设obj为一个数据库对象
const obj_clone = obj.clone();
Inherited from
createExtensionDictionary
▸ createExtensionDictionary(): boolean
创建对象的扩展字典数据.
Returns
boolean
Example
//假设obj为一个数据库对象
const res = obj.createExtensionDictionary();
Inherited from
McDbObject.createExtensionDictionary
erase
▸ erase(): boolean
删除对象。
Returns
boolean
是否删除成功。
Example
//假设obj为一个数据库对象
const res = obj.erase();
console.log(res);
Inherited from
getAllEntityId
▸ getAllEntityId(skipDeleted?
): McObjectId
[]
获取图块中所有实体的对象ID
Parameters
Name | Type | Default value |
---|---|---|
skipDeleted | boolean | true |
Returns
Example
import { McDbBlockTableRecord, McDbLine } from "mxcad";
const line = new McDbLine(-80, 80, 0, 80, -80, 0);
const blkRec = new McDbBlockTableRecord();
blkRec.appendAcDbEntity(line);
const aryId = blkRec.getAllEntityId();
console.log(aryId)
getBoundingBox
▸ getBoundingBox(): Object
得到图块最小外包,获取图块的最大点和最小点
Returns
Object
minPt:最小点 | maxPt:最大点 | ret:是否获取成功
Name | Type |
---|---|
maxPt | McGePoint3d |
minPt | McGePoint3d |
ret | boolean |
Example
// 假设blkRec为一个有效的块表记录对象
const retVal = blkRec.getBoundingBox();
if(retVal.ret){
console.log("最小点", retVal.minPt);
console.log("最大点", retVal.maxPt);
}else{
console.log("error")
}
getDatabase
▸ getDatabase(): McDbDatabase
得到对象所在的数据库
Returns
返回数据库
Example
//假设obj为一个数据库对象
const data = obj.getDatabase();
Inherited from
getDatabaseIndexId
▸ getDatabaseIndexId(): number
获取对象的索引ID
Returns
number
Example
//假设obj为一个数据库对象
const id = obj.getDatabaseIndexId();
Inherited from
getExtensionDictionary
▸ getExtensionDictionary(): McDbDictionary
得到对象的扩展字典数据.
Returns
扩展字典数据
Example
//假设obj为一个数据库对象
const id = obj.getOwnerID();
Inherited from
McDbObject.getExtensionDictionary
getGripPoints
▸ getGripPoints(): McGePoint3dArray
获取对象的控制点
Returns
Example
//假设obj为一个数据库对象
const ptArr = obj.getGripPoints();
Inherited from
getHandle
▸ getHandle(): string
得到对象句柄
Returns
string
返回对象句柄
Example
//假设obj为一个数据库对象
const handle = obj.getHandle();
Inherited from
getImp
▸ getImp(): any
获取内部实现对象。
Returns
any
内部实现对象。
Example
import { McRxObject } from 'mxcad';
let obj = new McRxObject();
let imp = obj.getImp();
Inherited from
getJson
▸ getJson(): string
获取 JSON 格式的字符串。
Returns
string
JSON 格式的字符串。
Example
import { McRxObject } from 'mxcad';
let obj = new McRxObject();
const json = obj.getJson()
Inherited from
getMinMaxDrawOrder
▸ getMinMaxDrawOrder(): Object
返回块表记录中所有对象的最小,最大显示顺序.
Returns
Object
minDrawOrder: 最小显示顺序 | maxDrawOrder: 最大显示顺序
Name | Type |
---|---|
maxDrawOrder | number |
minDrawOrder | number |
Example
// 获取最小和最大绘制顺序
const { minDrawOrder, maxDrawOrder } = blkRec.getMinMaxDrawOrder();
// 打印结果
console.log("最小绘制顺序:", minDrawOrder);
console.log("最大绘制顺序:", maxDrawOrder);
getObjectID
▸ getObjectID(): McObjectId
获取对象 ID。
Returns
对象 ID。
Example
import { McDbObject } from "mxcad";
const id = obj.getObjectID();
Inherited from
getOwnerID
▸ getOwnerID(): number
得到对象拥用者的id
Returns
number
Example
//假设obj为一个数据库对象
const id = obj.getOwnerID();
Inherited from
initTempObject
▸ initTempObject(imp
): void
初始化临时对象。
Parameters
Name | Type | Description |
---|---|---|
imp | any | 内部实现对象。 |
Returns
void
Example
import { McRxObject } from 'mxcad';
let obj = new McRxObject();
obj.initTempObject()
Inherited from
invalidBoundingBoxBuffer
▸ invalidBoundingBoxBuffer(): void
使边界框缓冲区无效化,强制重新计算或更新边界框信息
Returns
void
Example
// 假设blkRec为一个有效的块表记录对象
blkRec.invalidBoundingBoxBuffer()
isErased
▸ isErased(): boolean
对象是否已经删除
Returns
boolean
Example
//假设obj为一个数据库对象
const res = obj.isErased();
console.log(res);
Inherited from
isHaveExtensionDictionary
▸ isHaveExtensionDictionary(): boolean
是否有扩展字典数据.
Returns
boolean
Example
//假设obj为一个数据库对象
const res = obj.isHaveExtensionDictionary();
Inherited from
McDbObject.isHaveExtensionDictionary
isKindOf
▸ isKindOf(sObjectName
): boolean
判断对象类型
Parameters
Name | Type | Description |
---|---|---|
sObjectName | string | 类型名 |
Returns
boolean
返回对象是否是目标类型
Example
import { McRxObject } from 'mxcad';
let obj = new McRxObject();
let isKind = obj.isKindOf('SomeObjectType');
console.log(isKind); // 输出: true 或 false
Inherited from
isNull
▸ isNull(): any
判断是否为空对象
Returns
any
Example
import { McRxObject } from 'mxcad';
let obj = new McRxObject();
console.log(obj.isNull()); // 输出: true 或 false
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
Example
//假设obj为一个数据库对象
obj.moveGripPointsAt(1,10,10,10);
Inherited from
setJson
▸ setJson(str
): boolean
设置 JSON 格式的字符串。
Parameters
Name | Type | Description |
---|---|---|
str | string | JSON 格式的字符串。 |
Returns
boolean
是否设置成功。
Example
import { McRxObject } from 'mxcad';
let obj = new McRxObject();
const res = obj.setJson('{"key": "value"}');
console.log(res)
Inherited from
unErase
▸ unErase(): boolean
反删除对象。
Returns
boolean
Example
//假设obj为一个数据库对象
const res = obj.unErase();
console.log(res);