Skip to content
On this page

Interrupt

Below we will show how to use the mxcad plug-in to implement the curve breaking function in CAD drawings. In this function, users can cut a complete curve into two or more parts by breaking points, and these cut parts will become independent curves. Among them, curve-like entities in mxcad include: McDbPolyline Section of the line, McDbArc Circular arc, McDbCircle Round, McDbEllipse Oval/arc, McDbLine in a straight line. The interrupt function can help users to measure, delete and adjust the length of the target curve in the drawing efficiently.

Function implementation

  1. Select the target curve

We can set the filter by MxCADResbuf, Call again MxCADUiPrEntity for the user to select entity, Will filter the user can choose only McDbCurve curve type of entity is convenient we interrupted by subsequent operations. To make it easier for us to visualize which entity is selected, We can be the selected entities through McDbCurve.highlight() methods to set is highlighted.

ts
// Select the curve you want to break
const getCurve = new MxCADUiPrEntity();
getCurve.setMessage('Please select a curve that you want to break');
// Set filter
const filter = new MxCADResbuf([DxfCode.kEntityType, "LWPOLYLINE,LINE,ARC,CIRCLE,ELLIPSE"]);
getCurve.setFilter(filter);
const curveId = await getCurve.go();
if(!curveId.id) return;
const curve = curveId.getMcDbEntity() as McDbCurve;
// Set curve highlighting
curve.highlight(true);
  1. Set break points

We can MxCADUiPrPoint in the above steps on the target curve take operation, These selected points are the breakpoints of the target curve. During the drawing process, we can dynamically draw a circle with the breakpoint as the center of the circle to facilitate us to observe the specific location of the breakpoint.

ts
// Select the break point of the curve
const getBreakPoint = new MxCADUiPrPoint();
getBreakPoint.setMessage('Please select the break point on the curve');
const pointsArr:McGePoint3d[] = [];
const radius = MxFun.screenCoordLong2Doc(5)
while(true){
    // Dynamically draw break points
    getBreakPoint.setUserDraw((pt,pw)=>{
        if(pointsArr.length > 0){
        pointsArr.forEach(pt=>{
            const circle = new McDbCircle();
            circle.center = pt;
            circle.radius = radius;
            pw.drawMcDbEntity(circle)
        })
        };
        pw.drawCircle(new THREE.Vector3(pt.x,pt.y), radius)
    })
    const point = await getBreakPoint.go();
    if(!point) break;
    pointsArr.push(point);
}
  1. Break curves

After completing the above steps, We will target curve according to these breakpoints calls McDbCurve.splitCurves() Method March line cutting, and then we can get the interrupted curve.

ts
// Interrupted curve
const mxcad = MxCpp.getCurrentMxCAD();
if(pointsArr.length === 0) return;
curve.splitCurves(pointsArr).forEach(obj=>{
    mxcad.drawEntity(obj as McDbCurve)
});
curve.highlight(false);
curveId.erase();
mxcad.updateDisplay();

Function extension

  1. To achieve the intersection interrupt function

We can call McDbCurve.IntersectWith() Methods The intersections between curves are obtained, and these intersections are used as the breaking points of curves to break curves. In the following example, we use the intersection points between curves as breakpoints to cut the curve and draw a certain length of the fracture for easy observation. Users can make corresponding adjustments according to their actual needs.

ts
// Intersection break
async function Mx_IntersectBreak() {
    // Selective reference curve
    let eventObj = new MxCADUiPrEntity();
    eventObj.setMessage("Please select a reference curve");
    let eventObj_id = await eventObj.go();
    let event = await eventObj_id.getMcDbEntity()//Get instance object
    if (event === null) return;
    const mxcad = MxCpp.App.getCurrentMxCAD();
    let curve = event.clone();
    let filter = new MxCADResbuf();
    filter.AddMcDbEntityTypes("CIRCLE,ARC,LINE,LWPOLYLINE,ELLIPSE");
    let aryId = await MxCADUtility.userSelect("Select interrupt object", filter);//Select the id of the object
    if (aryId.length == 0) return;
    let dTol = mxcad.mxdraw.viewCoordLong2Cad(0.5);// Set precision value
    aryId.forEach(async (id) => {
        if (id.id !== eventObj_id.id) {
            let breakEvent: McDbCurve = (await id.getMcDbEntity()) as McDbCurve;
            let breakArr = breakEvent.IntersectWith(curve as McDbEntity, McDb.Intersect.kOnBothOperands);//A collection of points intersecting an entity
            if (breakArr.length() != 0) {
                //Objects with intersecting points
                let arr: McGePoint3d[] = [];//Intersection array
                breakArr.forEach((item: McGePoint3d) => {
                    arr.push(item)
                })
                let breakPoint: McGePoint3d[] = [];
                arr.forEach(pt => {
                    let closePoint = breakEvent.getClosestPointTo(pt, false);//The point on the curve closest to the mouse position
                    if (!closePoint.ret) return;
                    let vec = breakEvent.getFirstDeriv(closePoint.val);//The vector where the breakpoint is located
                    if (!vec.ret) return;
                    vec.val.normalize().mult(MxFun.viewCoordLong2Cad(10));//Break distance
                    let pt1 = closePoint.val.clone();
                    pt1.addvec(vec.val);
                    let pt2 = closePoint.val.clone();
                    pt2.subvec(vec.val);
                    // If the curve ends intersect, special treatment is required
                    const startPt = breakEvent.getPointAtDist(0).val;
                    const endPt = breakEvent.getPointAtDist(breakEvent.getLength().val).val;
                    if (startPt.distanceTo(closePoint.val) < dTol || endPt.distanceTo(closePoint.val) < dTol) {
                        const num = breakEvent.getDistAtPoint(pt1);
                        breakPoint.push(closePoint.val)
                        num.ret ? breakPoint.push(pt1) : breakPoint.push(pt2);
                    } else {
                        breakPoint.push(pt1);
                        breakPoint.push(pt2);
                    }
                });
                let breakcurve = breakEvent.splitCurves(breakPoint);
                if (breakcurve.empty()) {
                    breakEvent.highlight(false);
                    return;
                }
                breakcurve.forEach((obj: McDbObject, index: number) => {
                    if (index % 2 == 0) mxcad.drawEntity(obj as McDbEntity);
                });
                breakEvent.erase()
            }
        }
    })
}

Functional practice

Practical effects are as follows:

Step 1 Interrupt

  • Click the Interrupt button to execute the interrupt method
  • Left click to select the target curve in the drawing
  • Left click again to select the break point (loopable point) in the target curve, and right click to end the point
  • Successfully interrupted the target curve
  • Select the target curve again in the drawing, the target curve has been broken into multiple curves
  1. Internode interruptions
  • Click the intersection Break button to execute the intersection break method
  • Left click to select the reference curve in the drawing (i.e. the curve that will not be interrupted)
  • After selecting the reference curve, left-click again to select the curve that needs to be interrupted (multiple curves can be selected consecutively)
  • Right-click to end the selection and successfully break the curve according to the intersection of the curve