Hello everyone , i am trying to make a simple code to create a hole using (AddNewHoleFromRefPoint).
I used twice "selecetelement2" : once for vertex , second for face and made them references , seems to look fine but code fails on this line:
and cannot understand why .
I tried also (AddNewHole) - wich requires only face as support and depth) and it works , so i am assuming that problem is somewhere with "vertex"
Could someone help me , please?
VBA code :
Sub CATMain()
Dim partDocument1 As PartDocument
Set partDocument1 = CATIA.ActiveDocument
Dim part1 As Part
Set part1 = partDocument1.Part
Dim osel As Object
Set osel = partDocument1.Selection
Dim status As String
Dim InputObjectType(0)
InputObjectType(0) = "Vertex"
status = osel.SelectElement2(InputObjectType, "Select vertex", False)
If status = "Normal" And osel.Count = 1 Then
Dim vertex1 As Reference
Set vertex1 = osel.Item(1).Reference
Else
MsgBox ("Macro aborted, to execute the desired action, select the Macro again")
Exit Sub
End If
Dim EnabledObjectSelection1(0)
EnabledObjectSelection1(0) = "Face"
Dim osel2 As Object
Set osel2 = partDocument1.Selection
Dim status2 As String
status2 = osel2.SelectElement2(EnabledObjectSelection1, "Select face ", False)
If status2 = "Normal" And osel2.Count = 1 Then
Dim face1 As Reference
Set face1 = osel2.Item(1).Reference
Dim shapeFactory1 As ShapeFactory
Set shapeFactory1 = part1.ShapeFactory
Dim hole1 As Hole
Set hole1 = shapeFactory1.AddNewHoleFromRefPoint(vertex1, face1, 10#)
hole1.Type = catSimpleHole
hole1.AnchorMode = catExtremPointHoleAnchor
hole1.BottomType = catVHoleBottom
Dim limit1 As Limit
Set limit1 = hole1.BottomLimit
limit1.LimitMode = catOffsetLimit
Dim length1 As Length
Set length1 = hole1.Diameter
length1.Value = 10#
Dim angle1 As Angle
Set angle1 = hole1.BottomAngle
angle1.Value = 120#
hole1.ThreadingMode = catSmoothHoleThreading
hole1.ThreadSide = catRightThreadSide
length1.Value = 9#
Dim length2 As Length
Set length2 = limit1.Dimension
length2.Value = 25#
part1.Update
End If
End Sub
I used twice "selecetelement2" : once for vertex , second for face and made them references , seems to look fine but code fails on this line:
I tried also (AddNewHole) - wich requires only face as support and depth) and it works , so i am assuming that problem is somewhere with "vertex"
Could someone help me , please?
VBA code :
Sub CATMain()
Dim partDocument1 As PartDocument
Set partDocument1 = CATIA.ActiveDocument
Dim part1 As Part
Set part1 = partDocument1.Part
Dim osel As Object
Set osel = partDocument1.Selection
Dim status As String
Dim InputObjectType(0)
InputObjectType(0) = "Vertex"
status = osel.SelectElement2(InputObjectType, "Select vertex", False)
If status = "Normal" And osel.Count = 1 Then
Dim vertex1 As Reference
Set vertex1 = osel.Item(1).Reference
Else
MsgBox ("Macro aborted, to execute the desired action, select the Macro again")
Exit Sub
End If
Dim EnabledObjectSelection1(0)
EnabledObjectSelection1(0) = "Face"
Dim osel2 As Object
Set osel2 = partDocument1.Selection
Dim status2 As String
status2 = osel2.SelectElement2(EnabledObjectSelection1, "Select face ", False)
If status2 = "Normal" And osel2.Count = 1 Then
Dim face1 As Reference
Set face1 = osel2.Item(1).Reference
Dim shapeFactory1 As ShapeFactory
Set shapeFactory1 = part1.ShapeFactory
Dim hole1 As Hole
Set hole1 = shapeFactory1.AddNewHoleFromRefPoint(vertex1, face1, 10#)
hole1.Type = catSimpleHole
hole1.AnchorMode = catExtremPointHoleAnchor
hole1.BottomType = catVHoleBottom
Dim limit1 As Limit
Set limit1 = hole1.BottomLimit
limit1.LimitMode = catOffsetLimit
Dim length1 As Length
Set length1 = hole1.Diameter
length1.Value = 10#
Dim angle1 As Angle
Set angle1 = hole1.BottomAngle
angle1.Value = 120#
hole1.ThreadingMode = catSmoothHoleThreading
hole1.ThreadSide = catRightThreadSide
length1.Value = 9#
Dim length2 As Length
Set length2 = limit1.Dimension
length2.Value = 25#
part1.Update
End If
End Sub