Skip to content
On this page

Specify range output dwg

Below we will show you how to use the mxcad plug-in to output dwg functionality at a specified range in a CAD drawing. In this function, the user can choose the drawing scope and export the drawing file in dwg format. The specified range output dwg function can achieve efficient file compression, help users to accurately extract the design information of drawings, is a very practical drawing cutting function.

Function implementation

  1. Specify the scope

We can call MxCADUiPrPoint Method Obtain the scope for exporting dwg drawings.

ts
// Select export range.
let getPoint = new MxCADUiPrPoint();
getPoint.setMessage("\n Specifies the first point of the output range:");
// Gets the first corner of the range
let pt1 = await getPoint.go();
if (!pt1) return;

getPoint.setMessage("\n Specifies the second point of the output range:");
// Set the selection range dynamic fill style
getPoint.setUserDraw((currentPoint: McGePoint3d, worldDraw) => {
    // Set range box color as position
    worldDraw.setColor(0xFF0000);
    let pl = new McDbPolyline();
    pl.addVertexAt(pt1);
    pl.addVertexAt(new McGePoint3d(pt1.x, currentPoint.y))
    pl.addVertexAt(currentPoint);
    pl.addVertexAt(new McGePoint3d(currentPoint.x, pt1.y))
    pl.constantWidth = MxFun.screenCoordLong2Doc(2);
    pl.isClosed = true;
    worldDraw.drawMcDbEntity(pl);
    // Sets the fill style in the range box
    let points = [];
    points.push(pt1.toVector3());
    points.push(new McGePoint3d(pt1.x, currentPoint.y).toVector3());
    points.push(currentPoint.toVector3());
    points.push(new McGePoint3d(currentPoint.x, pt1.y).toVector3())
    worldDraw.setColor(0x003244);
    worldDraw.drawSolid(points, 0.5)

});
// Set disable capture and ortho tracking
getPoint.setDisableOsnap(true);
getPoint.setDisableOrthoTrace(true);
// Gets the second corner of the range
let pt2 = await getPoint.go();
if (!pt2) return;
  1. Export the pdf

In the above steps we have obtained the scope of the pdf on the drawing, So we can direct call McObject.saveFileToUrl() Method to export target pdf. If you do not set the scope for exporting drawings, all drawings are exported by default.

ts
// Range parameter setting
let param = {
    bd_pt1_x: "" + pt1.x,
    bd_pt1_y: "" + pt1.y,
    bd_pt2_x: "" + pt2.x,
    bd_pt2_y: "" + pt2.y
};

// Save the mxweb file to the server and convert it to dwg.
// cutDwgUrl: back-end request interface
MxCpp.getCurrentMxCAD().saveFileToUrl(cutDwgUrl, (iResult: number, sserverResult: string) => {
    try {
    let ret = JSON.parse(sserverResult);
    if (ret.ret == "ok") {
        // filePath:The URL for downloading the file
        MxTools.downloadFileFromUrl(filePath, ret.file);
    }
    else {
        console.log(sserverResult);
    }
    } catch {
    console.log("Mx: sserverResult error");
    }
}, undefined, JSON.stringify(param));

TIP

Attention: Will drawing according to the specified range output DWG must call node. Js back-end services, therefore, please call the above method before starting development kit cloud services in the background. If you are not sure how to start the service with Cloud Mapping Kit, please refer to Getting Started with Cloud Mapping Kit

Functional practice

Practical effects are as follows:

  • Click the Export jpg button to perform the Export jpg method
  • Click the left mouse button to select the export range according to the command line prompt
  • Click the left mouse button again to end the box selection
  • Successfully exported the contents of the target range of drawings to jpg format