SolidWorks API:测量点坐标

发布于 2025-02-09 04:46:39 字数 919 浏览 1 评论 0 原文

有一个SolidWorks组件,其中包含一个“ P”和一个坐标系框架“ F”。目的是找到 X,Y,Z codleds“ p” wrt框架“ f”的坐标。 VB代码看起来像

Sub main()
    Dim swApp As SldWorks.SldWorks
    Dim swModel As SldWorks.ModelDoc2
    Dim bstatus As Boolean
    Dim swMeasure As SldWorks.Measure
    
    Set swApp = Application.SldWorks
    Set swModel = swApp.ActiveDoc

    swModel.ClearSelection2 True
    bstatus = swModel.Extension.SelectByID2("P", "DATUMPOINT", 0, 0, 0, False, 0, Nothing, 0)
    Debug.Assert bstatus

    Set swMeasure = swModel.Extension.CreateMeasure
    bstatus = swMeasure.Calculate(Nothing)
    Debug.Assert bstatus

    Debug.Print ("X: " & swMeasure.X)
    Debug.Print ("Y: " & swMeasure.Y)
    Debug.Print ("Z: " & swMeasure.Z)
End Sub

脚本有效,但是在最近使用的坐标系统框架中提供了坐标。它可以是帧“ F”或默认帧,因此结果是不可预测的。我找不到 MEATUR 类的属性来强制使用必要的帧。有没有办法明确指定框架?有解决方法吗?

There is a solidworks assembly containing a point "P" and a coordinate system frame "F". The goal is to find x,y,z coordinates of the point "P" wrt the frame "F". The VB code looks like

Sub main()
    Dim swApp As SldWorks.SldWorks
    Dim swModel As SldWorks.ModelDoc2
    Dim bstatus As Boolean
    Dim swMeasure As SldWorks.Measure
    
    Set swApp = Application.SldWorks
    Set swModel = swApp.ActiveDoc

    swModel.ClearSelection2 True
    bstatus = swModel.Extension.SelectByID2("P", "DATUMPOINT", 0, 0, 0, False, 0, Nothing, 0)
    Debug.Assert bstatus

    Set swMeasure = swModel.Extension.CreateMeasure
    bstatus = swMeasure.Calculate(Nothing)
    Debug.Assert bstatus

    Debug.Print ("X: " & swMeasure.X)
    Debug.Print ("Y: " & swMeasure.Y)
    Debug.Print ("Z: " & swMeasure.Z)
End Sub

The script works, but it gives coordinates in recently used coordinate system frame. It can be the frame "F" or the default frame, so the result is unpredictable. I couldn't find the properties of the Measure class to force it to use the necessary frame. Is there a way to explicitly specify the frame? Is there a workaround?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

2025-02-16 04:46:39

您可以获取像此示例这样的点坐标,GetCoordinateSystemTransformByName or getDefinition ot坐标系统功能,如果点p在组件中,则需要使用组件矩阵变换

另请参见此相关 post

You can get the point coordinates like this example method, then you might need to multiply that with the matrix of the coordinate system with GetCoordinateSystemTransformByName or GetDefinition ot the Coordinate System Feature, and if the point P is in a component, you will need to multiply previous matrix with the component matrix transform Transform2.

See also this related post

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文