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("");
}
如果 就是这样了哈
posted @
2022-11-30 18:30
painezeng 阅读(
0) 评论(
0)
编辑
收藏
举报
来源