获取 InDesign 多页文档的当前页码
Get current page number of InDesign multi page document
我正在尝试将 InDesign 页面的当前页码放入标签中。
这是我正在使用的:
myLabel = myDocument.properties.name.replace(/\D+/,'').split(' ')[0].split('_')[0] + '_'
+ app.activeWindow.activePage.name +'_'+myCounter;
我 运行 遇到的问题是,我 运行 从一个多页文档中对此进行了处理,而不是使用当前页码,而是使用当前页码的第一页码在每一页的所有标签中记录。
这是我认为有问题的代码:
function myAddLabel(myDocument, myGraphic, myCounter, myLabelType, myLabelHeight, myLabelOffset, myStyle, mySwatch, myStoriesArray){
var myLabel;
var myLink = myGraphic.itemLink;
var myPasteFromClipboard = false;
//Create the label layer if it does not already exist.
var myLabelLayer = myDocument.layers.item("Coded Layout");
try{
myLabelLayer.name;
}
catch (myError){
myLabelLayer = myDocument.layers.add({name:"Coded Layout"});
}
//Label type defines the text that goes in the label.
switch(myLabelType){
//File name
case 0:
myLabel = myDocument.properties.name.replace(/\D+/,'').split(' ')[0].split('_')[0]+'_' + app.activeWindow.activePage.name+'_'+padNumber(myCounter);
break;
现在我认为实际问题出在脚本的这一部分,如果我 select 页面上的所有项目和 运行 脚本它按我想要的方式工作工作。
function myAddLabels(myLabelType, myLabelHeight, myLabelOffset, myStyle, mySwatch){
var myDocument = app.documents.item(0);
myStoriesArray = new Array();
if (app.selection.length == 0) // If nothing is selected apply caption to all graphics in the document
{
var myConfirmation = confirm("Add captions to all images in the document?", false, "LabelGraphics.jsx" );
if (myConfirmation == true)
{
var myGraphics = myDocument.allGraphics;
}
}
else
{ // If graphics are selected, just add captions to the selected items, as long as they are rectangles(image frames)
var myConfirmation = true;
var mySelections = app.selection;
myGraphics = new Array();
for(i = 0; i < mySelections.length; i++){
if(mySelections[i] == "[object Rectangle]"){ //Check to make sure selection only includes rectangles
myGraphics.push(mySelections[i].allGraphics[0]);
}
else{
//alert("Objects other than graphics were selected!");
//Nothing happens if you don't select at least one graphic
}
}
}
此时我需要做的是按照您向 运行 建议的方式创建一个循环,遍历从第一页到最后一页应用标签的所有页面。
属性 app.activeWindow.activePage.name
只有 return 是 "name"(确实是当前页码)可见的一页 在您当前(活动)的 InDesign window 中。除非您的代码主动切换布局 window 以依次显示每个页面,否则它将始终 return 相同的数字(如果当前显示的页面是第一页,那么您将得到您想要的描述)。
要将 myLabel
分配给整个文档中的每个页码,您需要遍历文档的每个 页:
for (p=0; p<myDocument.pages.length; p++)
{
myLabel = myDocument.name.replace(/\D+/,'') + '_'
+ app.activeDocument.pages[p].name +'_'+myCounter;
/* .. use myLabel here .. */
}
我删除了 split
命令,因为正则表达式已经删除了所有非数字字符,因此没有空格或下划线可以拆分 on .
我正在尝试将 InDesign 页面的当前页码放入标签中。 这是我正在使用的:
myLabel = myDocument.properties.name.replace(/\D+/,'').split(' ')[0].split('_')[0] + '_'
+ app.activeWindow.activePage.name +'_'+myCounter;
我 运行 遇到的问题是,我 运行 从一个多页文档中对此进行了处理,而不是使用当前页码,而是使用当前页码的第一页码在每一页的所有标签中记录。
这是我认为有问题的代码:
function myAddLabel(myDocument, myGraphic, myCounter, myLabelType, myLabelHeight, myLabelOffset, myStyle, mySwatch, myStoriesArray){
var myLabel;
var myLink = myGraphic.itemLink;
var myPasteFromClipboard = false;
//Create the label layer if it does not already exist.
var myLabelLayer = myDocument.layers.item("Coded Layout");
try{
myLabelLayer.name;
}
catch (myError){
myLabelLayer = myDocument.layers.add({name:"Coded Layout"});
}
//Label type defines the text that goes in the label.
switch(myLabelType){
//File name
case 0:
myLabel = myDocument.properties.name.replace(/\D+/,'').split(' ')[0].split('_')[0]+'_' + app.activeWindow.activePage.name+'_'+padNumber(myCounter);
break;
现在我认为实际问题出在脚本的这一部分,如果我 select 页面上的所有项目和 运行 脚本它按我想要的方式工作工作。
function myAddLabels(myLabelType, myLabelHeight, myLabelOffset, myStyle, mySwatch){
var myDocument = app.documents.item(0);
myStoriesArray = new Array();
if (app.selection.length == 0) // If nothing is selected apply caption to all graphics in the document
{
var myConfirmation = confirm("Add captions to all images in the document?", false, "LabelGraphics.jsx" );
if (myConfirmation == true)
{
var myGraphics = myDocument.allGraphics;
}
}
else
{ // If graphics are selected, just add captions to the selected items, as long as they are rectangles(image frames)
var myConfirmation = true;
var mySelections = app.selection;
myGraphics = new Array();
for(i = 0; i < mySelections.length; i++){
if(mySelections[i] == "[object Rectangle]"){ //Check to make sure selection only includes rectangles
myGraphics.push(mySelections[i].allGraphics[0]);
}
else{
//alert("Objects other than graphics were selected!");
//Nothing happens if you don't select at least one graphic
}
}
}
此时我需要做的是按照您向 运行 建议的方式创建一个循环,遍历从第一页到最后一页应用标签的所有页面。
属性 app.activeWindow.activePage.name
只有 return 是 "name"(确实是当前页码)可见的一页 在您当前(活动)的 InDesign window 中。除非您的代码主动切换布局 window 以依次显示每个页面,否则它将始终 return 相同的数字(如果当前显示的页面是第一页,那么您将得到您想要的描述)。
要将 myLabel
分配给整个文档中的每个页码,您需要遍历文档的每个 页:
for (p=0; p<myDocument.pages.length; p++)
{
myLabel = myDocument.name.replace(/\D+/,'') + '_'
+ app.activeDocument.pages[p].name +'_'+myCounter;
/* .. use myLabel here .. */
}
我删除了 split
命令,因为正则表达式已经删除了所有非数字字符,因此没有空格或下划线可以拆分 on .