(Retitled from "Please help me!!" by John Hawkinson)
Hi All,
I want to indesign add 2 number per every entry in content or index with javascript
For Example
2, 9, 10-12, 30-33, 45-48
I want this type of result:
4, 11, 12-14, 32-35, 47-50
Please help me please send me javascript ASASP
This is the your 4th post with the subject line "Please help me" (with varying exclamation points.)
Please do not do this.
If everyone did this, the forum would be completely useless.
Please use the subject line to describe and summarize the intent of your post. Do not say "please help me." Of course everyone wants help.
I will retitle this thread.
I can't understand what you are asking. Perhaps you could restate your question with more words, and perhaps a screenshot or a more clear example.
Manish: It sounds like there's a much better way! Is the problem that you have your pages numbered wrong in the body of the document? You can change the starting page number of the document (or a subset thereof) by selecting the starting page icon in the Pages panel, and choose Numbering and Section options.
You should be able to correct your page numbering problems in that way.
I had this one under my sleeve
Select the text and then run the script
#target indesign
app.doScript("main()", ScriptLanguage.javascript, undefined, UndoModes.FAST_ENTIRE_SCRIPT, "Add 2 to page numbers");
function main(){
app.findGrepPreferences = app.changeGrepPreferences = null;
myFinds= new Array;
app.findGrepPreferences.findWhat = "\\d+";
myFinds=app.selection[0].findGrep();
for (c=0;c<myFinds.length;c++){
p=2+1*myFinds[c].contents;
q=p.toString();
app.changeGrepPreferences.changeTo=q;
myFinds[c].changeGrep();
}
}
Hi,
Is there any way to alter this script so that it finds only numbers greater than a certain number? That is, I need to insert 2 pages after page 32, so every page number in the index that is greater than 32 needs to be incremented by 2, but pages 1-32 need to stay the same.
Thanks in advance if you can help!
Is there any way to alter this script so that it finds only numbers greater than a certain number? That is, I need to insert 2 pages after page 32, so every page number in the index that is greater than 32 needs to be incremented by 2, but pages 1-32 need to stay the same.
Yes.
Something like this (untested):
#target indesign
app.doScript("main()", ScriptLanguage.javascript,
undefined, UndoModes.FAST_ENTIRE_SCRIPT,
"Add 2 to page numbers");
function main(){
var oldnum;
app.findGrepPreferences = app.changeGrepPreferences = null;
myFinds= new Array;
app.findGrepPreferences.findWhat = "\\d+";
myFinds=app.selection[0].findGrep();
for (c=0;c<myFinds.length;c++) {
oldnum=1*myFinds[c].contents;
if (oldnum > 32) {
p=2+oldnum;
q=p.toString();
app.changeGrepPreferences.changeTo=q;
myFinds[c].changeGrep();
}
}
}
ArchieOldie wrote:
Oh, I'm an idiot. No, I did not have anything selected. Why, why, why is it so hard to follow directions? In my haste I forgot to re-read before the test. Yes, once I selected the text the script worked beautifully. Thank you so much for your help!
Ok,
I know my one line instruction "Select the text and then run the script" is a bit on the complicated side so I have added a catch for those in need of a nap.
made a couple of other changes as well.
#target indesign
try {
mySelection=app.selection[0];
app.findGrepPreferences = app.changeGrepPreferences = null;
var oldnum;
app.findGrepPreferences.findWhat = "\\d+";
myFinds= new Array;
myFinds=mySelection.findGrep();
pagesToAdd=parseInt(prompt ("Ammount to add to page numbers ?", "1", "Ammount to add to page numbers ?"));
fromPage=parseInt(prompt ("Add "+pagesToAdd+" to page numbers from page ?", "1", "Add "+pagesToAdd+"Add "+pagesToAdd+" to page numbers from page ?"));
untilPage=parseInt(prompt ("Add "+pagesToAdd+" to page numbers from page "+fromPage+" until page ?", app.documents[0].pages.length, "Add "+pagesToAdd+" to page numbers from page "+fromPage+" until page ?"));
app.doScript("main()", ScriptLanguage.javascript,
undefined, UndoModes.ENTIRE_SCRIPT,
"Adjust index page numbers");
function main(){
myFinds=mySelection.findGrep();
for (c=0;c<myFinds.length;c++) {
oldnum=1*myFinds[c].contents;
if (oldnum >= fromPage && oldnum <=untilPage) {
p=pagesToAdd+oldnum;
q=p.toString();
app.changeGrepPreferences.changeTo=q;
myFinds[c].changeGrep();
}
}
}
}
catch (noSelection) {
alert("Did you realy wan't to adjust every number in your "+app.documents[0].pages.length
+" page document!!!!\rMaybe you just wanted to change the index entries????\rHave a little nap and then select the text of the index and run the script again");
}
I made quite an advanced version of this script that also cleans up the index entries, checks that their in the right order (changes 3,6,4, 55-34 to 3, 4, 6, 34-55) using appropriate separators and spacing and dealing with numbers that are part of the entry and not the page number. I.e "WWII 1939 - 1945 34, 66, 36" will change to "WWII 1939 - 1945 36, 38, 68" if we add 2 to the pages and not "WWII 1941 - 1947 36, 38, 68"
But sorry not giving that one away as a freebie for now.
Regards
Trevor
North America
Europe, Middle East and Africa
Asia Pacific