Files
Associated model(s) Create a keyhole profile and then extrude cut
Code
'Preconditions: A block 200x200mm on Front Plane is present; face is selected
'Result: Extrude cut with keyhole profile is created
'Written by Keith Rice
'CADSharp LLC
'www.cadsharp.com
Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim swSketchMgr As SldWorks.SketchManager
Dim swDim As SldWorks.Dimension
Dim swSketch As SldWorks.Sketch
Dim vSketchSegs As Variant
Dim swSketchSeg As SldWorks.SketchSegment
Dim swBody As SldWorks.Body2
Dim swFace As SldWorks.Face2
Dim swFeatMgr As SldWorks.FeatureManager
Dim swFeat As SldWorks.Feature
Sub main()
Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc
Set swSketchMgr = swModel.SketchManager
Set swFeatMgr = swModel.FeatureManager
'insert sketch on selected face
swSketchMgr.InsertSketch True
'create 3 pt arc: XYZ1 = start point, XYZ2 = end pt, XYZ3 = middle pt
swSketchMgr.Create3PointArc 0.01, 0, 0, -0.01, 0, 0, 0, -0.01, 0
'create vert line
swSketchMgr.CreateLine -0.01, 0, 0, -0.01, 0.02, 0
'create tangent arc
swSketchMgr.CreateTangentArc -0.01, 0.02, 0, -0.02, 0.03, 0, swFront
'create horiz line
swSketchMgr.CreateLine -0.02, 0.03, 0, -0.03, 0.03, 0
'create vert line
swSketchMgr.CreateLine -0.03, 0.03, 0, -0.03, 0.055, 0
'create 3 pt arc
swSketchMgr.Create3PointArc -0.03, 0.055, 0, 0.03, 0.055, 0, 0, 0.145, 0
'create vert line
swSketchMgr.CreateLine 0.03, 0.055, 0, 0.03, 0.03, 0
'create horiz line
swSketchMgr.CreateLine 0.03, 0.03, 0, 0.02, 0.03, 0
'create tangent arc
swSketchMgr.CreateTangentArc 0.02, 0.03, 0, 0.01, 0.02, 0, 1
'create vert line
swSketchMgr.CreateLine 0.01, 0.02, 0, 0.01, 0, 0
'fully define sketch; first select the origin (a sketch point, not a vertex) and mark _
it with 6 so that it is used as the datum
swModel.Extension.SelectByID2 "", "EXTSKETCHPOINT", 0, 0, 0, False, 6, Nothing, 0
swSketchMgr.FullyDefineSketch True, True, 1023, True, 1, Nothing, 1, Nothing, 0, 0
'leave sketch
swSketchMgr.InsertSketch True
'create extrude cut; third arg is the direction; see notes
Set swFeat = swFeatMgr.FeatureCut3(True, False, False, 1, 0, 0.01, 0.01, False, False, _
False, False, 0, 0, False, False, False, False, False, True, True, _
True, True, False, 0, 0, False)
End Sub
'For FeatureCut3, by default the cut occurs opposite of the normal of the face. The third arg _
should be True if you want the direction FLIPPED opposite of the default. Hence normally _
you would want False