Skip to content
On this page

Offset

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

Function implementation

  1. Select the target entity

We can call MxCADResbuf set filters, Then use the MxCADUiPrEntity Filters out the objects to be migrated.

ts
// Obtain the offset object Obtain the offset object
let filter = new MxCADResbuf();
filter.AddMcDbEntityTypes("CIRCLE,ARC,LINE,LWPOLYLINE,ELLIPSE");
let getEvent = new MxCADUiPrEntity();
getEvent.setFilter(filter);
getEvent.setMessage(' Specify offset object ');
let event_id = await getEvent.go();
if (! event_id) return;
// Set entity highlighting
let event = (await event_id.getMcDbEntity()) as McDbCurve;
event.highlight(true);
  1. Set the offset distance

We by calling MxCADUiPrDist according to the users to set two points determine the offset distance.

ts
//Get offset distance
const getOffDist = new MxCADUiPrDist();
getOffDist.setMessage('Please enter the offset distance');
const distVal = await getOffDist.go();
if (!distVal) return;
const offDist = getOffDist.value();
  1. Specify the offset direction

In the above step, we obtained the rotation Angle, so, We can direct call McDbCurve.offsetCurves() Method to rotate the object. After moving, Call McObject.updateDisplay() method to update the drawing shows.

ts
// Specify offset direction
const getPoint = new MxCADUiPrPoint();
getPoint.setMessage('Please specify the offset direction');
// Draw dynamic effects
getPoint.setUserDraw((pt, pw) => {
    let objArr = event.offsetCurves(offDist, pt);
    if (objArr.length() === 0) return;
    objArr.forEach((obj: McDbObject) => {
        pw.drawMcDbEntity(obj as McDbEntity);
    });
})
const pt = await getPoint.go();
if (!pt) return;
// Offset entity
event.offsetCurves(offDist, pt).forEach((obj: McDbObject) => {
    if(obj) mxcad.drawEntity(obj as McDbEntity);
});
event.highlight(false);
mxcad.updateDisplay();

Functional practice

Practical effects are as follows:

  • Click the Offset button to perform the offset method
  • Left click to select the target entity
  • Click the left button and drag the mouse to set the offset distance according to the command line prompt
  • Move the mouse and click the left button again to set the offset distance (or enter the offset value directly in the input box and press Enter)
  • Move the mouse to specify the entity offset direction
  • Click the left mouse button to determine the entity offset direction and successfully offset the object