程序在 if 语句之前关闭 (CATIA VBA)

Program closes before if statement (CATIA VBA)

我正在尝试在我的宏中实现最小边界框子例程。子例程在进入 if statement 之前结束。你能帮我找到解决办法吗?

Option Explicit

Sub bounding()

Dim partDocument1 As PartDocument
Set partDocument1 = CATIA.ActiveDocument

Dim part1 As Part
Set part1 = partDocument1.Part

Dim hybridShapeFactory1 As HybridShapeFactory
Set hybridShapeFactory1 = part1.HybridShapeFactory

Dim hybridBodies1 As HybridBodies
Set hybridBodies1 = part1.HybridBodies

Dim hybridBody1 As hybridbody
Set hybridBody1 = hybridBodies1.Item(cevap)

Dim hybridShapes1 As HybridShapes
Set hybridShapes1 = hybridBody1.HybridShapes

Dim axisSystems1 As AxisSystems
Set axisSystems1 = part1.AxisSystems

Dim axisSystem1 As AxisSystem
Set axisSystem1 = part1.FindObjectByName("axissys")



Dim direction As Long


If extindex Mod 2 = 1 Then

direction = 1

Else

direction = 0

End If


Dim reference1 As Reference

MsgBox CStr(extindex)

Select Case extindex

Case 1, 2

Set reference1 = axisSystem1.XAxisDirection

MsgBox CStr(extindex) + "1ve2"

Case 3, 4

Set reference1 = axisSystem1.YAxisDirection
MsgBox CStr(extindex) + "3ve4"

Case Else


Set reference1 = axisSystem1.YAxisDirection
MsgBox CStr(extindex) + "5ve6"

End Select

Debug.Print ("exit if check")

Dim hybridShapeDirection1 As HybridShapeDirection
Set hybridShapeDirection1 = hybridShapeFactory1.AddNewDirection(reference1)


Dim bodies1 As Bodies
Set bodies1 = part1.Bodies

Dim body1 As Body
Set body1 = bodies1.Item("PartBody")

Dim reference2 As Reference
Set reference2 = part1.CreateReferenceFromObject(body1)

Dim hybridShapeExtremum1 As HybridShapeExtremum
Set hybridShapeExtremum1 = hybridShapeFactory1.AddNewExtremum(reference2,                         
hybridShapeDirection1, 0)

part1.Update

hybridBody1.AppendHybridShape hybridShapeExtremum1

part1.InWorkObject = hybridShapeExtremum1

hybridShapeExtremum1.Name = "ext1" + CStr(extindex)



part1.Update

End Sub

程序上的所有变量都经过检查并且它们有效。我不明白发生了什么,为什么它不起作用。我什至检查了所有变量。程序应该在 if statement 里面,但它没有

AxisSystem 属性 XAxisDirection、YAxisDirection 和 ZAxisDirection 引用定义轴系统的参考。

您可以使用这些属性来编辑 AxisSystem 对象本身,但它们不是 "output" 应该用于构造下游几何体的参考对象。

您可以使用 GetXAxis、GetYAxis 和 GetZAxis 方法(始终包含值)提取向量分量,然后使用 HybridShapeFactory.AddDirectionFromCoord() 方法创建极值方向。

...
MsgBox CStr(extindex)
Dim vect(2)
Dim vAxis As Variant
Set vAxis = axisSystem1

Select Case extindex
Case 1, 2
    vAxis.GetXAxis vect
Case 3, 4
    vAxis.GetYAxis vect
Case Else
    vAxis.GetYAxis vect
End Select

Dim hybridShapeDirection1 As HybridShapeDirection
Set hybridShapeDirection1 = hybridShapeFactory1.AddNewDirectionByCoord(vect(0), vect(1), vect(2))
...