Arc and Ellipse in MxDraw

5/5/2022

# Draw an arc using three points in MxDraw (Mx3PointArc)

Click Mx.Mx3PointArc API (opens new window) for detailed properties and method descriptions.

import Mx from "mxdraw"

// Create a dynamic point object
const point = new Mx.MrxDbgUiPrPoint()
const arc = new Mx.Mx3PointArc()

point.setMessage("\nSpecify the start point of the arc:");
point.go(async (status)=> {
    if(status === Mx.MrxDbgUiPrBaseReturn.kOk) {
        arc.point1 = point.value()
        
        // Set the dynamic drawing function
        point.setUserDraw((currentPoint, worldDraw)=> {
            worldDraw.drawLine(arc.point1, currentPoint)
        })
        point.setMessage("\nSpecify the end point of the arc:");
        // Synchronously get the position of the next mouse click
        arc.point2 = await point.go()
        
        point.setUserDraw((currentPoint, worldDraw)=> {
            arc.point3 = currentPoint
            worldDraw.drawCustomEntity(arc)
        })
        point.setMessage("\nSpecify any other point on the arc:");
        arc.point3 = await point.go()
        const mxDraw = Mx.MxFun.getCurrentDraw()
        mxDraw.addMxEntity(arc)
    }
})

Note:

Effect:

# Draw an ellipse using MxDbEllipse

Click Mx.MxDbEllipse API (opens new window) for detailed properties and method descriptions.

const point = new Mx.MrxDbgUiPrPoint()
const ellipse = new Mx.MxDbEllipse()

point.go(async (status)=> {
    if(status === Mx.MrxDbgUiPrBaseReturn.kOk) {
        ellipse.point1 = point.value()
        
        point.setUserDraw((currentPoint, worldDraw)=> {
            ellipse.point2 = currentPoint
            worldDraw.drawCustomEntity(ellipse)
        })
    }
    // Get the position of the next mouse click
    ellipse.point2 = await point.go()
    const mxDraw = Mx.MxFun.getCurrentDraw()
    mxDraw.addMxEntity(ellipse)
})