Option Explicit
Sub CATMain()
'---------------------------------------------
' Variables declarations
'---------------------------------------------
Dim oPartDoc As PartDocument
Set oPartDoc = CATIA.ActiveDocument
Dim oSelection
Set oSelection = oPartDoc.Selection
oSelection.Clear
Dim oPart As Part
Set oPart = oPartDoc.Part
Dim oBodies As HybridBodies
Set oBodies = oPart.HybridBodies
Dim oParams As Parameters
Set oParams = oPart.Parameters
Dim oHybridShapeFactory As HybridShapeFactory
Set oHybridShapeFactory = oPart.HybridShapeFactory
Dim oProduct As Product
Set oProduct = oPartDoc.GetItem(oPart.Name)
Dim oPublications
Set oPublications = oProduct.Publications
Dim InputObjectType(0)
InputObjectType(0) = "Edge"
Dim j As Integer
Dim i As Integer
Dim m As Integer
'---------------------------------------------
' Circular holes prerequisite
'---------------------------------------------
Dim oHolePublicationData As HybridBody
Dim strHybridBodyName As String
strHybridBodyName = "HolePublicationData"
Dim oReferencePlane
Dim ReferencePlaneForObject As Reference
Dim oLine
Dim oClearanceCircle
Dim oDiamRelation As Formula
Dim oExtractPointParam
Dim oClearanceDiamParam As Dimension
Dim dFootThickness 'As Double
Dim oLineParams As Parameters
Dim oFootThickParam As Dimension
Dim dCircleRadius As Double
Dim dInsertHoleDiamParam
Dim bInsertHolesParamExistence As Boolean
bInsertHolesParamExistence = False
oPart.Update
'Creation of HolePublicationData geometrical set and parameters if previous checks ran well. Ask the user to enter the FootThickness as well.
Set oHolePublicationData = oBodies.Add()
oHolePublicationData.Name = strHybridBodyName
oPart.Update
'---------------------------------------------
' "Circular holes interface"
'---------------------------------------------
MsgBox "Circular holes interface starting; press escape when you have finished."
'---------------------------------------------
' Declaration of variables needed for the "Circle interface" below
'---------------------------------------------
Dim CircularHolesStatus
CircularHolesStatus = "Normal"
Dim oSelectedCircle
Dim iHoleNumber As Integer
Dim strHoleNumber As String
iHoleNumber = 1
Dim oCircleCenter
Dim ReferenceCircleCenterForObject As Reference
'---------------------------------------------
' Circular holes selection
'---------------------------------------------
While CircularHolesStatus = "Normal"
'---------------------------------------------
'Error-handling
'---------------------------------------------
On Error Resume Next
If Err.Number <> 0 Then
Err.Clear
MsgBox "Unable to proceed.", vbCritical, "Critical error"
Exit Sub
End If
'---------------------------------------------
' Selection of the circle edge
'---------------------------------------------
' Line from where it resume if an other edge than a circular is selected
SelectionResumption:
oSelection.Clear
CircularHolesStatus = oSelection.SelectElement2(InputObjectType, "Select a circular hole edge ", False)
If CircularHolesStatus = "Normal" Then
Set oSelectedCircle = oSelection.Item(1).Value
oSelection.Clear
If Not TypeName(oSelectedCircle) = "TriDimFeatEdge" Then
MsgBox ("The selected object is not a slotted edge, please start again.")
GoTo SelectionResumption:
End If
'---------------------------------------------
'Create the reference plane and publish it.
'---------------------------------------------
Dim FirstOne, SecondOne
Set oReferencePlane = oHybridShapeFactory.AddNewPlane1Curve(oSelectedCircle)
oHolePublicationData.AppendHybridShape oReferencePlane
oPart.Update
oReferencePlane.Name = "Ref.Plane" & CStr(iHoleNumber)
Call Publication(oReferencePlane, oProduct)
oPart.Update
oSelection.Clear
oSelection.Add oReferencePlane
oSelection.VisProperties.SetRealColor 128, 0, 128, 0
oPart.Update
oSelection.Clear
Set ReferencePlaneForObject = oPart.CreateReferenceFromObject(oReferencePlane)
oPart.Update
'This is to number every points, lines and clearance circle
iHoleNumber = iHoleNumber + 1
strHoleNumber = CStr(iHoleNumber)
[indent]'Here is the test I want to do[/indent]
If iHoleNumber = 3 Then
FirstOne = oHolePublicationData.Item("Ref.Plane1")
SecondOne = oHolePublicationData.Item("Ref.Plane2")
Dim reference1 As Reference
Set reference1 = oPart.CreateReferenceFromObject(FirstOne)
Dim reference2 As Reference
Set reference2 = oPart.CreateReferenceFromObject(SecondOne)
Dim TheSPAWorkbench As Workbench
Set TheSPAWorkbench = CATIA.ActiveDocument.GetWorkbench("SPAWorkbench")
Dim TheMeasurable As Measurable
Set TheMeasurable = TheSPAWorkbench.GetMeasurable(reference1)
Dim Angle As Double
Angle = TheMeasurable.GetAngleBetween(reference2)
MsgBox ("Angle=" & CStr(MinimumDistance))
End If
Else
If MsgBox("Have you finished to prepare all the circular insert holes ?", vbYesNo) = vbNo Then
CircularHolesStatus = "Normal"
Else
MsgBox ("Circular holes interface completed")
GoTo CircularWhileExit:
End If
End If
On Error GoTo 0
Wend
CircularWhileExit:
End Sub