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

[ Branched ] Select Character and replace font?

Participant ,
Nov 18, 2020 Nov 18, 2020

Copy link to clipboard

Copied

Hi, this is great, but I can only get it to work on the first character of the regex I input i.e. I need to change 'EN' to another font so have used 'var reg = /EN/g;' but it only seems to change the 'E' and not the 'N' to my desired font.

 

How would I get around this issue?

[ branched from Select Character and replace font? by moderator ]

 

TOPICS
Scripting

Views

202

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 1 Correct answer

Community Expert , Nov 18, 2020 Nov 18, 2020

Your own script snippet only changes the first occurrence of your search string in a text frame.


The problem is: For the solution in the other thread, we didn't need all the properties of reg.exec ()

But we absolutely need the properties for your request.

 

Try the following:

// regex_textRange_changeFormattingOfString.jsx
// regards pixxxelschubser

var aDoc = app.activeDocument;
var aTF = aDoc.textFrames[0];
var reg = /EN/g;
var res = null;
var aCon = null;
while (res = reg.exec(aTF.contents))
...

Votes

Translate

Translate
Adobe
Participant ,
Nov 18, 2020 Nov 18, 2020

Copy link to clipboard

Copied

I have temporarily got around the issue by doing the following, but thisis far from ideal. Is anyone able to help me on how to do this in the correct manner? Many thanks in advance:



var aDoc = app.activeDocument;
var aTF = aDoc.textFrames[0];
var reg = /EN/g;
var res = reg.exec(aTF.contents);
idx1 = res.index;
idx2 = res.index+1;
aTF.characters[idx1].textFont = app.textFonts.getByName("ArialMT");
aTF.characters[idx2].textFont = app.textFonts.getByName("ArialMT");

 

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 ,
Nov 18, 2020 Nov 18, 2020

Copy link to clipboard

Copied

Your own script snippet only changes the first occurrence of your search string in a text frame.


The problem is: For the solution in the other thread, we didn't need all the properties of reg.exec ()

But we absolutely need the properties for your request.

 

Try the following:

// regex_textRange_changeFormattingOfString.jsx
// regards pixxxelschubser

var aDoc = app.activeDocument;
var aTF = aDoc.textFrames[0];
var reg = /EN/g;
var res = null;
var aCon = null;
while (res = reg.exec(aTF.contents)) {
    aCon = aTF.characters[res.index];
    aCon.length = res[0].length;
    aCon.textFont = app.textFonts.getByName("ArialMT");
    }

 

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 ,
Nov 19, 2020 Nov 19, 2020

Copy link to clipboard

Copied

LATEST

Thank you so much for this, it is exactly what I was after. Greatly appreciated.

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