SolidWorks二次开发 API-增加指示标记

大家应该经常会用到solidworks的测量功能。
比如测量一个边的长度(当前正常选中之后 ,右下角就会显示长度,不必测量,所以不要抬杠哈):
在这里插入图片描述
我们今天要讲到的就是上面的这标记,显示了长度: 300mm

在solidworks里面它是叫Callout
Allows add-in applications to manipulate single and multi-row callouts.
它显示是需要插件上用的。但是exe上也是可以出来的。
具体的大家可以在API帮助中查找对应的信息,而且也有相关的例子。我这就不多讲了。
在这里插入图片描述

上代码:

private void btnAddCallout_Click(object sender, EventArgs e)
        {
            var swApp = PStandAlone.GetSolidWorks();

            var colortable = (ColorTable)swApp.GetColorTable();
           

            ModelDoc2 swModel;
            ModelDocExtension swExt;
            SelectionMgr swSelMgr;
            MathUtility mathUtil;

            swModel = (ModelDoc2)swApp.ActiveDoc;
            swExt = swModel.Extension;
            swSelMgr = (SelectionMgr)swModel.SelectionManager;

            var mousePoint = (double[])swSelMgr.GetSelectionPoint2(1, -1);

            mathUtil = (MathUtility)swApp.GetMathUtility();
            calloutHandler handle = new calloutHandler();
            MathPoint mp;
            double[] vPnt = new double[3];
            vPnt[0] = 0.0;
            vPnt[1] = 0.0;
            vPnt[2] = 0.0;
            mp = (MathPoint)mathUtil.CreatePoint(mousePoint);
            Callout myCallout;
            myCallout = swExt.CreateCallout(2, handle);
            myCallout.set_Value(1, "-");
            myCallout.set_IgnoreValue(1, true);
            myCallout.set_Label2(1, "SldWorks API");
            //myCallout.SkipColon = true;
            //myCallout.TextColor[0] = t.GetColorRefAtIndex(0);  这里的颜色颜色好像没有测试出来。
            //myCallout.OpaqueColor = t.GetColorRefAtIndex(1);

            myCallout.SetLeader(true, false);
            myCallout.SetTargetPoint(0, mousePoint[0], mousePoint[1], mousePoint[2]);
            //myCallout.SetTargetPoint(2, -0.001, 0.001, 0);
            myCallout.Position = mp;
            myCallout.set_ValueInactive(0, true);
            myCallout.TextBox = false;
            myCallout.Display(true);

            TextFormat swTextFormat = myCallout.TextFormat;
            ProcessTextFormat(swApp, swModel, swTextFormat);



        }
        public void ProcessTextFormat(SldWorks swApp, ModelDoc2 swModel, TextFormat swTextFormat)
        {

            Debug.Print("    BackWards                    = " + swTextFormat.BackWards);
            Debug.Print("    Bold                         = " + swTextFormat.Bold);
            Debug.Print("    CharHeight                   = " + swTextFormat.CharHeight);
            Debug.Print("    CharHeightInPts              = " + swTextFormat.CharHeightInPts);
            Debug.Print("    CharSpacingFactor            = " + swTextFormat.CharSpacingFactor);
            Debug.Print("    Escapement                   = " + swTextFormat.Escapement);
            Debug.Print("    IsHeightSpecifiedInPts       = " + swTextFormat.IsHeightSpecifiedInPts());
            Debug.Print("    Italic                       = " + swTextFormat.Italic);
            Debug.Print("    LineLength                   = " + swTextFormat.LineLength);
            Debug.Print("    LineSpacing                  = " + swTextFormat.LineSpacing);
            Debug.Print("    ObliqueAngle                 = " + swTextFormat.ObliqueAngle);
            Debug.Print("    Strikeout                    = " + swTextFormat.Strikeout);
            Debug.Print("    TypeFaceName                 = " + swTextFormat.TypeFaceName);
            Debug.Print("    Underline                    = " + swTextFormat.Underline);
            Debug.Print("    UpsideDown                   = " + swTextFormat.UpsideDown);
            Debug.Print("    Vertical                     = " + swTextFormat.Vertical);
            Debug.Print("    WidthFactor                  = " + swTextFormat.WidthFactor);

            Debug.Print("");

        }

如果 就是这样了哈
在这里插入图片描述

  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 5
    评论
评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Paine Zeng

如果对有帮助,请我喝咖啡吧

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值