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

Text selection

Guest
Sep 24, 2012 Sep 24, 2012

Copy link to clipboard

Copied

Hi All

I want to apply underline on selected text but when i select text with itemByRange() then text not selected.

itemByRange() return array of characters.when i store array of characters in var type variable character and try to

underline then it give error object is invalid in line 7.In which type of  variable I store character of array. I also try array type of variable but not sucess.How select text ?

var myDocument = app.documents.add();

var myTextFrame = myDocument.pages.item(0).textFrames.add();

myTextFrame.geometricBounds = ["10p", "15p", "30p", "35p"];

myTextFrame.contents = "Adobe Indesign";

var character=myTextFrame.characters.itemByRange(7,14); // for selection of Indesign in "Adobe Indesign"

character.underline=true;   // error object is invalid

Thanks.

TOPICS
Scripting

Views

1.6K

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

Advisor , Sep 24, 2012 Sep 24, 2012

try counting from 0!!!

try this:

var myDocument = app.documents.add();

var myTextFrame = myDocument.pages.item(0).textFrames.add();

myTextFrame.geometricBounds = ["10p", "15p", "30p", "35p"];

myTextFrame.contents = "Adobe Indesign";

var character=myTextFrame.characters.itemByRange(6,13); // for selection of Indesign in "Adobe Indesign"

character.underline=true;   // error object is invalid

Votes

Translate

Translate
Advisor ,
Sep 24, 2012 Sep 24, 2012

Copy link to clipboard

Copied

the "itemByRange()" returns a ARRAY of objects.

to underline them you can either iterate the array and underline every character individualy, or use myTextFrame.texts

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
Guest
Sep 24, 2012 Sep 24, 2012

Copy link to clipboard

Copied

Thanks Vamitul for reply

When I try to underline every character individualy using

character[0].underline=true;

It give error Object does not support the property or method '0'.

I also try this :

var character = new Array();

character =myTextFrame.characters.itemByRange(7,14);

character[0].underline=true;  // error Object does not support the property or method '0'.

But give error.

Which type of variable store characters array ?

I try this but give same error

var text =myTextFrame.texts.itemByRange(7,14);

text.underline=true;  // error object is invalid

How select a text range and underline this?

Thanks

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
Advisor ,
Sep 24, 2012 Sep 24, 2012

Copy link to clipboard

Copied

try counting from 0!!!

try this:

var myDocument = app.documents.add();

var myTextFrame = myDocument.pages.item(0).textFrames.add();

myTextFrame.geometricBounds = ["10p", "15p", "30p", "35p"];

myTextFrame.contents = "Adobe Indesign";

var character=myTextFrame.characters.itemByRange(6,13); // for selection of Indesign in "Adobe Indesign"

character.underline=true;   // error object is invalid

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
Guest
Sep 25, 2012 Sep 25, 2012

Copy link to clipboard

Copied

Thanks Vamitul for reply

This work sucessfully.

Thanks

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
New Here ,
Sep 25, 2012 Sep 25, 2012

Copy link to clipboard

Copied

Hi

Iam new to javascript can you explain how this coding has been worked by changing "itemByRange(6,13)" instead of "itemByRange(7,14)". If anyone knows please explain.

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 ,
Sep 25, 2012 Sep 25, 2012

Copy link to clipboard

Copied

Count the number of characters in "Adobe InDesign" ...

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 ,
Sep 25, 2012 Sep 25, 2012

Copy link to clipboard

Copied

itemByRange is zero based so the counts goes 0, 1, 2, 3, ...

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
Guest
Sep 25, 2012 Sep 25, 2012

Copy link to clipboard

Copied

LATEST

Hi rajesh2373

Count the number of characters in "Adobe InDesign"

start counting from 0,1,2,..............13.

last value is 13 not 14.

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