0

I am trying to implement a minimum boundary box subroutine inside my macro. Subroutine ends before going into if statement. Can you help me find the solution?

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

All variables on the program are checked and they work. I don't understand what is happening an why it doesnt work. I even checked all variables. Program should go inside if statement but it doesnt

Pᴇʜ
  • 56,719
  • 10
  • 49
  • 73
  • Use `Option explicit`. You will notice that `extindex` is not declared. it has a value of `0` and hence your if condition will never be true... – Siddharth Rout Oct 04 '19 at 06:21
  • Also `If extindex = (1) Or (2) Then` should be written as `If extindex = 1 Or extindex = 2) Then`. BTW a `Select Case` would be more appropriate here... – Siddharth Rout Oct 04 '19 at 06:22
  • extindex is declared on main sub like "public extindex as integer" it get the proper values inside this sub. But i will try select case. Thank you. – Serhat Yıldız Oct 04 '19 at 06:49
  • I tried everthing you said. It still doesnt work. – Serhat Yıldız Oct 04 '19 at 07:05
  • can you post the updated code above? – Siddharth Rout Oct 04 '19 at 07:12
  • i update the code. Like i said extindex is declared public. This subroutine is in a for loop of 6 in main. extindex is variable of for loop. I cant even see debug print after if statement – Serhat Yıldız Oct 04 '19 at 07:39
  • What does `MsgBox CStr(extindex)` give you? – Siddharth Rout Oct 04 '19 at 07:52
  • Could it be you have in the outside sub on error resume next? So there might be an error before it reaches the if statement and because there is an error it resumes the outer sub? – Lorne Oct 04 '19 at 07:54
  • MsgBox CStr(extindex) gives me 1,2,3,4,5 and 6 – Serhat Yıldız Oct 04 '19 at 08:04
  • checked for errors inside sub. Cleared errors before it just in case. No errors after first if statement. Still no improvement – Serhat Yıldız Oct 04 '19 at 08:42
  • I've found the problem. I am trying to get directions from coordinate system but the coordinate system is created from a point and a plane for z direction. x and y directions are not specifed. Because of that program cannot use .YAxisDirection and .XaxisDirection which causes program not to work. I still dont understand why program doesnt execute codes after select-case. – Serhat Yıldız Oct 04 '19 at 11:00

1 Answers1

0

The AxisSystem properties XAxisDirection, YAxisDirection, and ZAxisDirection refer to the references from which the axis system was defined.

You can use these properties to edit the AxisSystem object itself but they are not "output" Reference objects which should be used to construct downstream geometry.

You can pull the vectors components using the GetXAxis, GetYAxis, and GetZAxis methods (which will always contain values) and then use HybridShapeFactory.AddDirectionFromCoord() method to create the direction for the extremum.

...
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))
...
C R Johnson
  • 964
  • 1
  • 5
  • 12