Как изменить ориентацию оси таблицы отверстий с помощью SolidWorks API?

Есть ли способ изменить ориентацию (направление) осей таблицы отверстий с помощью SolidWorks API?

Я могу сделать это вручную, перетаскивая ручки, но записанный макрос VBA не содержит фактических изменений.

Вот чего я хотел бы добиться:

До
before

После
введите здесь описание изображения

У меня нет инструментов Visual Studio на этом ПК, поэтому я не могу записать макрос C# или VB и посмотреть, содержит ли он дополнительный код. Если кто-то может проверить это на своем компьютере, я был бы признателен.


person spacer    schedule 13.11.2019    source источник


Ответы (1)


Я понял это. На этот раз было полезно копаться в справке SolidWorks API.

Используя метод HoleTable.DatumOrigin.SetAxisPoints(), можно изменить точки, определяющие оси таблицы отверстий.
Важно отметить, что SetAxisPoints() изменяет только конечные точки стрелок осей (наконечники стрелок). Начальные точки обновляются автоматически.

Вы можете получить текущие значения баллов с помощью метода HoleTable.DatumOrigin.GetAxisPoints2().

Следует также отметить, что значения в таблице отверстий не обновляются автоматически. Они обновились после того, как я вручную перетащил точку оси. Чтобы обновить их с помощью кода, установите свойство HoleTable.EnableUpdate в False до и обратно в True после вызова SetAxisPoints().

Вот фрагмент кода, который делает то, что мне нужно:

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
person spacer    schedule 13.11.2019