- 'precondition: you must be inside a sketch to execute this macro
- Sub main()
- Dim swApp As SldWorks.SldWorks
- Dim swSketchSeg As SldWorks.SketchSegment
- Dim swModel As SldWorks.ModelDoc2
- Dim swSelMgr As SldWorks.SelectionMgr
- Dim swSketch As SldWorks.Sketch
- Dim vSketchSeg As Variant
- Dim i As Long
- Dim bRet As Boolean
- Dim swSelData As SldWorks.SelectData
- Dim vSketchPt As Variant
- Dim swSketchPt As SldWorks.SketchPoint
- Set swApp = Application.SldWorks
- Set swModel = swApp.ActiveDoc
- Set swSelMgr = swModel.SelectionManager
- Set swSketch = swModel.GetActiveSketch2
- Set swSelData = swSelMgr.CreateSelectData
- 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
- End Sub
This macro removes all restrictions in a sketch by cycling through each sketch segment in the currently opened 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. I use this macro a lot right after using the Convert Entities tool. Also,
if I want to quickly scale up an entire sketch it is easy enough to take note of a sketch dimension, run the DeleteRelations.swp macro,
then re dimension that sketch element.
This macro requires you to be inside a sketch in order to delete all constraints, relations, and dimensions. For a
macro that requires you to be outside a sketch in order to delete all constraints, check out DeleteRelations2.
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.