Jump to content
Pat Stanford

Change All Fonts in File

Recommended Posts

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);

Share this post


Link to post

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

Share this post


Link to post

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 by MullinRJ
  • Like 1

Share this post


Link to post

@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.

 

Share this post


Link to post
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?

 

Share this post


Link to post

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

 

Share this post


Link to post

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.

 

😃

Share this post


Link to post

@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.

Share this post


Link to post

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


 

7150 Riverwood Drive, Columbia, Maryland 21046, USA   |   Contact Us:   410-290-5114

 

© 2018 Vectorworks, Inc. All Rights Reserved. Vectorworks, Inc. is part of the Nemetschek Group.

×
×
  • Create New...