Having some trouble with this code;
The intent is for the user to select a hole edge then generate a cylinder(GSD) normal to the support surface as a keep out zone.
It completely skips the user input(screen pick) for the edge and support surface but generates the cylinder with missing center point and surface inputs.
I'm still trying to teach myself VB so I may have missed something fundamental.
Sub CATMain(Radius, Height1, Height2)
On Error Resume Next
Dim partDocument1 As Document
Dim part1 As Part
Set partDocument1 = CATIA.ActiveDocument
Set part1 = partDocument1.Part
If Err.Number = 0 Then
partDocument1.Activate
Dim Dia1 As Long
Dia1 = Radius * 2
Dim hybridBodies1 As HybridBodies
Set hybridBodies1 = part1.HybridBodies
Dim hybridBody1 As HybridBody
Set hybridBody1 = hybridBodies1.Add()
hybridBody1.Name = "Ø" & Dia1 & "mm Socket Clearance"
partDocument1.Activate
Dim sel2 As Selection
Set sel2 = part1.Selection
If sel2.Count > 0 Then
sel2.Clear
End If
Dim Sel2lb 'as selection 'declare as a variant, not as a Selection (for selectelement2)
Dim InputObjectType1(3), UserInput1
InputObjectType1(0) = "BiDimFeatEdge"
InputObjectType1(1) = "TriDimFeatEdge"
InputObjectType1(2) = "HybridShapeCurveExplicit"
InputObjectType1(3) = "Vertex"
Set Sel2lb = sel2 'late bound sel2
UserInput1 = Sel2lb.SelectElement2(InputObjectType1(), ">>>>>>>>>>>> Select circular edge <<<<<<<<<<<<", False)
If (UserInput1 = "Cancel") Then Exit Sub
Dim CircEdge1 As Object
Set CircEdge1 = Sel2lb.Item(1).Reference
partDocument1.Activate
Sel2lb.Clear
Dim sel3 As Selection
Set sel3 = part1.Selection
If sel3.Count > 0 Then
sel3.Clear
End If
Dim sel3lb 'as selection 'declare as a variant, not as a Selection (for selectelement2)
Dim InputObjectType2(0), UserInput2
InputObjectType2(0) = "BiDim"
Set sel3lb = sel3 'late bound sel3
UserInput2 = sel3lb.SelectElement2(InputObjectType2, ">>>>>>>>>>>>>> Select the support surface <<<<<<<<<<<<<<", False)
If (UserInput2 = "Cancel") Then Exit Sub
Dim Surf1
Set Surf1 = sel3lb.Item(1).Reference
Dim reference1 As Reference
Set reference1 = part1.CreateReferenceFromObject(CircEdge1)
Dim reference2 As Reference
Set reference2 = part1.CreateReferenceFromObject(Surf1)
Dim HybridShapeFactory1 As Factory
Set HybridShapeFactory1 = part1.HybridShapeFactory
Dim hybridShapeDirection1 As HybridShapeDirection
Set hybridShapeDirection1 = HybridShapeFactory1.AddNewDirection(reference2)
Dim hybridShapeCylinder1 As HybridShapeCylinder
Set hybridShapeCylinder1 = HybridShapeFactory1.AddNewCylinder(reference1, Radius, Height1, Height2, hybridShapeDirection1)
hybridShapeCylinder1.SymmetricalExtension = 0
hybridBody1.AppendHybridShape hybridShapeCylinder1
part1.Update
Else
MsgBox "This is not a part document!"
End If
End Sub
The intent is for the user to select a hole edge then generate a cylinder(GSD) normal to the support surface as a keep out zone.
It completely skips the user input(screen pick) for the edge and support surface but generates the cylinder with missing center point and surface inputs.
I'm still trying to teach myself VB so I may have missed something fundamental.
Sub CATMain(Radius, Height1, Height2)
On Error Resume Next
Dim partDocument1 As Document
Dim part1 As Part
Set partDocument1 = CATIA.ActiveDocument
Set part1 = partDocument1.Part
If Err.Number = 0 Then
partDocument1.Activate
Dim Dia1 As Long
Dia1 = Radius * 2
Dim hybridBodies1 As HybridBodies
Set hybridBodies1 = part1.HybridBodies
Dim hybridBody1 As HybridBody
Set hybridBody1 = hybridBodies1.Add()
hybridBody1.Name = "Ø" & Dia1 & "mm Socket Clearance"
partDocument1.Activate
Dim sel2 As Selection
Set sel2 = part1.Selection
If sel2.Count > 0 Then
sel2.Clear
End If
Dim Sel2lb 'as selection 'declare as a variant, not as a Selection (for selectelement2)
Dim InputObjectType1(3), UserInput1
InputObjectType1(0) = "BiDimFeatEdge"
InputObjectType1(1) = "TriDimFeatEdge"
InputObjectType1(2) = "HybridShapeCurveExplicit"
InputObjectType1(3) = "Vertex"
Set Sel2lb = sel2 'late bound sel2
UserInput1 = Sel2lb.SelectElement2(InputObjectType1(), ">>>>>>>>>>>> Select circular edge <<<<<<<<<<<<", False)
If (UserInput1 = "Cancel") Then Exit Sub
Dim CircEdge1 As Object
Set CircEdge1 = Sel2lb.Item(1).Reference
partDocument1.Activate
Sel2lb.Clear
Dim sel3 As Selection
Set sel3 = part1.Selection
If sel3.Count > 0 Then
sel3.Clear
End If
Dim sel3lb 'as selection 'declare as a variant, not as a Selection (for selectelement2)
Dim InputObjectType2(0), UserInput2
InputObjectType2(0) = "BiDim"
Set sel3lb = sel3 'late bound sel3
UserInput2 = sel3lb.SelectElement2(InputObjectType2, ">>>>>>>>>>>>>> Select the support surface <<<<<<<<<<<<<<", False)
If (UserInput2 = "Cancel") Then Exit Sub
Dim Surf1
Set Surf1 = sel3lb.Item(1).Reference
Dim reference1 As Reference
Set reference1 = part1.CreateReferenceFromObject(CircEdge1)
Dim reference2 As Reference
Set reference2 = part1.CreateReferenceFromObject(Surf1)
Dim HybridShapeFactory1 As Factory
Set HybridShapeFactory1 = part1.HybridShapeFactory
Dim hybridShapeDirection1 As HybridShapeDirection
Set hybridShapeDirection1 = HybridShapeFactory1.AddNewDirection(reference2)
Dim hybridShapeCylinder1 As HybridShapeCylinder
Set hybridShapeCylinder1 = HybridShapeFactory1.AddNewCylinder(reference1, Radius, Height1, Height2, hybridShapeDirection1)
hybridShapeCylinder1.SymmetricalExtension = 0
hybridBody1.AppendHybridShape hybridShapeCylinder1
part1.Update
Else
MsgBox "This is not a part document!"
End If
End Sub