[mxcad_2d API documentation] (../README. md)/[2d] (../modules/2d. md)/McObject TempDraw
Class: McObjectTempDraw
2d.McObjectTempDraw
Temporary Graphics Drawing Manager (McObject TempDraw)
Description
This class is used for high-performance temporary graphic rendering (Overlay) on CAD views. The core feature is "read-only without writing": it allows you to draw graphics on the screen (such as highlights, auxiliary lines, dynamic feedback), But these graphics will not be actually saved to the graphics database. Commonly used to achieve mouse hover highlighting, drag and drop preview, or temporary measurement display.
Summary of usage:
- Obtain temporary graphic drawing objects through
MxCpp. mxcad. getTempDraw(); - Call methods such as' readyMcDbElementsWorldDraw() 'and' setDrawColor() 'to prepare the drawing context;
- Call 'worldDrawMcDbElements()' for temporary drawing, and then use 'endMcDbElementsWorldDraw()' to end the drawing.
Example
//Scenario: After selecting an entity, temporarily bold it and turn it red to display (highlight effect)
import { MxCADUtility, MxCpp } from "mxcad";
async function highlightSelectedEntity() {
// 1. Obtain the entity ID selected by the user
Const retIds=await MxCADUtility. setEnt ("Select bold display object");
if (retIds.length == 0) return;
const ent = retIds[0].getMcDbEntity();
if (!ent) return;
// 2. Get temporary drawing context
const mxcad = MxCpp.getCurrentMxCAD();
const tempDraw = mxcad.getTempDraw();
// 3. Configure drawing style (red, line width 0.60mm)
tempDraw.clearAll(); //Clear old drawings
tempDraw.readyMcDbEntitysWorldDraw(); //Prepare context
tempDraw.setDrawColor(0xFF0000, 0xFF0000); //Set color
tempDraw.setLineWeightDisplay(true, McDb.LineWeight.kLnWt060); //Set line width
// 4. Execute drawing
tempDraw.worldDrawMcDbEntitys(ent as any);
// 5. End drawing context
tempDraw.endMcDbEntitysWorldDraw();
}Note
- The drawn content only exists in the current view frame and may disappear after refreshing or redrawing, requiring a new call.
- It is necessary to call 'readyMcDbElementsWorldDraw' and 'endMcDbElementsWorldDraw' in pairs to ensure the correct release of resources.
Table of contents
Constructors
Methods
- addLines
- addTriangles
- clear
- clearAll
- clearMcDbEntitysDisplay
- disableDepthTestMcDbEntitysDisplay
- endMcDbEntitysWorldDraw
- freeMcDbEntitysDisplay
- readyMcDbEntitysWorldDraw
- setDrawColor
- setDrawOrder
- setLineWeightDisplay
- worldDrawMcDbEntitys
Constructors
constructor
• new McObjectTempDraw(imp)
Constructor function
Parameters
| Name | Type | Description |
|---|---|---|
| Imp | any | Object Implementation |
Methods
addLines
▸ addLines(vecLinePoints): void
Add temporary drawing line data
Parameters
| Name | Type | Description |
|---|---|---|
| VecLinePoints | [McGePoint3dArray] (2d. McGePoint3dArray. md) | Line Point Array |
Returns
void
addTriangles
▸ addTriangles(vecTrianglesPoints): void
Add temporary drawing to fill triangle data
Parameters
| Name | Type | Description |
|---|---|---|
| VecTrianglePoints | [McGePoint3dArray] (2d. McGePoint3dArray. md) | Triangle Point Array |
Returns
void
clear
▸ clear(): void
Clear temporary drawing data
Returns
void
clearAll
▸ clearAll(): void
Clear all temporary drawing content
Returns
void
Description
Remove all temporary graphics drawn through this type on the current view.
clearMcDbEntitysDisplay
▸ clearMcDbEntitysDisplay(): void
Clear temporary data drawn by McDbEntities
Returns
void
disableDepthTestMcDbEntitysDisplay
▸ disableDepthTestMcDbEntitysDisplay(isDisable?): void
Disable temporary rendering of McDbEntities in OpenGL DepthTest
Parameters
| Name | Type | Default value | Description |
|---|---|---|---|
| IsDisable | boolean | true | Whether to disable deep testing, default to true |
Returns
void
endMcDbEntitysWorldDraw
▸ endMcDbEntitysWorldDraw(): void
End the temporary drawing context for McDbEntities and release the resources.
Returns
void
freeMcDbEntitysDisplay
▸ freeMcDbEntitysDisplay(): void
Release the temporary drawing context for McDbEntities.
Returns
void
readyMcDbEntitysWorldDraw
▸ readyMcDbEntitysWorldDraw(): void
Prepare temporary drawing context for McDbEntities.
Returns
void
setDrawColor
▸ setDrawColor(color, iMcDbEntityDrawColor?): void
Set Draw color
Parameters
| Name | Type | Default value | Description |
|---|---|---|---|
| Color | number | undefined | color value |
| IMcDbEntity DrawColor | number | -2 | McDbEntity's drawing color |
Returns
void
setDrawOrder
▸ setDrawOrder(iDrawOrder, iMcDbEntityDrawOrder): void
Set display order
Parameters
| Name | Type | Description |
|---|---|---|
| IDrawOrder | Number | Drawing Order |
| IMcDbEntity DrawOrder | number | Drawing order of McDbEntity |
Returns
void
setLineWeightDisplay
▸ setLineWeightDisplay(val?, iGlobalLineweight?): void
Enable the display of line weights.
Parameters
| Name | Type | Default value | Description |
|---|---|---|---|
| Val | boolean | true | Enable line re display |
| IGlobalLineweight | number | -1 | Global line width, default is -1 to use default line width |
Returns
void
worldDrawMcDbEntitys
▸ worldDrawMcDbEntitys(ent): boolean
Generate temporary drawn data for McDbEntities
Parameters
| Name | Type | Description |
|---|---|---|
| Ent | McDbEntity (2d. McDbEntity. md) | McDbEntity object |
Returns
boolean
