MACRO LIBRARY

Get drawing note bounding box

Free public access. No account or subscription required.

Files

Get drawing bounding box

Code

Module: mMain

'Demonstrates how to get a note's bounding box using INote::GetExtent.
    
'Precondition: Note is selected in drawing.
'Results: See immediate window.
    
'Notes.
'-If you do not want the leader factored into the exten of the note, you _
    will need to turn off the leader using IAnnotation::SetLeader3.
'-INote::GetExtent causes SolidWorks to crash if SolidWorks is invisible. _
    (Last verified in early SP of SolidWorks 2015.)
    
'Written by Keith Rice
'CADSharp LLC
'www.cadsharp.com
    
Sub main()
    Dim swApp As SldWorks.SldWorks
    Dim swModel As SldWorks.ModelDoc2
    Dim swDraw As SldWorks.DrawingDoc
    Dim swView As SldWorks.View
    Dim swSelMgr As SldWorks.SelectionMgr
    Dim swNote As SldWorks.Note
    Dim dblScaleFactor As Double
    Dim vExtent As Variant
    Dim i As Integer
    
    Set swApp = Application.SldWorks
    Set swModel = swApp.ActiveDoc
    Set swDraw = swModel
    Set swView = swDraw.GetFirstView    'gets sheet
    
    dblScaleFactor = swView.ScaleDecimal
    
    Set swSelMgr = swModel.SelectionManager
    Set swNote = swSelMgr.GetSelectedObject6(1, -1)
    vExtent = swNote.GetExtent
    
    For i = 0 To UBound(vExtent)
        vExtent(i) = vExtent(i) / dblScaleFactor
    Next i
    
    Debug.Print "Lower left corner (m): ", Round(vExtent(0), 6), Round(vExtent(1), 6)
    Debug.Print "Upper right corner (m): ", Round(vExtent(3), 6), Round(vExtent(4), 6)
    Debug.Print "Height (m): ", Round(vExtent(4), 6) - Round(vExtent(1), 6)
    Debug.Print "Width (m): ", Round(vExtent(3), 6) - Round(vExtent(0), 6)
End Sub