- 'preconditions: Exit all sketches and select a sketch from the Feature Manager Design Tree (Left Pane).
- Option Explicit
- Sub main()
- Dim swApp As SldWorks.SldWorks
- Dim swModel As SldWorks.ModelDoc2
- Dim swSelMgr As SldWorks.SelectionMgr
- Dim swFeat As SldWorks.Feature
- Dim swSketch As SldWorks.Sketch
- Dim vSketchSeg As Variant
- Dim swSketchSeg As SldWorks.SketchSegment
- Dim vSketchPt As Variant
- Dim swSketchPt As SldWorks.SketchPoint
- Dim swSelData As SldWorks.SelectData
- Dim i As Long
- Dim bRet As Boolean
- Set swApp = Application.SldWorks
- Set swModel = swApp.ActiveDoc
- Set swSelMgr = swModel.SelectionManager
- Set swSelData = swSelMgr.CreateSelectData
- Set swFeat = swSelMgr.GetSelectedObject6(1, 0)
- Set swSketch = swFeat.GetSpecificFeature2
- swModel.EditSketch
- vSketchSeg = swSketch.GetSketchSegments
- For i = 0 To UBound(vSketchSeg)
- Set swSketchSeg = vSketchSeg(i)
- bRet = swSketchSeg.Select4(False, swSelData): Debug.Assert bRet
- swModel.SketchConstraintsDelAll
- Next i
- vSketchPt = swSketch.GetSketchPoints2
- For i = 0 To UBound(vSketchPt)
- Set swSketchPt = vSketchPt(i)
- bRet = swSketchPt.Select4(False, swSelData): Debug.Assert bRet
- swModel.SketchConstraintsDelAll
- Next i
- swModel.InsertSketch2 True
- End Sub
You must exit all sketches to run this macro and you must have a sketch selected in the Feature Manager Design Tree
(left pane). This macro removes all restrictions in a sketch by cycling through each sketch segment in the currently selected sketch
and removing all constraints with the .SketchConstraintsDelAll function. Then the macro cycles through each sketch point and removes all
constraints, again using the .SketchConstraintsDelAll function. This macro removes all dimensions in the sketch. It removes all horizontal and
vertical restraints, all coincidence and anchor constraints.
This macro requires you to be outside a sketch in order to delete all constraints, relations, and dimensions. For a
macro that requires you to be inside a sketch to delete all constraints, check out DeleteRelations. Both DeleteRelations and DeleteRelations2 are modified versions of the
Delete All Constraints in Selected Sketch Example (VBA) found in the Solidworks API Online help.
Return to the SolidWorks VBA Macros page.
Return to the SolidWorks VBA Macros page.