Code:
Sub CATMain()Dim Teil As Part
Set Teil = CATIA.ActiveDocument.Part
Dim Koerper As Body
Set Koerper = Teil.Bodies.Item("Gewinde")
Teil.InWorkObject = Koerper
Dim InputObjectType(0)
InputObjectType(0) = "Face"
Dim Auswahl
Set Auswahl = CATIA.ActiveDocument.Selection
Auswahl.Clear
Status = Auswahl.SelectElement2(InputObjectType, "Fläche für Bohrung wählen", True)
Dim Flaeche As Reference
Set Flaeche = Auswahl.Item(1).Value
Dim Bohrer As ShapeFactory
Set Bohrer = Teil.ShapeFactory
Dim Bohrung As Hole
Set Bohrung = Bohrer.AddNewHole(Flaeche, 22)
Dim BohrSkizze As Sketch
With Bohrung
.Type = catSimpleHole
'.AnchorMode = catExtremPointHoleAnchor
.BottomType = catVHoleBottom
.BottomLimit.LimitMode = catOffsetLimit
.BottomAngle.Value = 120
.ThreadingMode = catThreadedHoleThreading 'Gewindebohrung
.CreateStandardThreadDesignTable catHoleMetricThickPitch
.HoleThreadDescription.Value = "M6"
'.ThreadingMode = catSmoothHoleThreading 'Einfache Bohrung
'.Diameter.Value = 6
.ThreadSide = catRightThreadSide
Set BohrSkizze = .Sketch
End With
Auswahl.Clear
Status = Auswahl.SelectElement2(InputObjectType, "Erste Fläche für Bemaßung wählen", True)
Dim Abstand1 As Reference
Set Abstand1 = Auswahl.Item(1).Value
Auswahl.Clear
Status = Auswahl.SelectElement2(InputObjectType, "Zweite Fläche für Bemaßung wählen", True)
Dim Abstand2 As Reference
Set Abstand2 = Auswahl.Item(1).Value
Dim Punkt As Reference
Set Punkt = Teil.CreateReferenceFromObject(BohrSkizze.GeometricElements.Item(2))
Teil.InWorkObject = BohrSkizze
BohrSkizze.OpenEdition
Dim Bedingung As Constraint
Set Bedingung = BohrSkizze.Constraints.AddBiEltCst(catCstTypeDistance, Punkt, Abstand1)
Bedingung.Mode = catCstModeDrivingDimension
Bedingung.Dimension.Value = 10
Set Bedingung = BohrSkizze.Constraints.AddBiEltCst(catCstTypeDistance, Punkt, Abstand2)
Bedingung.Mode = catCstModeDrivingDimension
Bedingung.Dimension.Value = 10
BohrSkizze.CloseEdition
Auswahl.Clear
Auswahl.Add BohrSkizze
Auswahl.Add BohrSkizze.GeometricElements.Item("AbsoluteAxis").GetItem("Origin")
Auswahl.Add BohrSkizze.GeometricElements.Item("AbsoluteAxis").GetItem("HDirection")
Auswahl.Add BohrSkizze.GeometricElements.Item("AbsoluteAxis").GetItem("VDirection")
Auswahl.VisProperties.SetShow 1
Teil.InWorkObject = Koerper
InputObjectType(0) = "Edge"
Auswahl.Clear
Status = Auswahl.SelectElement2(InputObjectType, "Richtung fürs Pattern wählen", True)
Dim Richtung As Reference
Set Richtung = Auswahl.Item(1).Value
Dim A1 As Reference
Set A1 = Teil.CreateReferenceFromName("")
Dim A2 As Reference
Set A2 = Teil.CreateReferenceFromName("")
Dim Muster As RectPattern
Set Muster = Bohrer.AddNewRectPattern(Bohrung, 2, 1, 30, 30, 1, 1, Richtung, A2, True, True, 0)
Muster.SetFirstDirection Richtung
Teil.Update
Teil.InWorkObject = Teil.MainBody
End Sub