Skip to content
On this page

Mirror image

Below we will introduce how to use the mxcad plug-in to implement the mirroring function in CAD drawings. In this function, the user can select or click the target entity to mirror it for editing the content of the drawing. In our document Common Editing operations has done a basic explanation of the mirror operation, the following we will achieve the mirror function that can interact with users on this basis.

Function implementation

  1. Select the target entity

We can call MxCADSelectionSet Select the entity that you want to mirror.

ts
// Select the object you want to mirror
let ss = new MxCADSelectionSet();
if (!await ss.userSelect("\n Select Move objects")) return;
  1. Set the mirror guide

We by calling MxCADUiPrPoint take the object to determine the image reference line start and end points. During the setup process, We can go through MxCADUiPrPoint.setUserDraw() Dynamically drawing the image object enables us to see the position of the object after the image rotation more intuitively.

ts
// Gets the start and end points of the mirror guide
const getStartPt = new MxCADUiPrPoint();
getStartPt.setMessage('Specify the first point of the mirrored line');
// Fetch point
const startPt = await getStartPt.go();
if (!startPt) return;
const getEndPt = new MxCADUiPrPoint();
getEndPt.setMessage('Specify the second point of the mirrored line');
// // Dynamically draw image guides and image objects
getEndPt.setUserDraw((pt, pw) => {
    const line = new McDbLine(startPt, pt);
    pw.drawMcDbEntity(line);
    ss.forEach((objId: McObjectId) => {
        const ent = objId.getMcDbEntity().clone() as McDbEntity;
        ent.mirror(startPt, pt);
        pw.drawMcDbEntity(ent)
    });
})
// Fetch point
const endPt = await getEndPt.go();
if (!endPt) return;
  1. Mirror the rotated object

In the above step, we get the start and end points of the mirror guides, so, We can direct call McDbEntity.mirror() method to image rotation object. After moving, Call McObject.updateDisplay() method to update the drawing shows.

ts
const mxcad = MxCpp.getCurrentMxCAD();
// Mirror image rotating entity
ss.forEach((objId: McObjectId) => {
    const ent = objId.getMcDbEntity().clone() as McDbEntity;
    ent.mirror(startPt, endPt);
    mxcad.drawEntity(ent)
});
// Update display
mxcad.updateDisplay();

Functional practice

Practical effects are as follows:

  • Click the Mirror button to perform the mirror method
  • Left click to select the target entity, right click to end the selection (or direct box selection)
  • Follow the command line prompts by left-clicking to set the mirror guide starting point
  • Left click again to set the mirror guide end point
  • The object after successfully drawing the image