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.
OK... First, you need to be sure of the difference between a template and a sheet format.
It really sounds to me like you are changing the sheet format (the title block, all the default notes, etc), but you are NOT changing the template. The sheet format does NOT contain any font information (size, family, etc) for the document. The document font can only be accessed through Tools->Options, Document Properties tab. When you replace your template, does the font update under Tools->Options, Document Properties tab? If not, you are not replacing your template. You're replacing your sheet format. You can't really replace a template.
So... Once you "replace your template"... Does every note/dimension/etc. have the "Use Document" checkbox cleared in its font properties? If not, you don't need to select everything etc etc. You just need to use a macro to update the document font. Or you can manually update it in the Document PRoperties tab.
Your macro already changes the document font family... and it sounds like it already works to do that, right? You have 99.5% of what you need.
Right under swTextFormat.TypeFaceName = Fname, you just need a line that says swTextFormat.CharHeight = [whatever height you want - units are meters].