Skip to content
On this page

Command line

The command line in CAD can be used to display input parameters, commands and other information, similar to the record of the operation process. It allows us to clearly understand the steps of the operation and helps to check the correctness of the operation. mxcad does not provide a direct implementation of the command line method, but you can rely on mxdraw library command function to achieve the following main functions of the command line:

  1. Shortcut command: By entering the target command on the command line, users can quickly draw or run other commands.

  2. Record the operation process: The command line can record the information about the operations performed by the user to help the user recall the previous operations.

  3. Data interaction: The command line can pass the user's input to the internal program of the software, and give the corresponding feedback according to the command execution state.

  4. Step prompt: The command line can provide the user with step prompt, so that the user can complete the drawing more efficiently.

UI interface construction

The most basic interface construction of the command line depends on the canvas canvas, input input box, and textarea text box. The canvas is used to display drawings, the input input box is used to listen to commands entered by users, and the textarea text box is used to display historical operation information, step prompts, and command feedback.

html
<div style="height: 80vh; overflow: hidden;">
    <canvas id="myCanvas"></canvas>
</div>
<div style="width: 100%;height: 12vh;">
    <textarea id="myArea" style="width: 100%;height: 8vh;background-color: #000;color: #fff;border-radius: 5px" readonly="true"></textarea>
    <input id="myInput" style="width:100%;height: 2vh;background-color: #000;color: #fff;" />
</div>

Monitor, register command

Once you've built the basic command line UI, you need to listen to user input, At the same time call MxFun setCommandLineInputData() method to set the command line message data; Call MxFun listenForCommandLineInput() method to listen for dynamically updated data from command line messages, the commands set in the fetch point object and the graphic objects we provide are a set of command prompts and parametric plots.

ts
import { MxFun } from "mxdraw"

const inputBox = document.getElementById("myInput")
const cmdWindow = document.getElementById("myArea")

// Listen for command line input
let inputText = ""
inputBox.oninput = () => {
    inputText = inputBox.value
}
inputBox.onkeydown = (e) => {
    MxFun.setCommandLineInputData(inputText, e.keyCode)
    if (e.keyCode === 13) inputText = inputBox.value = ""
}

// Command message changes are displayed
MxFun.listenForCommandLineInput(({
    msCmdTip,
    msCmdDisplay,
    msCmdText
}) => {
    inputText = msCmdText
    cmdWindow.value = msCmdDisplay + "\n" + msCmdTip
    cmdWindow.scrollTop = cmdWindow.scrollHeight
})

Registered command need to rely on mxdraw libraries provide MxFun. AddCommand(). The following takes the registration line drawing command as an example:

ts
import { MxFun } from "mxdraw"

// Registration command
MxFun.addCommand("Mx_Pline", async () => {
    let getFristPoint = new MxCADUiPrPoint();
    getFristPoint.setMessage("Please click OK starting point");
    let fristPoint: any = await getFristPoint.go();
    if (!fristPoint) return
    let getSecondPoint = new MxCADUiPrPoint();
    getSecondPoint.setMessage("Please click OK Destination");
    getSecondPoint.setUserDraw((pt, pw) => {
        let line = new McDbLine(fristPoint.x, fristPoint.y, fristPoint.z, pt.x, pt.y, pt.z);
        pw.drawMcDbEntity(line)
    })
    let secondPoint: any = await getSecondPoint.go();
    if (!secondPoint) return
    let line = new McDbLine(fristPoint.x, fristPoint.y, fristPoint.z, secondPoint.x, secondPoint.y, secondPoint.z);
    let mxcad = MxCpp.App.getCurrentMxCAD();
    mxcad.drawEntity(line)
});

Execute the command

Manual command execution relies on the mxdraw library Provided in the MxFun sendStringToExecute().

ts
import { MxFun } from "mxdraw"

MxFun.sendStringToExecute("Mx_Line");

Demo

The full effect demonstration is as follows:

  • On the CLI, enter the Mx_Pline command and press Enter to execute the command

  • Then draw a straight line according to the prompt steps output from the command line