Offset Sketch Example (VBA)
This example shows how to offset a sketch.
'----------------------------------------------------------------------------
' Preconditions: Ensure the specified template exists.
'
' Postconditions:
' 1. A part with a sketch of a line is created.
' 2. The sketch is offset 2.54 mm in both directions.
' ---------------------------------------------------------------------------
Dim swApp As SldWorks.SldWorks
Dim Part As SldWorks.ModelDoc2
Dim skSegment As SldWorks.SketchSegment
Dim boolstatus As Boolean
Dim longstatus as Long
Sub main()
Set swApp = Application.SldWorks
Set Part = swApp.NewDocument("C:\ProgramData\SolidWorks\SolidWorks
2012\templates\Part.prtdot", 0, 0, 0)
swApp.ActivateDoc2 "Part2", False, longstatus
Set Part = swApp.ActiveDoc
Part.SketchManager.InsertSketch
True
boolstatus = Part.Extension.SelectByID2("Top
Plane", "PLANE", -7.70466366627886E-02, 2.33041566204965E-03,
3.90732100788036E-02, False, 0, Nothing, 0)
Part.ClearSelection2 True
Set skSegment = Part.SketchManager.CreateLine(-0.081532,
0.028203, 0#, -0.029228, -0.017264, 0#)
Set skSegment = Part.SketchManager.CreateLine(-0.029228,
-0.017264, 0#, 0.035382, -0.025468, 0#)
Set skSegment = Part.SketchManager.CreateLine(0.035382,
-0.025468, 0#, 0.087008, -0.070346, 0#)
Part.ClearSelection2 True
boolstatus = Part.Extension.SelectByID2("Line3",
"SKETCHSEGMENT", 0, 0, 0, False, 1, Nothing, 0)
boolstatus = Part.SketchManager.SketchOffset(0.00254,
True, True, True, False, True)
' Alternative sketch offset method
' boolstatus = Part.SketchOffset2(0.00254, True, True)
Part.ClearSelection2 True
Part.SketchManager.InsertSketch True
End Sub