• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

How to change the font type for a specific frame using script??

Participant ,
Aug 27, 2020 Aug 27, 2020

Copy link to clipboard

Copied

Hey all! 

 

I've a doc full of diffranet textframes, and i want to change the font type for a scpicif textframe, how to do it?

I've used this code, it's good and works but change all the text frames, and i want to change only a spicifed frame!

The code

		app.findTextPreferences=app.changeTextPreferences= NothingEnum.nothing;

app.findTextPreferences = app.changeTextPreferences = NothingEnum.nothing;

app.findTextPreferences.appliedFont = app.fonts.item("Times New Roman MT Std Bold");////Here you can specify your old font name

app.changeTextPreferences.appliedFont = app.fonts.item("Times New Roman Italic");////Here you can specify your NEW font name

doc.changeText();
		

 

and lets say that the frame i want to change 

	var rect2 = doc.pages[0].textFrames.add({
		geometricBounds: [12.7, 12.7, 90, 90]
	});

		rect2.contents = "wooow"

 

and thanks all!

TOPICS
Activation billing and install , Bug , EPUB , Feature request , How to , Import and export , InCopy workflow , Performance , Print , Publish online , Scripting , SDK , Sync and storage , Type

Views

648

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 2 Correct answers

Community Expert , Aug 27, 2020 Aug 27, 2020

What is the font that you are using? Is it installed on the system or document fonts folder?

Try changing the code to the following

rect.texts[0].appliedFont = "Times New Roman"
rect.texts[0].fontStyle = "Bold"

-Manan 

Votes

Translate

Translate
Community Expert , Aug 27, 2020 Aug 27, 2020

—once i type the name in the code

 

The name string has to be exact including any whitespace characters, so maybe try this variation on Manan’s suggestion and copy and paste the text from the alert dialog rather than typing the name—appliedFont is the family and style usually separated by a tab

 

 

 

//note that I’m getting the appliedFont.name and not appliedFont.fontFamily
alert(app.selection[0].texts[0].appliedFont.name)

//the appliedFont is the font name and style with a tab separating the 
...

Votes

Translate

Translate
Community Expert ,
Aug 27, 2020 Aug 27, 2020

Copy link to clipboard

Copied

If you have the reference of the text frame you don't need to use the find change, just change the font like the following

rect.texts[0].appliedFont = app.fonts.item("Times New Roman MT Std Bold")

-Manan 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Aug 27, 2020 Aug 27, 2020

Copy link to clipboard

Copied

The font i use is installed, so when i use the code that i've posted it works and change the font, but when id ur code and write the family font, it alerrt me that the requested font family is unaviliable.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advisor ,
Aug 27, 2020 Aug 27, 2020

Copy link to clipboard

Copied

Hello,

 

You can give this a try.

var rect2 = doc.pages[0].textFrames.add({
    geometricBounds: [12.7, 12.7, 90, 90]
});

rect2.contents = "wooow"
rect2 = myYTextFrame.parentStory.characters.everyItem();
rect2.appliedFont = app.fonts.item("Helvetica Neue");
rect2.fontStyle = "Medium";  

Regards,

Mike

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Aug 27, 2020 Aug 27, 2020

Copy link to clipboard

Copied

There is error (

myYTextFrame

is undefined)

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advisor ,
Aug 27, 2020 Aug 27, 2020

Copy link to clipboard

Copied

Sorry....

var rect2 = doc.pages[0].textFrames.add({
    geometricBounds: [12.7, 12.7, 90, 90]
});

rect2.contents = "wooow"
myTextObject = rect2.parentStory.characters.everyItem();
myTextObject.appliedFont = app.fonts.item("Helvetica Neue");
myTextObject.fontStyle = "Medium"; 

Regards,

Mike

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Aug 27, 2020 Aug 27, 2020

Copy link to clipboard

Copied

It works, but only with the bulit in fonts (i,e)

Times New Roman

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Aug 27, 2020 Aug 27, 2020

Copy link to clipboard

Copied

Try something like the following

rect.texts[0].appliedFont = app.fonts.item("Times New Roman")
rect.texts[0].fontStyle = "Bold"

-Manan

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Aug 27, 2020 Aug 27, 2020

Copy link to clipboard

Copied

It works, but i think because 

Times New Roman

is a built-in font type. When i use mine, the installed one, it alert me that the requested font are unavaible. The weird thing when i replac the font from the UI not the script it wokrs!  

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Aug 27, 2020 Aug 27, 2020

Copy link to clipboard

Copied

Apply your font using the UI, select the frame and run the following code

alert(app.selection[0].texts[0].appliedFont.fontFamily)

This should give you the name of the font family that is to be used in the code I gave previously.

-Manan

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Aug 27, 2020 Aug 27, 2020

Copy link to clipboard

Copied

indeed yes it gave me the name, and once i type the name in the code and specify the style, it alerts me that the requested font un available

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Aug 27, 2020 Aug 27, 2020

Copy link to clipboard

Copied

What is the font that you are using? Is it installed on the system or document fonts folder?

Try changing the code to the following

rect.texts[0].appliedFont = "Times New Roman"
rect.texts[0].fontStyle = "Bold"

-Manan 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Aug 27, 2020 Aug 27, 2020

Copy link to clipboard

Copied

I'm using a special font for my company, and yes it's installed in the system. still same issue. the furstrating thing that i can change the font and found the font family from the UI !

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advisor ,
Aug 27, 2020 Aug 27, 2020

Copy link to clipboard

Copied

Can you share\post the "special font" for testing?

 

Regards,

Mike

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Aug 31, 2020 Aug 31, 2020

Copy link to clipboard

Copied

LATEST

it's for my company, but it works now. apperntly there was a tab space i didn't recognize it.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Aug 27, 2020 Aug 27, 2020

Copy link to clipboard

Copied

—once i type the name in the code

 

The name string has to be exact including any whitespace characters, so maybe try this variation on Manan’s suggestion and copy and paste the text from the alert dialog rather than typing the name—appliedFont is the family and style usually separated by a tab

 

 

 

//note that I’m getting the appliedFont.name and not appliedFont.fontFamily
alert(app.selection[0].texts[0].appliedFont.name)

//the appliedFont is the font name and style with a tab separating the name and style so try copying from the alert
app.selection[0].texts[0].appliedFont = "Myriad Pro	Regular"

 

 

 

Screen Shot 41.png

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Aug 31, 2020 Aug 31, 2020

Copy link to clipboard

Copied

THANKS rob!!! it works perfictly! i didn't now about the tab! THANKS A LOT

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines