mxcad_2d API 文档 / 2d / McObjectTempDraw
Class: McObjectTempDraw
2d.McObjectTempDraw
临时图形绘制管理器 (McObjectTempDraw)
Description
该类用于在 CAD 视图上进行高性能的临时图形绘制(Overlay)。 核心特点是“只读不写”:它允许你在屏幕上绘制图形(如高亮、辅助线、动态反馈), 但不会将这些图形实际保存到图形数据库中。常用于实现鼠标悬停高亮、拖拽预览或临时测量显示。
使用方法总结:
- 通过
MxCpp.mxcad.getTempDraw()获取临时图形绘制对象; - 调用
readyMcDbEntitysWorldDraw()、setDrawColor()等方法准备绘制上下文; - 调用
worldDrawMcDbEntitys()进行临时绘制,完成后使用endMcDbEntitysWorldDraw()结束绘制。
Example
// 场景:选中实体后,将其临时加粗并变红显示(高亮效果)
import { MxCADUtility, MxCpp } from "mxcad";
async function highlightSelectedEntity() {
// 1. 获取用户选择的实体 ID
const retIds = await MxCADUtility.selectEnt("选择加粗显示对象");
if (retIds.length == 0) return;
const ent = retIds[0].getMcDbEntity();
if (!ent) return;
// 2. 获取临时绘制上下文
const mxcad = MxCpp.getCurrentMxCAD();
const tempDraw = mxcad.getTempDraw();
// 3. 配置绘制样式(红色、线宽 0.60mm)
tempDraw.clearAll(); // 清除旧绘制
tempDraw.readyMcDbEntitysWorldDraw(); // 准备上下文
tempDraw.setDrawColor(0xFF0000, 0xFF0000); // 设置颜色
tempDraw.setLineWeightDisplay(true, McDb.LineWeight.kLnWt060); // 设置线宽
// 4. 执行绘制
tempDraw.worldDrawMcDbEntitys(ent as any);
// 5. 结束绘制上下文
tempDraw.endMcDbEntitysWorldDraw();
}Note
- 绘制的内容仅存在于当前视图帧,刷新或重绘后可能会消失,需重新调用。
- 务必成对调用
readyMcDbEntitysWorldDraw和endMcDbEntitysWorldDraw以确保资源正确释放。
Table of contents
Constructors
Methods
- addLines
- addTriangles
- clear
- clearAll
- clearMcDbEntitysDisplay
- disableDepthTestMcDbEntitysDisplay
- endMcDbEntitysWorldDraw
- freeMcDbEntitysDisplay
- readyMcDbEntitysWorldDraw
- setDrawColor
- setDrawOrder
- setLineWeightDisplay
- worldDrawMcDbEntitys
Constructors
constructor
• new McObjectTempDraw(imp)
构造函数
Parameters
| Name | Type | Description |
|---|---|---|
imp | any | 对象实现 |
Methods
addLines
▸ addLines(vecLinePoints): void
添加临时绘制线条数据
Parameters
| Name | Type | Description |
|---|---|---|
vecLinePoints | McGePoint3dArray | 线条点数组 |
Returns
void
addTriangles
▸ addTriangles(vecTrianglesPoints): void
添加临时绘制填充三角形数据
Parameters
| Name | Type | Description |
|---|---|---|
vecTrianglesPoints | McGePoint3dArray | 三角形点数组 |
Returns
void
clear
▸ clear(): void
清除临时绘制数据
Returns
void
clearAll
▸ clearAll(): void
清除所有临时绘制内容
Returns
void
Description
移除当前视图上所有通过此类绘制的临时图形。
clearMcDbEntitysDisplay
▸ clearMcDbEntitysDisplay(): void
清除McDbEntitys临时绘制的数据
Returns
void
disableDepthTestMcDbEntitysDisplay
▸ disableDepthTestMcDbEntitysDisplay(isDisable?): void
禁用McDbEntitys临时绘制的OpenGL的DepthTest
Parameters
| Name | Type | Default value | Description |
|---|---|---|---|
isDisable | boolean | true | 是否禁用深度测试,默认为true |
Returns
void
endMcDbEntitysWorldDraw
▸ endMcDbEntitysWorldDraw(): void
结束对McDbEntitys的临时绘制的上下文,释放资源。
Returns
void
freeMcDbEntitysDisplay
▸ freeMcDbEntitysDisplay(): void
释放对McDbEntitys的临时绘制上下文。
Returns
void
readyMcDbEntitysWorldDraw
▸ readyMcDbEntitysWorldDraw(): void
准备对McDbEntitys的临时绘制上下文。
Returns
void
setDrawColor
▸ setDrawColor(color, iMcDbEntityDrawColor?): void
设置Draw颜色
Parameters
| Name | Type | Default value | Description |
|---|---|---|---|
color | number | undefined | 颜色值 |
iMcDbEntityDrawColor | number | -2 | McDbEntity的绘制颜色 |
Returns
void
setDrawOrder
▸ setDrawOrder(iDrawOrder, iMcDbEntityDrawOrder): void
设置显示顺序
Parameters
| Name | Type | Description |
|---|---|---|
iDrawOrder | number | 绘制顺序 |
iMcDbEntityDrawOrder | number | McDbEntity的绘制顺序 |
Returns
void
setLineWeightDisplay
▸ setLineWeightDisplay(val?, iGlobalLineweight?): void
启用线重的显示。
Parameters
| Name | Type | Default value | Description |
|---|---|---|---|
val | boolean | true | 是否启用线重显示 |
iGlobalLineweight | number | -1 | 全局线宽,默认为-1表示使用默认线宽 |
Returns
void
worldDrawMcDbEntitys
▸ worldDrawMcDbEntitys(ent): boolean
生成McDbEntitys临时绘制的数据
Parameters
| Name | Type | Description |
|---|---|---|
ent | McDbEntity | McDbEntity对象 |
Returns
boolean
