Copy link to clipboard
Copied
Dear friend,
I need to find all line last character and fill color (No need to words last character).
My code problem: Without space in the last character is not fill color.
My code is below:
var myDocument = app.activeDocument;
var myLine = myDocument.stories.everyItem().lines.everyItem().getElements();
for(i=0; i<myLine.length; i++)
{
var myCon = myLine.texts[0].contents;
if(myCon.match(/\n| /gi) != null){
try{
if(myLine.characters.item(-2).fillColor = myDocument.colors[2]);
}catch(e){}
}
}
My screenshot also below:
Please suggest friend,
Thanks in Advance
KS
add an 'if else' statement to apply the fill color to the second to last character only if the last character is a space. else apply the fill color to the last character.
var myDocument = app.activeDocument;
var myLine = myDocument.stories.everyItem().lines.everyItem().getElements();
for(i=0; i<myLine.length; i++)
{
var myCon = myLine.texts[0].contents;
if(myCon.match(/\n| /gi) != null){
try{
if(myLine.characters.item(-1).contents == " "){
...
Copy link to clipboard
Copied
I need output file. Please see below screen shot:
Thanks in Advance
KS
Copy link to clipboard
Copied
add an 'if else' statement to apply the fill color to the second to last character only if the last character is a space. else apply the fill color to the last character.
var myDocument = app.activeDocument;
var myLine = myDocument.stories.everyItem().lines.everyItem().getElements();
for(i=0; i<myLine.length; i++)
{
var myCon = myLine.texts[0].contents;
if(myCon.match(/\n| /gi) != null){
try{
if(myLine.characters.item(-1).contents == " "){
myLine.characters.item(-2).fillColor = myDocument.colors[2];
}else myLine.characters.item(-1).fillColor = myDocument.colors[2];
}catch(e){};
}
}
Copy link to clipboard
Copied
Hi Skemicle,
Thanks to your replay,
Your coding working fine.
One more question: How to match 1st line last character, 2nd line last characters and 3rd line last characters?
Exp:
Last 1st line character >> a
Last 2nd line character >> a
Last 3rd line character >> a
Please suggest friend
Thanks in Advance
Ks
Copy link to clipboard
Copied
Your lines are scripted as myLine for each individual line you will replace the with the index number of each line (keep in mind that javascript starts with an index of 0. (eg. line 1 would be myLine[0], line 2 would be myLine[1], etc.) This will specify that everything in this line of code will be confined to that line. (eg. myLine[1].characters matches all characters but only within line 2. To determine which character is the same as determining the line, myLine[1].characters[0] being 1st character, to get to the end of a line use the [- ] since javascript is confined to this line it will loop backwards to the end of the line and you can then set how far from the end of the line you want to match the character (myLine[1].characters[-1] will be the last character, [-2] the second to last, etc.)
Copy link to clipboard
Copied
Hi SK,
Thanks to your suggestion.
Quick Replay: please go my link and see my code. i am going right way? please suggest.
Thanks in Advance
KS