Skip to content
On this page

Move

Below we will show how to use the mxcad plug-in to achieve the movement function in the CAD drawing. In this function, the user can select or click the target entity to move it, which is used to edit the position of the entity in the drawing. In our document Common Editing operations has made a basic explanation of mobile operations, the following we will achieve mobile functions 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 move.

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

We by calling MxCADUiPrPoint take the object to determine the basis of moving objects and mobile location. During the setup process, We can go through MxCADUiPrPoint.setUserDraw() Dynamically draw the translation object.

ts
// Designated moving base point
let getPoint = new MxCADUiPrPoint();
getPoint.setMessage("\指定基点");
getPoint.clearLastInputPoint();
let ptBase = await getPoint.go();// Fetch point
if (!ptBase) return;

// Specify the move final position
getPoint.setMessage("Specify the point to move to");
getPoint.setBasePt(ptBase);
getPoint.setUseBasePt(true);

// Dynamically draw entity movements
getPoint.setUserDraw((pt, pw) => {
    ss.forEach(id=>{
        let tmp: McDbEntity = id.clone() as McDbEntity;
        tmp.move((ptBase as any), pt);
        pw.drawMcDbEntity(tmp);
    })
});

let ptMoveTo = await getPoint.go(); // Fetch point
if (!ptMoveTo) return;
  1. Move the entity

In the above step, we get the moving base point and the position after the move, so, We can direct call McDbEntity.move() approach to moving objects. After moving, Call McObject.updateDisplay() method to update the drawing shows.

ts
// Mobile entity
ss.forEach(id=>{
    let tmp: McDbEntity = id.getMcDbObject() as McDbEntity;
    tmp.move((ptBase as any), ptMoveTo);
});
// Update display
MxCpp.getCurrentMxCAD().updateDisplay();

Functional practice

Practical effects are as follows:

  • Click the Move button to execute the move method
  • Left click to select the target entity, right click to end the selection (or direct box selection)
  • Follow the command line prompt and left click to set the move base point
  • Move the mouse to place the entity at the target location
  • Right-click to determine the entity moving position, successfully move the entity