This example shows how to replace a sketch entity in a model with another
sketch entity.
'----------------------------------------------------------------------------
' Preconditions: Ensure that the specified template exists.
'
' Postconditions: A sketch line is replaced with a sketch arc, and the
' extrusion is modified.
'
---------------------------------------------------------------------------
Imports
SolidWorks.Interop.sldworks
Imports
SolidWorks.Interop.swconst
Imports
System.Runtime.InteropServices
Imports
System
Partial
Class
SolidWorksMacro
Dim
Part As
ModelDoc2
Dim
myFeature As
Feature
Dim
skSegment As
SketchSegment
Dim
boolstatus As
Boolean
Sub
main()
Part = swApp.NewDocument("C:\ProgramData\SolidWorks\SolidWorks
2014\templates\Part.prtdot", 0, 0, 0)
Part = swApp.ActiveDoc
boolstatus = Part.Extension.SelectByID2("Front
Plane",
"PLANE", -0.048646278525398,
0.0222864804840025, 0.0105288722478765,
False, 0,
Nothing, 0)
Dim
vSkLines As
Object
vSkLines = Part.SketchManager.CreateCornerRectangle(-0.0338155129850894,
0.0167825138518592, 0, 0.0551067619016271, -0.0245475575743612, 0)
Part.ClearSelection2(True)
Part.SketchManager.InsertSketch(True)
Part.ShowNamedView2("*Trimetric",
8)
boolstatus = Part.Extension.SelectByID2("Sketch1",
"SKETCH",
0, 0, 0, False,
4, Nothing,
0)
myFeature = Part.FeatureManager.FeatureExtrusion2(True,
False,
False, 0,
0, 0.01778, 0.00254, False,
False,
False,
False,
0.0174532925199433, 0.0174532925199433,
False,
False,
False,
False, True,
True,
True, 0, 0,
False)
Part.SelectionManager.EnableContourSelection =
False
boolstatus = Part.Extension.SelectByID2("Sketch1",
"SKETCH",
0, 0, 0, False,
0, Nothing,
0)
Part.EditSketch()
Part.ClearSelection2(True)
skSegment = Part.SketchManager.Create3PointArc(-0.033816,
0.016783, 0.0#, 0.055107, 0.016783, 0.0#, 0.016009, 0.025458, 0.0#)
Part.ClearSelection2(True)
boolstatus = Part.Extension.SelectByID2("Line1",
"SKETCHSEGMENT",
0.00202904300411839, 0.0119654152286464, -0.00709549576220667,
True, 0,
Nothing, 0)
boolstatus = Part.Extension.SelectByID2("Arc1",
"SKETCHSEGMENT",
0.00588878331207997, 0.0171023327681304, -0.0126221740799126,
True, 0,
Nothing, 0)
boolstatus = Part.SketchManager.SketchReplace(True)
Part.SketchManager.InsertSketch(True)
End
Sub
Public
swApp As
SldWorks
End
Class