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

Insert superscript 2 in text field Illustrator Javascript scripting

New Here ,
Mar 26, 2018 Mar 26, 2018

Dear All,

I've been trying to add and remove certain pieces of text based on their font and whenever I need to add a certain piece of text back into it's original place again I need to insert a superscript 2 after this text.

This is the piece of code in which I add the text back in again:

if (textGroupItem.textRange.characterAttributes.textFont.toString().toLowerCase().match(regP attern)){

                textGroupItem.textRange.characters.removeAll()

                textGroupItem.textRange.characters.add(un + " - " + sm + "m" + "²")

}

This doens't give a superscript 2 but some kind of broken token as text.

So far i've also tried:

- translatePlaceholderText("c2b2")

- "2".sup()

-  <sup> 2</sup>

- textGroupItem.textRange.characterAttributes.baselineShift = height;  <-- height = 2 but this shifts the whole text item

How can you succesfully add a supercript 2 to a group of characters?

TOPICS
Scripting
1.1K
Translate
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
Adobe
Community Expert ,
Mar 26, 2018 Mar 26, 2018

Here is a basic code of superscript.

app.selection[0].characters[1].characterAttributes.baselinePosition = FontBaselineOption.SUPERSCRIPT;

スクリーンショット 2018-03-26 19.23.04.png

Translate
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
New Here ,
Mar 26, 2018 Mar 26, 2018

Thanks a lot for this code. I can see that the baseline position of the text item is indeed NORMALBASELINE


But if I try to execute the code last character  of the text with: textGroupItem.textRange.characters[-1]

I get that this is undefined.

Is it possible to acess this last character and change just the baseline of that character?

Translate
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 ,
Mar 26, 2018 Mar 26, 2018
LATEST

Hi marca12945532,

unfortunately, Illustrator Scripting is a bit more complicated in this regard.

One possibility

var aDoc = app.activeDocument;

aDoc.textFrames[0].textRange.characters[aDoc.textFrames[0].textRange.characters.length-1].characterAttributes.baselinePosition = FontBaselineOption.SUPERSCRIPT;

Have fun

Translate
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