Javascript 循环遍历层并将其设置为可见
我正在尝试在InDesign文档中循环遍历层,并将所有层设置为可见。这是为了确保正确进行文件收集 我总结了以下几点Javascript 循环遍历层并将其设置为可见,javascript,adobe-indesign,Javascript,Adobe Indesign,我正在尝试在InDesign文档中循环遍历层,并将所有层设置为可见。这是为了确保正确进行文件收集 我总结了以下几点 var myDocument = app.activeDocument; //make all layers visable for (i = 0; i < myDocument.layers.length; i++) { if(myDocument.layers[i].visible = false) { myDocument.laye
var myDocument = app.activeDocument;
//make all layers visable
for (i = 0; i < myDocument.layers.length; i++) {
if(myDocument.layers[i].visible = false) {
myDocument.layers[i].visible = true;
};
};
var myDocument=app.activeDocument;
//使所有层可见
对于(i=0;i
这是从自动化文件收集的较大脚本中摘录的,这只是层的例程
对于上下文,这里是实际的脚本
function Left(str, n){
if (n <= 0)
return "";
else if (n > String(str).length)
return str;
else
return String(str).substring(0,n);
}
function Right(str, n){
if (n <= 0)
return "";
else if (n > String(str).length)
return str;
else {
var iLen = String(str).length;
return String(str).substring(iLen, iLen - n);
}
}
if (app.documents.length != 0){
var myDocument = app.activeDocument;
var docName = myDocument.name;
var docName = Left(docName, String(docName).length-5)
//alert(docName);
var myFolder = new Folder ("~/Desktop/"+docName+"/");
//myFolder.create("Bob");s
/*new Folder ("~/Desktop/Collected/Hi-Res PDF/");
new Folder ("~/Desktop/Collected/RELEASE INFO/");*/
//make all layers visable
for (i = 0; i < myDocument.layers.length; i++) {
if(myDocument.layers[i].visible = false) {
myDocument.layers[i].visible = true;
};
};
myDocument.packageForPrint (myFolder,1,1,0,1,0,0,0);
var newFolder = new Folder ("~/Desktop/"+docName+"/RELEASE INFO/");
newFolder.create();
var inddFolder = new Folder ("~/Desktop/"+docName+"/Indesign Files/");
inddFolder.create();
var newFolder = new Folder ("~/Desktop/"+docName+"/IDML Files/");
newFolder.create();
//Export IMDL File
myDocument.exportFile(ExportFormat.INDESIGN_MARKUP, File("~/Desktop/"+docName+"/IDML Files/"+docName+".idml"), false);
//Move INDD File
//var myInddfile = File("~/Desktop/"+docName+"/"+docName+".indd");
//myDocument.changePath(File(inddFolder),false);
//Rip Low Res PDFs
var myPDFExportPreset = app.pdfExportPresets.item("CP3 Low Rez");
app.activeDocument.exportFile(ExportFormat.pdfType,
File("~/Desktop/"+docName+"/RELEASE INFO/"+docName+"_LR.pdf"), false, myPDFExportPreset);
//Now export the document. You'll have to fill in your own file path.
//app.activeDocument.exportFile(ExportFormat.pdfType, File("~/Desktop/"+docName+"_FILM/RELEASE INFO/"+docName+"_LR.pdf"), false);
var newFolder = new Folder ("~/Desktop/"+docName+"/Hi-Res PDF/");
newFolder.create();
//Rip Hi-Res PDF
var myPDFExportPreset = app.pdfExportPresets.item("Kern Hi Rez Print");
app.activeDocument.exportFile(ExportFormat.pdfType,
File("~/Desktop/"+docName+"/Hi-Res PDF/"+docName+"_HiRes.pdf"), false, myPDFExportPreset);
//Now export the document. You'll have to fill in your own file path.
//app.activeDocument.exportFile(ExportFormat.pdfType, File("~/Desktop/"+docName+"_FILM/Hi-Res PDF/"+docName+"_HiRes.pdf"), false);
myFolder.execute();
}
else{
alert("Please open a document and try again.");
}
函数左(str,n){
if(n字符串(str).length)
返回str;
其他的
返回字符串(str).substring(0,n);
}
功能权限(str,n){
if(n字符串(str).length)
返回str;
否则{
var-iLen=字符串(str).length;
返回字符串(str).substring(iLen,iLen-n);
}
}
如果(app.documents.length!=0){
var myDocument=app.activeDocument;
var docName=myDocument.name;
var docName=Left(docName,字符串(docName).length-5)
//警报(docName);
var myFolder=新文件夹(“~/Desktop/”+docName+“/”);
//myFolder.create(“Bob”)的
/*新文件夹(“~/Desktop/Collected/Hi Res PDF/”);
新文件夹(“~/Desktop/Collected/RELEASE INFO/”);*/
//使所有层可见
对于(i=0;i
希望在脚本执行时,所有层都将设置为可见,然后将进行文件收集。在
if
语句中使用三重相等。例如:
(i=0;i
if(myDocument.layers[i].visible==false){//感谢您提供了非常全面的答案,并将其复制一份以备将来参考。
for (i = 0; i < myDocument.layers.length; i++) {
if (!myDocument.layers[i].visible) { // <-- Change to this.
myDocument.layers[i].visible = true;
};
};
for (i = 0; i < myDocument.layers.length; i++) {
myDocument.layers[i].visible = true;
};
var myDocument = app.activeDocument;
// ...
function makeAllVisible() {
for (i = 0, max = myDocument.layers.length; i < max; i++) {
var currentLayer = myDocument.layers[i];
currentLayer.visible = true; // Make the top level layer visible.
// Make all sub layers visible,
// i.e. make all page items on the current layer visible.
var currentLayerPageItems = currentLayer.allPageItems;
for (x = 0, len = currentLayerPageItems.length; x < len; x++) {
currentLayerPageItems[x].visible = true
}
}
}
makeAllVisible(); // Invoke the function.
// ...