Ok, a bit late, been swamped this week 🙂
Here's what I came up with last week.
Public Sub BP()
' Create a new part document, using the default part template.
Dim oPartDoc As PartDocument
Set oPartDoc = ThisApplication.Documents.Add(kPartDocumentObject, _
ThisApplication.FileManager.GetTemplateFile(kPartDocumentObject))
' Set a reference to the component definition.
Dim oCompDef As PartComponentDefinition
Set oCompDef = oPartDoc.ComponentDefinition
' Create a new sketch on the X-Z work plane. Since it's being created on
Dim oSketch As PlanarSketch
Set oSketch = oCompDef.Sketches.Add(oCompDef.WorkPlanes(2))
' Set a reference to the transient geometry object.
Dim oTransGeom As TransientGeometry
Set oTransGeom = ThisApplication.TransientGeometry
'project origin point
Dim OP As SketchPoint
Set OP = oSketch.AddByProjectingEntity(oCompDef.WorkPoints.Item(1))
' Draw a 4cm x 3cm rectangle with the corner at (0,0)
Dim oc As SketchCircle
Set oc = oSketch.SketchCircles.AddByCenterRadius(OP, 24 * 2.54)
'Set oc = oSketch.SketchCircles.AddByCenterRadius(oTransGeom.CreatePoint2d(0, 0), 24 * 2.54)
Dim dimOD As DimensionConstraint
Set dimOD = oSketch.DimensionConstraints.AddDiameter(oc, oTransGeom.CreatePoint2d(3, 3), False)
dimOD.Parameter.Name = "OD"
Dim IC As SketchCircle
Set IC = oSketch.SketchCircles.AddByCenterRadius(OP, 18 * 2.54)
'Set IC = oSketch.SketchCircles.AddByCenterRadius(oTransGeom.CreatePoint2d(0, 0), 18 * 2.54)
Dim dimID As DimensionConstraint
Set dimID = oSketch.DimensionConstraints.AddDiameter(IC, oTransGeom.CreatePoint2d(-5, -5), False)
dimID.Parameter.Name = "ID"
'Create a Profile
Dim Prof As Profile
Set Prof = oSketch.Profiles.AddForSolid
'Create solid extrusion
Dim Ex1 As ExtrudeDefinition
Set Ex1 = oCompDef.Features.ExtrudeFeatures.CreateExtrudeDefinition(Prof, kJoinOperation)
Call Ex1.SetDistanceExtent(1, kPositiveExtentDirection)
Dim oExtrude1 As ExtrudeFeature
Set oExtrude1 = oCompDef.Features.ExtrudeFeatures.Add(Ex1)
'Create new sketch on top face
Dim TopF As Face
Set TopF = oExtrude1.EndFaces.Item(1)
Set oSketch = oCompDef.Sketches.AddWithOrientation(TopF, oCompDef.WorkAxes.Item(1), True, True, oCompDef.WorkPoints(1))
Set OP = oSketch.AddByProjectingEntity(oCompDef.WorkPoints.Item(1))
Dim SL1 As SketchLine
Set SL1 = oSketch.SketchLines.AddByTwoPoints(OP, oTransGeom.CreatePoint2d(0, 21 * 2.54))
Dim vert As GeometricConstraint
Set vert = oSketch.GeometricConstraints.AddVertical(SL1)
Dim LL As DimensionConstraint
Set LL = oSketch.DimensionConstraints.AddTwoPointDistance(SL1.StartSketchPoint, SL1.EndSketchPoint, kAlignedDim, oTransGeom.CreatePoint2d(7, 15), False)
Dim SL2 As SketchLine
Set SL2 = oSketch.SketchLines.AddByTwoPoints(OP, oTransGeom.CreatePoint2d(15, 30))
Dim L2 As DimensionConstraint
Set L2 = oSketch.DimensionConstraints.AddTwoPointDistance(SL2.StartSketchPoint, SL2.EndSketchPoint, kAlignedDim, oTransGeom.CreatePoint2d(7, 15), False)
L2.Parameter.value = 21 * 2.54
L2.Parameter.Name = "BCD2"
Dim A1 As DimensionConstraint
Set A1 = oSketch.DimensionConstraints.AddThreePointAngle(SL2.EndSketchPoint, OP, SL1.EndSketchPoint, oTransGeom.CreatePoint2d(15, 15), False)
A1.Parameter.value = ((180 - 15) * 3.1415) / 180
A1.Parameter.Name = "Angle1"
oPartDoc.Update
' Create an object collection for the hole center points.
Dim oHoleCenters As ObjectCollection
Set oHoleCenters = ThisApplication.TransientObjects.CreateObjectCollection
Dim myX, myY As Double
myX = SL2.EndSketchPoint.Geometry.X
myY = SL2.EndSketchPoint.Geometry.Y
' Add two points as hole centers.
'oHoleCenters.Add oSketch.SketchPoints.Add(oTransGeom.CreatePoint2d(0, 21 * 2.54)) works
'oHoleCenters.Add oSketch.SketchPoints.Add(oTransGeom.CreatePoint2d(SL2.EndSketchPoint.HoleCenter))
'Call oHoleCenters.Add(oSketch.SketchPoints.Add(SL2.EndSketchPoint))
oHoleCenters.Add oSketch.SketchPoints.Add(oTransGeom.CreatePoint2d(myX, myY), True)
' Create the hole feature.
Call oCompDef.Features.HoleFeatures.AddDrilledByThroughAllExtent( _
oHoleCenters, "1 in", kPositiveExtentDirection)
oPartDoc.Update
'fit view
ThisApplication.ActiveView.Fit
End Sub