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.
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
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
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
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
Copy link to clipboard
Copied
Thanks Vamitul for reply
This work sucessfully.
Thanks
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.
Copy link to clipboard
Copied
Count the number of characters in "Adobe InDesign" ...
Copy link to clipboard
Copied
itemByRange is zero based so the counts goes 0, 1, 2, 3, ...
Copy link to clipboard
Copied
Hi rajesh2373
Count the number of characters in "Adobe InDesign"
start counting from 0,1,2,..............13.
last value is 13 not 14.