天天看點

CAD繪制固定批注(網頁版)

js中實作代碼說明:

自定義實體繪制函數

function ExplodeFun(pCustomEntity, pWorldDraw, txt) {

    var sGuid = pCustomEntity.Guid;

    if (sGuid == "TestMxCustomEntity") {

        if (!pCustomEntity.IsHave("First"))

            return;

        var stp = pCustomEntity.GetPoint("First");

        var ept = pCustomEntity.GetPoint("BasePoint");

        var dimpt = pCustomEntity.GetPoint("DimPoint");

        var txt = pCustomEntity.GetString("Text");

        var textH = pCustomEntity.GetDouble("TextHeight");

        var edgeNum = pCustomEntity.GetLong("EdgeNumber");

        var shapRadius = pCustomEntity.GetDouble("ShapRadius");

        var isCircle = pCustomEntity.GetLong("isCircle");

        // 建立一個批注對象.

        var comment = mxOcx.NewEntity("IMxDrawComment");

        //标注文字

        comment.Text = txt;

        //标注文字高度

        comment.TextHeight = textH;

        //标注位置提示多邊形的邊數. 小于2不繪制,=2繪制圓,大于2繪制多邊形

        comment.EdgeNumber = edgeNum;

        //标注位置提示多邊形的半徑

        comment.ShapRadius = shapRadius;

        //标注基點

        comment.basePoint = ept;

        //标注位置點

        comment.Position = dimpt;

        // 設定文字樣式

        pWorldDraw.TextStyle = "MyCommentFont";

        // 動态繪制.

        pWorldDraw.DrawEntity(comment);

 

        if (isCircle) {

            var dR = stp.DistanceTo(ept) * 0.5;

            var vec = stp.SumVector(ept);

            vec.Mult(0.5);

            ept.Add(vec);

            //繪制一個圓

            //參數一為圓的中心X值 ,參數二為圓的中心Y值,

            //參數三為半徑

            pWorldDraw.DrawCircle(ept.x, ept.y, dR);

        }

        // 繪制矩形框.

        else {

            //繪制一個直線

            //參數一直線的開始點x坐标,參數二直線的開始點y坐标,參數三直線的結束點x坐标,參數四直線的結束點y坐标

            pWorldDraw.DrawLine(stp.x, stp.y, stp.x, ept.y);

            pWorldDraw.DrawLine(stp.x, ept.y, ept.x, ept.y);

            pWorldDraw.DrawLine(ept.x, ept.y, ept.x, stp.y);

            pWorldDraw.DrawLine(ept.x, stp.y, stp.x, stp.y);

        }

        mxOcx.SetEventRet(1);

    }

}
      

傳回自定義實體夾點

function GetGripPointsFun(pCustomEntity) {

    var sGuid = pCustomEntity.Guid;

    if (sGuid == "TestMxCustomEntity") {

        if (!pCustomEntity.IsHave("First"))

            return;

        var stp = pCustomEntity.GetPoint("First");

        var ept = pCustomEntity.GetPoint("BasePoint");

        var dimpt = pCustomEntity.GetPoint("DimPoint");

        var ret = mxOcx.NewResbuf();

        ret.AddPoint(stp);

        ret.AddPoint(ept);

        ret.AddPoint(dimpt);

        mxOcx.SetEventRetEx(ret);

    }

}
      

移動自定義實體夾點

function MoveGripPointsFun(pCustomEntity, lGridIndex, dOffsetX, dOffsetY) {

 

    var sGuid = pCustomEntity.Guid;

    if (sGuid == "TestMxCustomEntity") {

        if (!pCustomEntity.IsHave("First"))

            return;

        var stp = pCustomEntity.GetPoint("First");

        var ept = pCustomEntity.GetPoint("BasePoint");

        var dimpt = pCustomEntity.GetPoint("DimPoint");

        if (lGridIndex == 0) {

            stp.x = stp.x + dOffsetX;

            stp.y = stp.y + dOffsetY;

            pCustomEntity.SetPoint("First", stp);

        }

        else if (lGridIndex == 1)

        {

            ept.x = ept.x + dOffsetX;

            ept.y = ept.y + dOffsetY;

            pCustomEntity.SetPoint("BasePoint", ept);

        }

        else

        {

            dimpt.x = dimpt.x + dOffsetX;

            dimpt.y = dimpt.y + dOffsetY;

            pCustomEntity.SetPoint("DimPoint", dimpt);

        }

        mxOcx.SetEventRet(1);

    }

}
      

固定參數繪批注

function DoCommentFix() {

    var comment = mxOcx.NewEntity("IMxDrawComment");

    comment.Text = "固定參數繪批注";

    comment.TextHeight = 10;

    var basepos = mxOcx.NewPoint();

    basepos.x = 0;

    basepos.y = 10;

    var pos = mxOcx.NewPoint();

    pos.x = 20;

    pos.y = 30;

    //基點

    comment.BasePoint = basepos;

    //位置

    comment.Position = pos;

    var comobj = mxOcx.ObjectIdToObject( mxOcx.DrawEntity(comment) );

    comobj.TextStyle = "MyCommentFont";

    mxOcx.ZoomAll();

}

      

繼續閱讀