CAD交互绘制批注(网页版)

js中实现代码说明:

动态拖放时的绘制事件:

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

function DynWorldDrawComment( pCustomEntity, pWorldDraw, curPt) {

    // 得到绘制参数.

 

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

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

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

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

    // 创建一个批注对象.

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

    comment.Text = sText;

    comment.TextHeight = dTextHeight;

    comment.EdgeNumber = iEdgeNumber;

    comment.ShapRadius = dShapRadius;

    comment.basePoint = curPt;

    comment.Position = curPt;

    pWorldDraw.TextStyle = "MyCommentFont";

    // 动态绘制.

    pWorldDraw.DrawEntity(comment);

}

动态绘制文字:

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

function  DynWorldDrawComment2( pCustomEntity,pWorldDraw,  curPt) {

    // 得到绘制参数.

 

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

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

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

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

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

    // 创建一个批注对象.

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

    comment.Text        = sText;

    comment.TextHeight  = dTextHeight;

    comment.EdgeNumber  = iEdgeNumber;

    comment.ShapRadius  = dShapRadius;

    comment.basePoint   = basePoint;

    comment.Position = curPt;

    // 设置文字样式。

    pWorldDraw.TextStyle = "MyCommentFont";

    // 动态绘制.

    pWorldDraw.DrawEntity(comment);

}

动态绘制文字:

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

function DoComment() {

    // 出来一个对象,让用户输入文字.

    var winWidth = 440;

    var winHeight = 140;

    var winLeft = (screen.width - winWidth) / 2;

    var winTop = (screen.height - winHeight) / 2 - 20;

    var str = 'dialogHeight:' + winHeight + 'px;dialogWidth:' + winWidth + 'px;dialogTop:' + winTop + 'px;dialogLeft:' + winLeft + 'px;resizable:yes;center:yes;status:no;'

    var rt = window.showModalDialog("Gettext.htm?tmp=" + Math.random(), "输入文字", str);

    var txt;

    if (typeof (rt) == "undefined") {

        return;

    else {

        var arr = rt.split(",");

        txt = arr[0];

    }

    // 加入换行操作符\\P

    //txt = txt + "\\PTEST";

    // 创建一个文字样式,用于批注文字字体.

    mxOcx.AddTextStyle2("MyCommentFont","黑体",0.7);

    // 创建一个与用户交互取点的对象。

    var getPt = mxOcx.NewComObject("IMxDrawUiPrPoint");

    getPt.message = "输入标注插入基点";

    // 开始取第一个点。

    if (getPt.go() != 1)

        return;

    // 创建一个与用户交互取点的对象。

    var getSecondPt = mxOcx.NewComObject("IMxDrawUiPrPoint");

    getSecondPt.message = "输入标注位置点";

    getSecondPt.basePoint = getPt.value();

    getSecondPt.setUseBasePt(false);

    spDrawData = getSecondPt.InitUserDraw("DrawComment2");

    // 设置动态绘制参数.

    spDrawData.SetPoint("BasePoint", getPt.value());

    spDrawData.SetString("Text", txt);

    spDrawData.SetDouble("TextHeight", 100);

    spDrawData.SetLong("EdgeNumber", 0);

    spDrawData.SetDouble("ShapRadius", 300);

    // 开始取第二个点。

    if (getSecondPt.go() != 1)

        return;

    var ret = spDrawData.Draw();

    // 设置绘制的批注文字样式。

    for (var i = 0; i < ret.Count; i++)

    {

        var ent = ret.AtObject(i);

        ent.TextStyle = "MyCommentFont";

        ent.colorIndex = 4;

    }

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值