DeleteRelations.bmp
DeleteRelations.swp
  1.  
  2. 'precondition: you must be inside a sketch to execute this macro
  3.  
  4. Sub main()
  5. Dim swApp As SldWorks.SldWorks
  6. Dim swSketchSeg As SldWorks.SketchSegment
  7. Dim swModel As SldWorks.ModelDoc2
  8. Dim swSelMgr As SldWorks.SelectionMgr
  9. Dim swSketch As SldWorks.Sketch
  10. Dim vSketchSeg As Variant
  11. Dim i As Long
  12. Dim bRet As Boolean
  13. Dim swSelData As SldWorks.SelectData
  14. Dim vSketchPt As Variant
  15. Dim swSketchPt As SldWorks.SketchPoint
  16. Set swApp = Application.SldWorks
  17. Set swModel = swApp.ActiveDoc
  18. Set swSelMgr = swModel.SelectionManager
  19. Set swSketch = swModel.GetActiveSketch2
  20. Set swSelData = swSelMgr.CreateSelectData
  21. vSketchSeg = swSketch.GetSketchSegments
  22. For i = 0 To UBound(vSketchSeg)
  23. Set swSketchSeg = vSketchSeg(i)
  24. bRet = swSketchSeg.Select4(False, swSelData): Debug.Assert bRet
  25. swModel.SketchConstraintsDelAll
  26. Next i
  27. vSketchPt = swSketch.GetSketchPoints2
  28. For i = 0 To UBound(vSketchPt)
  29. Set swSketchPt = vSketchPt(i)
  30. bRet = swSketchPt.Select4(False, swSelData): Debug.Assert bRet
  31. swModel.SketchConstraintsDelAll
  32. Next i
  33. End Sub
  34.  

    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.