计算不同草图中点之间的距离 SolidWorks API

Calculate distance between points in differents sketches SolidWorks API


大约一个半月以来,我一直在为应用程序 SolidWorks 编写脚本,我想改进它,因为它非常慢。

我的脚本做了什么:
1. 它告诉用户 select 一些特定的组件(使用高级 Select)。
2. 我用这些组件制作了一个集合。
3. 我从这些集合中制作了一个集合,因为我需要根据它们的配置对它们进行重新组合。
4. 在每个组件中都有一个带有单个 sketchPoint 的草图。我必须计算此点与 3D 草图中预​​定点的原点之间的距离。所以我将组件上的 sketchPoint 附加到我的 3Dsketch 中,我计算,然后删除它。
5. 我对每个组件都这样做 (60++)

最耗时的部分是我必须编辑我的 3DSketch,将一个点放入其中,关闭版本,计算距离,编辑,删除,再次关闭。

我目前正在做一个更面向对象的方法,所以不再收集收集,但我的问题仍然存在。我想知道 IMath 是否有用,因为我看到了这个:http://help.solidworks.com/2014/english/api/sldworksapi/Transform_Sketch_to_Model_Example_VB.htm
但它似乎工作正常。

啊,我知道测量工具,但它不会工作,因为如果我的 sketchPoint 是 "behind" 我的原点,我需要负值。

谢谢:)

嗯,我在 SolidWorks 论坛上问过同样的问题,有人给了我答案,这里是:

Dim myComp As Component2
Dim fSketch As Feature
Dim swSketch As Sketch
Dim vSketchPts As Variant
Dim swSketchPt As SketchPoint
Dim p(2) as Double
Dim mPt as MathPoint
Dim vPt as Variant
Dim myUtil as Mathutility

Set myUtil = swApp.GetMathUtility
Set fSketch = myComp.FeatureByName("mySketchName")
Set swSketch = fSketch.GetSpecificFeature2
vSketchPts = swSketch.GetSketchPoints2
Set swSketchPt = vSketchPts(0)

p(0)=swSketchPt.X
p(1)=swSketchPt.Y
p(2)=0.0
vPt = p
Set mPt = myUtil.CreatePoint(vPt)


Dim mthTrans As MathTransform

Set mthTrans = swSketch.ModelToSketchTransform
Set mPt= mPt.MultiplyTransform(mthTrans.Inverse)
Set mthTrans = swIRBoxComp.Transform2
Set mPt= mPt.MultiplyTransform(mthTrans)
vPt = mPt.ArrayData ' This will contain the XYZ coordinates of the point in the coordinate system of the 3D sketch

所有学分归西蒙·特纳所有https://forum.solidworks.com/people/1-KQHM1