AnsweredAssumed Answered

Drawing Font Updates

Question asked by Ian Chamberlin on Aug 2, 2019
Latest reply on Aug 15, 2019 by Ian Chamberlin

Greetings all.  I'm trying to update drawing font family, size, etc... via a macro and need a little help getting the VBA code sorted out.

 

The scenario here is that we updated our drawing templates recently and are using different fonts for notes, dimensions, etc... than we did on the older template.  When we process a change to these drawings we are updating to the new template but the fonts are not updating on the drawing to the newer type.  

 

For example, when I open up an old drawing it uses Century Gothic for both the Annotations and Dimensions font option under the Document Properties tab.  When I switch the drawing template to the new version the fonts are not updated to Arial which we are using in the new template.  If I create a drawing from scratch using the new format everything is in Arial as expected so I know the new template has the right settings.

 

It seems like the template remembers the old font settings from the format and just reuses them.  Since I can't figure out a way to force it to reread the format to get the new fonts I think I'm stuck with updating them all via macro code.  I also need to make sure that all notes, dimensions, etc... are set to use the default font otherwise they won't update properly even when I change the default font.  So I think I need a two part macro:  step one needs to select all dimensions, notes, etc... and set them to use the default font; step two needs to change the default font for the drawing.

 

I have code that is partially working for the step two.  I can set the font family but not the height, bolding, etc...  My code for that portion is as follows:

 

Option Explicit

 

Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim swDraw As SldWorks.DrawingDoc

 

Dim FontName As String
Dim retval As Boolean

 

Dim TextFormatObj As Object
Dim swTextFormat As SldWorks.TextFormat

 

Sub main()

 

Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc
Set swDraw = swModel

 

FontName = "Arial"

 

retval = ReplaceFont(swDetailingAnnotationTextFormat, FontName)
retval = ReplaceFont(swDetailingBalloonTextFormat, FontName)
retval = ReplaceFont(swDetailingBillOfMaterialTextFormat, FontName)
retval = ReplaceFont(swDetailingDatumTextFormat, FontName)
retval = ReplaceFont(swDetailingDetailLabelTextFormat, FontName)
retval = ReplaceFont(swDetailingDetailTextFormat, FontName)
retval = ReplaceFont(swDetailingDimensionTextFormat, FontName)
retval = ReplaceFont(swDetailingGeneralTableTextFormat, FontName)
retval = ReplaceFont(swDetailingGeometricToleranceTextFormat, FontName)
retval = ReplaceFont(swDetailingHoleTableTextFormat, FontName)
retval = ReplaceFont(swDetailingNoteTextFormat, FontName)
retval = ReplaceFont(swDetailingRevisionTableTextFormat, FontName)
retval = ReplaceFont(swDetailingSectionLabelTextFormat, FontName)
retval = ReplaceFont(swDetailingSectionTextFormat, FontName)
retval = ReplaceFont(swDetailingSurfaceFinishTextFormat, FontName)
retval = ReplaceFont(swDetailingTableTextFormat, FontName)
retval = ReplaceFont(swDetailingViewArrowTextFormat, FontName)
retval = ReplaceFont(swDetailingViewTextFormat, FontName)
retval = ReplaceFont(swDetailingWeldSymbolTextFormat, FontName)

 

End Sub

 

Function ReplaceFont(AName As swUserPreferenceTextFormat_e, Fname As String)
Set TextFormatObj = swModel.GetUserPreferenceTextFormat(AName)
Set swTextFormat = TextFormatObj
swTextFormat.TypeFaceName = Fname
ReplaceFont = swModel.SetUserPreferenceTextFormat(AName, swTextFormat)
End Function

 

I can't seem to find any code for step one that will allow me to set all dimensions, notes, etc... to use the default font.

 

Any help would be greatly appreciated.

Outcomes