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

inserting unicode characters around selected text

Explorer ,
Feb 10, 2017 Feb 10, 2017

Hi, I select some text and use this two lines to add two characters before and after my selected text, it works but the selected text changes and includes one of the added characters. How can I add these tho characters and have the selection stay the same?

app.selection[0].insertionPoints[-1].contents = "\u0041";
app.selection[0].insertionPoints[0].contents = "\u0042";
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

correct answers 1 Correct answer

Mentor , Feb 10, 2017 Feb 10, 2017

Hi,

Store some properties before changes and use them:

var

    mText = app.selection[0].texts[0],

    len = mText.length;

mText.insertionPoints[-1].contents = "\u0041";  

mText.insertionPoints[0].contents = "\u0042";

mText = app.selection[0].texts[0];

mText.characters.itemByRange(0,len-1).select();

Jarek

Translate
Mentor ,
Feb 10, 2017 Feb 10, 2017

Hi,

Store some properties before changes and use them:

var

    mText = app.selection[0].texts[0],

    len = mText.length;

mText.insertionPoints[-1].contents = "\u0041";  

mText.insertionPoints[0].contents = "\u0042";

mText = app.selection[0].texts[0];

mText.characters.itemByRange(0,len-1).select();

Jarek

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
Explorer ,
Feb 11, 2017 Feb 11, 2017

Thank you!

Can I apply a certain character style to only these two added characters?

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
Mentor ,
Feb 11, 2017 Feb 11, 2017

Hi,

A property 'index' can be helpful:

var

    mText = app.selection[0].texts[0],

    mIndex = mText.index,

    len = mText.length,

    mStory = mText.parentStory,

    CSt1 = app.activeDocument.characterStyles.item("A"),

    CSt2 = app.activeDocument.characterStyles.item("B");

mText.insertionPoints[-1].contents = "\u0041";  

mText.insertionPoints[0].contents = "\u0042";

mText = app.selection[0].texts[0];

mStory.characters[mIndex].appliedCharacterStyle = CSt1;

mStory.characters[mIndex+len+1].appliedCharacterStyle = CSt2;

mText.characters.itemByRange(0,len-1).select();

Jarek

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
Explorer ,
Feb 13, 2017 Feb 13, 2017

Thank you, it works on main text but doesn't apply the styles when i select some text in footnotes and run the script..

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 ,
Feb 14, 2017 Feb 14, 2017

Hi,

because if you are using parentStory of a text selection in a footnote text you will get the story that is holding the footnote.
And not the footnote itself. For that you need simply parent. Same with text selected in table cells.

What should work (not tested):

mStory = mText.parent,

Regards,
Uwe

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
Explorer ,
Feb 14, 2017 Feb 14, 2017
LATEST

Yes, it works now

Thank you very much..

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