javascript - Get current page number of InDesign multi page document -
i trying current page number of indesign page label. using:
mylabel = mydocument.properties.name.replace(/\d+/,'').split(' ')[0].split('_')[0] + '_' + app.activewindow.activepage.name +'_'+mycounter; the issue running running multi page document, , instead of using current page number, using first page number of document in labels in each page.
here code think having issues with:
function myaddlabel(mydocument, mygraphic, mycounter, mylabeltype, mylabelheight, mylabeloffset, mystyle, myswatch, mystoriesarray){ var mylabel; var mylink = mygraphic.itemlink; var mypastefromclipboard = false; //create label layer if not exist. var mylabellayer = mydocument.layers.item("coded layout"); try{ mylabellayer.name; } catch (myerror){ mylabellayer = mydocument.layers.add({name:"coded layout"}); } //label type defines text goes in label. switch(mylabeltype){ //file name case 0: mylabel = mydocument.properties.name.replace(/\d+/,'').split(' ')[0].split('_')[0]+'_' + app.activewindow.activepage.name+'_'+padnumber(mycounter); break; now believe actual issue in part of script, if select items on page , run script works way want work.
function myaddlabels(mylabeltype, mylabelheight, mylabeloffset, mystyle, myswatch){ var mydocument = app.documents.item(0); mystoriesarray = new array(); if (app.selection.length == 0) // if nothing selected apply caption graphics in document { var myconfirmation = confirm("add captions images in document?", false, "labelgraphics.jsx" ); if (myconfirmation == true) { var mygraphics = mydocument.allgraphics; } } else { // if graphics selected, add captions selected items, long rectangles(image frames) var myconfirmation = true; var myselections = app.selection; mygraphics = new array(); for(i = 0; < myselections.length; i++){ if(myselections[i] == "[object rectangle]"){ //check make sure selection includes rectangles mygraphics.push(myselections[i].allgraphics[0]); } else{ //alert("objects other graphics selected!"); //nothing happens if don't select @ least 1 graphic } } } and need @ point create loop suggested run though pages first last applying label.
the property app.activewindow.activepage.name returns "name" (which indeed current page number) 1 page visible in current (active) indesign window. unless code actively switches layout window show each page in turn, return same number (and if page shown first page, you'd described).
to assign mylabel each page number in entire document, need loop on each of document's pages:
for (p=0; p<mydocument.pages.length; p++) { mylabel = mydocument.name.replace(/\d+/,'') + '_' + app.activedocument.pages[p].name +'_'+mycounter; /* .. use mylabel here .. */ } i removed split commands because regex removes of characters not digits, , there no spaces or underscores left split on.
Comments
Post a Comment