如何通过 SolidWorks API 更改孔 Table 轴方向?

How to change Hole Table axis orientation via SolidWorks API?

有没有办法用 SolidWorks API 改变 孔 Table 轴 的方向(方向)?

我可以通过拖动手柄手动完成,但记录了 VB宏不包含实际更改。

这是我想要实现的:

之前

之后

我在这台电脑上没有 Visual Studio 工具,所以我无法录制 C# 或 VB 宏并查看它是否包含更多代码。如果有人可以在他们的 PC 上检查一下,我将不胜感激。

我想通了。这次深入了解 SolidWorks API 帮助很有用。

通过使用 HoleTable.DatumOrigin.SetAxisPoints() 方法,可以更改定义孔 Table 轴的点。
需要注意的重要一点是 SetAxisPoints() 仅更改 轴箭头的端点 (箭头的尖端)。起点会自动更新。

您可以使用 HoleTable.DatumOrigin.GetAxisPoints2() 方法获取当前点值。

另一件需要注意的事情是洞 table 中的值不会自动更新。在我手动拖动一个轴点后,它们确实更新了。 要在调用 SetAxisPoints().

之前通过代码集 HoleTable.EnableUpdate 属性 更新到 False 并返回到 True

这是我需要的代码摘录:

Dim ht As SldWorks.HoleTable
Dim htdo As SldWorks.DatumOrigin
Dim htdaxpts() As Double
Dim htdaxptsnew(0 To 3) As Double
Dim ystarty As Double
Dim yendx As Double
Dim yendy As Double
Dim xstartx As Double
Dim xendx As Double
Dim xendy As Double

    '...
    'here comes code to prepare for Hole Table insertion
    '...

    'insert the Hole Table
    Set htann = theView.InsertHoleTable2(False, anchorx, anchory, swBOMConfigurationAnchor_BottomLeft, "A", holetemplatepath)

    If Not htann Is Nothing Then
        Set ht = htann.HoleTable
        Set htdo = ht.DatumOrigin

        'disable hole table update to get it refresh when done
        ht.EnableUpdate = False

        'get coordinates of the axis arrows (4 pairs of (x,y) doubles: X start(0,1), X end(2,3), Y start(4,5), Y end(6,7))
        htdaxpts = htdo.GetAxisPoints2()
        'take the values we use
        xstartx = htdaxpts(0)
        xendx = htdaxpts(2)
        xendy = htdaxpts(3)
        ystarty = htdaxpts(5)
        yendx = htdaxpts(6)
        yendy = htdaxpts(7)
        'change direction only if Y arrow points up
        If ystarty < yendy Then
            yendy = ystarty - (yendy - ystarty)
        End If
        'change direction only if X arrow points left
        If xstartx > xendx Then
            xendx = xstartx - (xendx - xstartx)
        End If
        'change position only if X arrow is below Y arrow
        If xendy < ystarty Then
            'we can change end point only so change X end y only
            xendy = xendy + (ystarty - xendy) * 2
        End If
        'prepare new axis points (2 pairs of (x,y) doubles: X end(0,1), Y end(2,3))
        htdaxptsnew(0) = xendx
        htdaxptsnew(1) = xendy
        htdaxptsnew(2) = yendx
        htdaxptsnew(3) = yendy
        'set new axis end points
        htdo.SetAxisPoints htdaxptsnew

        'enable hole table update to refresh the values
        ht.EnableUpdate = True

    End If