AnsweredAssumed Answered

Why is this macro missing certain annotations?

Question asked by Steven Soeder on Aug 21, 2018
Latest reply on Aug 22, 2018 by Alex Burnett

I wrote a Macro to update existing drawings to our new drawing standard.  It's supposed to load the drawing standard and then go in and set all the notes, dimensions, etc. to use the default font, but it always seems to miss a few.  I would say it typically works on about 90% of annotations (including dimensions, notes, tables, title block, etc. - and it does work on all pages in multi-page documents) but there are always a handful that it seems to "miss" - i.e. there are always a few notes or tables that don't get set to use the default font.

 

I'm not really sure why this would be - can anyone help me figure out what I'm missing?

 

Thanks!

 

Option Explicit
    Dim swApp As SldWorks.SldWorks
    Dim swModel As SldWorks.ModelDoc2
    Const drawStd As String = "C:\MyFolder\MyStandard.sldstd"




Sub main()
    Set swApp = Application.SldWorks
    Set swModel = swApp.ActiveDoc
    Dim theReturn As Boolean
    
    If swModel.GetType <> 3 Then MsgBox "active document is not a solidworks drawing": Exit Sub
    
    theReturn = swModel.Extension.LoadDraftingStandard(drawStd)
    
    Dim theFeat As SldWorks.Feature
    Set theFeat = swModel.FirstFeature
    
    Do While Not theFeat Is Nothing
    
        If "DrSheet" = theFeat.GetTypeName Then
        
            swModel.ActivateSheet theFeat.Name
            Call getnote
            
        End If
        
        Set theFeat = theFeat.GetNextFeature
    
    Loop


End Sub


Sub getnote()
    Dim theFormat As SldWorks.TextFormat
    Dim theDraw As SldWorks.DrawingDoc
    Dim theView As SldWorks.View
    Dim theNote As SldWorks.Note
    Dim theAnn As SldWorks.Annotation
    Dim theReturn As Boolean
    Dim i As Long
        
    
    Set theDraw = swModel
    Set theView = theDraw.GetFirstView
    Set theNote = theView.GetFirstNote
    swModel.ClearSelection2 (True)
    
    Do While Not theNote Is Nothing
    
        Set theAnn = theNote.GetAnnotation
        theReturn = theAnn.Select2(True, 0)
        Debug.Assert theReturn
        'theReturn = theAnn.ApplyDefaultStyleAttributes()
        For i = 0 To theAnn.GetTextFormatCount - 1
            Set theFormat = theAnn.GetTextFormat(i)
            theReturn = theAnn.SetTextFormat(i, True, theFormat)
        Next
        Set theNote = theNote.GetNext
    Loop
   
End Sub

Outcomes