Pat Stanford Posted January 6, 2012 Share 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 Link to comment
Chris Brough Posted January 23, 2018 Share Posted January 23, 2018 works like a charm! only comment is that it doesn't seem to touch drawing labels. Quote Link to comment
Andrew Lock Posted February 16, 2020 Share 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 Link to comment
MullinRJ Posted February 17, 2020 Share 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 Link to comment
Andrew Lock Posted February 18, 2020 Share Posted February 18, 2020 Thank you so much Raymond. This works well. Andrew Quote Link to comment
Taproot Posted October 7, 2020 Share 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 Link to comment
Taproot Posted October 7, 2020 Share 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 Link to comment
MullinRJ Posted October 7, 2020 Share 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 Link to comment
Taproot Posted October 7, 2020 Share 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 Link to comment
Taproot Posted October 8, 2020 Share 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 Link to comment
Andy Broomell Posted March 24, 2021 Share Posted March 24, 2021 Bump! Because this script is super useful. Also, it appears to work fine with the new Drawing Labels in 2021 🙂 1 Quote Link to comment
shorter Posted March 24, 2021 Share Posted March 24, 2021 Extremely useful! Thanks, @Pat Stanford Quote Link to comment
MattG Posted April 7, 2021 Share Posted April 7, 2021 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 Link to comment
Pat Stanford Posted April 7, 2021 Author Share Posted April 7, 2021 Glad you think it is useful and thank you to Raymond for the enhancements. 2 Quote Link to comment
DianaK Posted March 15, 2022 Share Posted March 15, 2022 Pat, You will never know just how much time you saved us. Thank you. Quote Link to comment
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.