This macro quickly check all the annotations on the active drawing sheet, automatically identifies the dangling ones, selects them, and provides a count of how many of them were found. This small macro can be a big time-saver for anyone working with complex drawings, helping ensure clarity and reducing errors before release.
Do you have a “delete dangling dimensions” macro that works with ordinate dimensions? I’ve tried a couple of macros over the years. One just ignores ordinate dimensions. The other will delete some, and if I run it again it will delete some more, but it takes 3 or 4 cycles to delete all of the dangling dimensions.
(I will provide more info on the macros I’ve tried when I get back to the office.)
I use the above macro only, and it works with the ordinate dimensions as well.
Just add following lines before the End if
swDraw.DeleteSelection (True)
swDraw.ClearSelection2 (True)
You may comment out the count message if you do not want the popup message.
Thanks. I will give it a try when I get back to work.
Great macro. This reminds me of the macro idea I had a while ago to repair broken references. You know how when you have a missing reference (for example a deleted plane), SW still shows it’s position..?
(In this instance - the outline)
I am wondering, since SW clearly saves some info of that deleted reference, is it possible to access the location of that missing reference via API somehow? If so, perhaps it would be possible to search geometry for other elements that are in the exact same position, and replace the missing reference with it. For example, you have a sketch on a face, then the face was recreated with another feature and the sketch plane reference got broken, but the macro would recognize that there is another face in the exact same position, and replace that reference. Same with sketch relations, mates, etc.
Does anyone know if this is possible?
This shows the same behavior as the other macro I’ve been using. Only some of the dangling ordinate dimensions are deleted.
It appears to only delete one view at a time.
The GIF is too big to upload.
Starting point.
Run Once
Run again
Run #3
DANGLING ORDINATE.SLDDRW (363.6 KB)
DANGLING ORDINATE.SLDPRT (811.6 KB)
I do not think that this would be easily feasible. I could not find anything related in the API helps files ![]()
Move this line
swDraw.DeleteSelection (True)
above
Set swView = swView.GetNextView
and then it should work for all the views on the active sheet (check attached video). I’m working on another macro which will work on all the sheets.
I haven’t done this yet, but as the starting face/plane is selected in the extrude feature property manager I would look first there:
use GetDefinition() to get the extrudeFeatureData2 of the feature;
then try the GetFromEntity Method (IExtrudeFeatureData2) which determines also the type:
- Surface
- Face
- Plane
- Vertex
- Sketch point
hope it helps you get in the right direction
I am looking into this, but what about sketches? In my example the missing plane was a sketch plane; and there doesn’t seem to be a way to call GetDefinition() for ISketch, unless I’m missing something. I can’t see anything related to sketch as an object in this list either, which lists FeatureData types.
The sketch plane is retrieved using GetReferenceEntity.
Yeah, but that one doesn’t return anything if the reference plane is missing, while SW clearly saves some info on that plane, as can be seen from my screenshot. Maybe it is not accessible via API after all…
It does remember where the plane was. You can still access that info from the ModelToSketchTransform. Note that the reference will also be reported as missing if the face has been removed due to a modeling operation further down in the feature tree. The API help recommends putting the sketch into edit mode (which rolls back the feature tree) before checking the plane reference in order to verify if it’s really lost or just no longer present in the fully rebuilt model.
Dim swSketch As SldWorks.Sketch
Dim swSels As SldWorks.SelectionMgr
Dim swXform As SldWorks.MathTransform
Dim swMath As SldWorks.MathUtility
Dim oRef As Object
Dim nType As Long
Dim swVec As SldWorks.MathVector
Dim dVec(2) As Double
Sub main()
Set swApp = Application.SldWorks
Set swDoc = swApp.ActiveDoc
Set swSels = swDoc.SelectionManager
If swSels.GetSelectedObjectType3(1, -1) = swSelSKETCHES Then
Set swFeat = swSels.GetSelectedObject6(1, -1)
Debug.Print swFeat.Name
'Get reference entity type and whether or not it still exists
Set swSketch = swFeat.GetSpecificFeature2
Set oRef = swSketch.GetReferenceEntity(nType)
Debug.Print , "Plane reference type: " & nType, "Reference missing: " & (oRef Is Nothing)
'Get the location of the sketch origin
Set swXform = swSketch.ModelToSketchTransform.Inverse
Debug.Print , "Origin: " & swXform.ArrayData(9), swXform.ArrayData(10), swXform.ArrayData(11)
'Get the normal vector of the sketch
Set swMath = swApp.GetMathUtility
dVec(0) = 0
dVec(1) = 0
dVec(2) = 1
Set swVec = swMath.CreateVector(dVec)
Set swVec = swVec.MultiplyTransform(swXform)
Debug.Print , "Normal: " & swVec.ArrayData(0), swVec.ArrayData(1), swVec.ArrayData(2)
Else
MsgBox "Select a sketch and run again"
End If
End Sub







