Pat Stanford 1,622 Posted January 6, 2012 The attached script will change the font of all text objects in a drawing, even objects that are part of a group, symbol or viewport annoation. A dialog box allows the user to select the desired font. Depending on how a PluginObject has been written it might or might not be able to change the font of text that is part of a PIO. Free for your use. BACKUP your file before use. No Warranty is Expressed or Implied. Do not operate heavy machinery while using this script. If a rash or sneezing develops for more than 4 hours consult a doctor immediately. Procedure ChangeAllFonts; {Changes the font of all text on a drawing to the selected font} {Traverses into groups, symbols and viewport annotations} {January 6, 2012} {? 2012, Coviana, Inc - Pat Stanford pat@coviana.com} {Licensed under the GNU Lesser General Public License} var Hd :Handle; Font :String; dInt :Integer; dReal :Real; Procedure ChangeFont(Hd:Handle); Begin if GetType(Hd)= 10 then begin SetTextFont(Hd, 0,len(gettext(Hd)),GetFontID(Font)); end end; Begin Font:='Arial'; FormatTextDialog(Font,dInt,dReal,dInt,dReal,dInt,dInt,62); ForEachObject(ChangeFont,(INSYMBOL & INOBJECT & INVIEWPORT & (ALL))); end; Run(ChangeAllFonts); Quote Share this post Link to post
Chris Brough 0 Posted January 23, 2018 works like a charm! only comment is that it doesn't seem to touch drawing labels. Quote Share this post Link to post
Andrew Lock 1 Posted February 16, 2020 Pat I know this is an old thread but is there any chance this script can be made to change all the sizes of the font as well? Many thanks Andrew Quote Share this post Link to post
MullinRJ 220 Posted February 17, 2020 (edited) Hi Andrew, I adapted Pat's script to also set the Point Size of the text. This will set all objects to the same size which could make some documents look weird. You could break the script into two scripts to give you more control. To just set the point size, comment out (or remove) the SetTextFont() command. You can also make the script work only on SELECTED text objects only by changing the "& ALL" to "& SEL" in the ForEachObject() command near the bottom. PROCEDURE ChangeAllFonts; { Changes the font of all text on a drawing to the selected font } { Traverses into groups, symbols and viewport annotations } { January 6, 2012 } { © 2012, Coviana, Inc - Pat Stanford pat@coviana.com } { Licensed under the GNU Lesser General Public License } { 17 February 2020 - R. Mullin } { Added ability to set the Point Size of all text objects at the same time. } { Same GNU License as above. } VAR Hd :Handle; Font :String; FontID, dInt :Integer; PointSize, dReal :Real; Procedure ChangeFont(Hd:Handle); Begin if (GetTypeN(Hd) = 10) then begin SetTextFont(Hd, 0, len(gettext(Hd)), GetFontID(Font)); SetTextSize(Hd, 0, len(gettext(Hd)), PointSize); end; End; BEGIN Font := 'Arial'; FormatTextDialog(Font, dInt, PointSize, dInt, dReal, dInt, dInt, 60); { correct Point Size ommission - RJM 7 Oct 2020 } ForEachObject(ChangeFont, INSYMBOL & INOBJECT & INVIEWPORT & ALL); END; Run(ChangeAllFonts); Raymond Edited October 7, 2020 by MullinRJ 1 Quote Share this post Link to post
Andrew Lock 1 Posted February 18, 2020 Thank you so much Raymond. This works well. Andrew Quote Share this post Link to post
Taproot 286 Posted October 7, 2020 @MullinRJ @Pat Stanford Is it possible to modify this script to replace a single font - rather than every font in the drawing? i.e. if the existing Font = "Arial" then replace it with "xxx" ? Our office formerly used a font that no longer functions properly. It was everywhere, inside symbols, etc. Rather than trying to replace every object one by one, we opted to re-map the font to a new one. (This was before Text Styles) This basically solved our problem. However, exported files revert back to the offending font, so the display goes wonky. It would be better to replace all instances of the corrupt font and scripting looks like the best way to do it. Quote Share this post Link to post
Taproot 286 Posted October 7, 2020 10 minutes ago, MullinRJ said: Yes, BRB, Raymond Excellent. I assume that I would need to modify this portion of the script to also limit the selection of objects based upon it's font. On 1/6/2012 at 12:17 PM, Pat Stanford said: Begin if GetType(Hd)= 10 then begin SetTextFont(Hd, 0,len(gettext(Hd)),GetFontID(Font)); end end; I see that Type 10 = Text Objects, but I don't know how to further limit the selection via font. Could you assist me in that regard? Quote Share this post Link to post
MullinRJ 220 Posted October 7, 2020 Hi @Taproot , 41 minutes ago, Taproot said: I see that Type 10 = Text Objects, but I don't know how to further limit the selection via font. Could you assist me in that regard? You have a good eye, but there is not an easy way in VS to describe how to determine the font assigned to a text block. Rather than try to guide you through it, I made the changes to the previous script and posted it below. As you can see, it still took me about an hour to do this and I still took the easy way out by only checking the first character of a text block to check the font assignment. See next paragraph. I modified the previous script to only change the font type of Arial text blocks. You can specify the font to be changed by changing the constant "kFontNm" at the top of the program. There is one caveat, this script assumes that if a text block starts with a character in the Arial font, the whole text block is Arial. This script does not change individual characters within a text block. That can be done, but requires a bit more time to code. <<< THIS SCRIPT IS LIGHTLY TESTED — VERY LIGHTLY TESTED. USE AT YOUR OWN RISK, AND PLEASE TRY IT ON A TEST FILE FIRST. >>> Also, I corrected a mistake in the previous script that did not pass back the point size in variable "PointSize" from the FormatTextDialog() procedure. That is now corrected in the above script and in the one posted below. If anyone finds any problems with this script, please write back and I'll have @PatStanford get right on it. 😉 PROCEDURE ChangeSomeFonts; { Changes the font of all text on a drawing to the selected font } { Traverses into groups, symbols and viewport annotations } { January 6, 2012 } { © 2012, Coviana, Inc - Pat Stanford pat@coviana.com } { Licensed under the GNU Lesser General Public License } { 17 February 2020 - R. Mullin } { Added ability to set the Point Size of all text objects at the same time. } { Same GNU License as above. } { 7 October 2020 - R. Mullin } { Only change Text Blocks with name specified in constant "kFontNm" to target font name "kNewFontNm". } { Same GNU License as above. } CONST kFontNm = 'Arial'; { change from this font name } VAR Hd :Handle; NewFontNm :String; FontID, dummyInt :Integer; PointSize, dummyReal :Real; Procedure ChangeFont(Hd :Handle); Var FID :Integer; Begin if (GetTypeN(Hd) = 10) then begin FID := GetTextFont(Hd, 0); { assumes all characters in txtBlk are the same fontID } if (FontID = FID) then begin SetTextFont(Hd, 0, len(GetText(Hd)), GetFontID(NewFontNm)); SetTextSize(Hd, 0, len(GetText(Hd)), PointSize); end; { if (FontID = FID) } end; { if GetTypeN() } End; { ChangeFont } BEGIN FontID := GetFontID(kFontNm); { existing FontID } FormatTextDialog(NewFontNm, dummyInt, PointSize, dummyInt, dummyReal, dummyInt, dummyInt, 60); ForEachObject(ChangeFont, INSYMBOL & INOBJECT & INVIEWPORT & ALL); END; Run(ChangeSomeFonts); HTH, Raymond Quote Share this post Link to post
Taproot 286 Posted October 7, 2020 Above and beyond Raymond! Yes, I'm glad you didn't try and talk me through it - that's definitely 'next level' stuff. I'll do some testing and let you know how it goes. 😃 Quote Share this post Link to post
Taproot 286 Posted October 8, 2020 @MullinRJ It worked perfectly! I deleted the Text Size substitution line (as I have different font sizes throughout the file) and it took care of it. I appreciate the assistance. 1 Quote Share this post Link to post
Andy Broomell 1,138 Posted March 24 Bump! Because this script is super useful. Also, it appears to work fine with the new Drawing Labels in 2021 🙂 1 Quote Share this post Link to post
shorter 323 Posted March 24 Extremely useful! Thanks, @Pat Stanford Quote Share this post Link to post
MattG 44 Posted Wednesday at 03:04 PM Not sure how I just saw this but this is awesome. I know I posted a "wish list" for something like this integrated into VW a long way back but just this is great. Long story short for me it helps in consistency when getting files from other incorporating into yours and suddenly text from .dwgs or other items don't all match. Super nice. Quote Share this post Link to post
Pat Stanford 1,622 Posted Wednesday at 03:55 PM Glad you think it is useful and thank you to Raymond for the enhancements. 1 Quote Share this post Link to post