Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/vba/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Vba 如何通过SolidWorks API更改孔工作台轴方向?_Vba_Solidworks - Fatal编程技术网

Vba 如何通过SolidWorks API更改孔工作台轴方向?

Vba 如何通过SolidWorks API更改孔工作台轴方向?,vba,solidworks,Vba,Solidworks,是否有方法使用SolidWorks API更改孔工作台轴的方向 我可以通过拖动控制柄手动执行此操作,但录制的VBA宏不包含实际更改 这就是我想要实现的目标: 在 在 这台电脑上没有Visual Studio工具,因此无法录制C#或VB宏并查看它是否包含更多代码。如果有人能在他们的电脑上检查一下,我将不胜感激。我已经弄明白了。这一次,通过solidworksapi帮助进行挖掘非常有用 通过使用HoleTable.DatumOrigin.SetAxisPoints()方法,可以更改定义孔工作台轴

是否有方法使用SolidWorks API更改孔工作台轴的方向

我可以通过拖动控制柄手动执行此操作,但录制的VBA宏不包含实际更改

这就是我想要实现的目标:




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

我已经弄明白了。这一次,通过solidworksapi帮助进行挖掘非常有用

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

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

另一件需要注意的事情是,孔参数表中的值不会自动更新。在我手动拖动轴点后,它们确实更新了。 通过调用
SetAxisPoints()
之前和之后的代码集
HoleTable.EnableUpdate
属性将它们更新为
False

下面是我需要的代码摘录:

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
Dim ht作为SldWorks.HoleTable
作为SldWorks.DatumOrigin的Dim htdo
将htdaxpts()设置为双精度
Dim htdaxptsnew(0到3)为双精度
双倍
双色暗黄色
黯淡的杨迪像双倍
Dim xstartx为双精度
Dim xendx为双精度
暗森迪双倍
'...
'下面是准备插入孔参数表的代码
'...
'插入孔表
Set htann=View.InsertHoleTable2(假,anchorx,anchory,SWBOM配置Anchor_左下角,“A”,holetemplatepath)
如果不是,那就什么都不是了
设置ht=htann.HoleTable
设置htdo=ht.DatumOrigin
'禁用孔参数表更新以在完成时刷新孔参数表
ht.EnableUpdate=False
'获取轴箭头的坐标(4对(x,y)双精度:x开始(0,1),x结束(2,3),y开始(4,5),y结束(6,7))
htdaxpts=htdo.GetAxisPoints2()
“以我们使用的值为准
xstartx=htdaxpts(0)
xendx=htdaxpts(2)
xendy=htdaxpts(3)
ystarty=htdaxpts(5)
yendx=htdaxpts(6)
yendy=htdaxpts(7)
'仅当Y箭头指向上时才更改方向
如果Y党xendx,则
xendx=xstartx-(xendx-xstartx)
如果结束
'仅当X箭头低于Y箭头时才更改位置
如果xendy