Skip navigation
Currently Being Moderated

Text selection

Sep 24, 2012 9:19 PM

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.

 
Replies
  • Currently Being Moderated
    Sep 24, 2012 11:05 PM   in reply to Bill joy

    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

     
    |
    Mark as:
  • Currently Being Moderated
    Sep 24, 2012 11:54 PM   in reply to Bill joy

    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
     
    
     
    |
    Mark as:
  • Currently Being Moderated
    Sep 25, 2012 8:38 AM   in reply to Vamitul

    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.

     
    |
    Mark as:
  • Currently Being Moderated
    Sep 25, 2012 8:47 AM   in reply to rajesh2373

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

     
    |
    Mark as:
  • Currently Being Moderated
    Sep 25, 2012 11:13 AM   in reply to rajesh2373

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

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points