Highlighted

script for finding the font indices

Community Beginner ,
Jun 03, 2020

Copy link to clipboard

Copied

fonts of a text frame are associated with the index or something like position of text. the problem is that when i replace a frame with another text the other text takes the same font as the original text in text frame(because fonts are assigned on the basis of locaation).how can i keep a track that this font is there in this bound and how can i retain the font of replaced text instead of default assignment to the font of original text.actulally i want to ask is that how can i get the area range of given font so that i can do some manipulations or hiow can i maintain the font of replaced text.

Adobe Community Professional
Correct answer by brianp311 | Adobe Community Professional

Not sure I quite understand the question, but you can capture the applied font of text objects with obj.appliedFont, ie: 

var currFont = app.activeDocument.textFrames[0].texts[0].appliedFont;

You can also use app.findGrep() to find all sets of text with a particular font and replace it with a different font: 

 

app.findTextPreferences = NothingEnum.NOTHING; 
app.findTextPreferences.appliedFont = "Font to find"; 
var myFinds = app.findText(); //returns an array of Text objects that match the font.

 

So, you can store the existing font in a variable, change some text, then apply the stored font to the changed text. Of course, using Paragraph and Character Styles is much more flexible and powerful, and the better way to go. 

Topics

Scripting

Views

370

Likes

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

script for finding the font indices

Community Beginner ,
Jun 03, 2020

Copy link to clipboard

Copied

fonts of a text frame are associated with the index or something like position of text. the problem is that when i replace a frame with another text the other text takes the same font as the original text in text frame(because fonts are assigned on the basis of locaation).how can i keep a track that this font is there in this bound and how can i retain the font of replaced text instead of default assignment to the font of original text.actulally i want to ask is that how can i get the area range of given font so that i can do some manipulations or hiow can i maintain the font of replaced text.

Adobe Community Professional
Correct answer by brianp311 | Adobe Community Professional

Not sure I quite understand the question, but you can capture the applied font of text objects with obj.appliedFont, ie: 

var currFont = app.activeDocument.textFrames[0].texts[0].appliedFont;

You can also use app.findGrep() to find all sets of text with a particular font and replace it with a different font: 

 

app.findTextPreferences = NothingEnum.NOTHING; 
app.findTextPreferences.appliedFont = "Font to find"; 
var myFinds = app.findText(); //returns an array of Text objects that match the font.

 

So, you can store the existing font in a variable, change some text, then apply the stored font to the changed text. Of course, using Paragraph and Character Styles is much more flexible and powerful, and the better way to go. 

Topics

Scripting

Views

371

Likes

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
Adobe Community Professional ,
Jun 04, 2020

Copy link to clipboard

Copied

Not sure I quite understand the question, but you can capture the applied font of text objects with obj.appliedFont, ie: 

var currFont = app.activeDocument.textFrames[0].texts[0].appliedFont;

You can also use app.findGrep() to find all sets of text with a particular font and replace it with a different font: 

 

app.findTextPreferences = NothingEnum.NOTHING; 
app.findTextPreferences.appliedFont = "Font to find"; 
var myFinds = app.findText(); //returns an array of Text objects that match the font.

 

So, you can store the existing font in a variable, change some text, then apply the stored font to the changed text. Of course, using Paragraph and Character Styles is much more flexible and powerful, and the better way to go. 

Likes

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
Reply
Loading...
Community Beginner ,
Jun 05, 2020

Copy link to clipboard

Copied

var currFont = app.activeDocument.textFrames[0].texts[0].appliedFont;
this line is giving currFont value as [object Font] but how to find exact font that is applied on text?

Likes

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
Reply
Loading...
Community Beginner ,
Jun 05, 2020

Copy link to clipboard

Copied

sorry got the answer...thank you so much 

Likes

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
Reply
Loading...
Adobe Community Professional ,
Jun 06, 2020

Copy link to clipboard

Copied

You should read about textstyleranges and insertionpoints. See an example where its discussed how to change formatting in a section of text. This shows the use of the insertionPoints collection

https://community.adobe.com/t5/indesign/lt-indesign-gt-script-to-change-font-partly-with-javascript/...

textStyleRanges can be considered as a continous block of text that has the same formatting, so a paragraph can have multiple textStyleRanges or a single, depending upon if it has style overrides or has character styles applied over its text.

 

-Manan

 

Likes

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
Reply
Loading...