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

How to add superscript 2 as text in textGroupItem with Javascript

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(regPattern)){

                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
719
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

Maybe you should post over at

Illustrator Scripting

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, first question here so fairly new at this!

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

No problem, I expect some of the regulars might frequent both Fora anyway, but Scripting is a somewhat specialised option so the dedicated Scripting Forum may provide better and/or speedier feedback on the issue.

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 ,
May 17, 2018 May 17, 2018
LATEST

Hi marca12945532,

do you need further assistance?

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 Employee ,
May 10, 2018 May 10, 2018

moved to Illustrator Scripting

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 ,
May 10, 2018 May 10, 2018

Hi marca12945532​,

your snippet isn't complete.

That's why I can give you only one 'way to go':

var aDoc = app.activeDocument;

var aTF = aDoc.textFrames.add();

aTF.contents = "Lorem ipsum";

var regPattern= /ipsum/;

var txt = aTF.textRange.contents.replace(regPattern,"un -  sm m²");

aTF.textRange.contents = txt;

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