Copy link to clipboard
Copied
Hi Adobe Community! I am trying to tweak a script in InDesign and am way out of my depth. I have a script that will move all items to the pasteboard, but will ignore any JPGs TIFs or PDFs. Though I would like to utilize a script that will ignore everything except for PDFs (leave the document alone, but will pull all PDFs out to the pasteboard. I've fiddled with this a lot, but the original script I'm working with looks like this:
function myFunction() {
var moveGroup = [];
var myDoc = app.activeDocument;
var myPages = myDoc.pages;
var myItems, myGroup;
for (var p=0; p<myPages.length; p++) {
var thePage = myPages[p];
for (var i=0; i<thePage.pageItems.length; i++) {
var myItem = thePage.pageItems[i];
if (!myItem.hasOwnProperty("contentType")) {
moveGroup.push(myItem);
}
else {
if (myItem.contentType == ContentType.GRAPHIC_TYPE && myItem.images.length != 0) {
if (!myItem.images[0].itemLink.name.match(/\.(tif|jpg)$/gi)) {
moveGroup.push(myItem);
}
}
else if (myItem.contentType == ContentType.GRAPHIC_TYPE && myItem.pdfs.length != 0) {
if (!myItem.pdfs[0].itemLink.name.match(/\.(pdf)$/gi)) {
moveGroup.push(myItem);
}
}
else {
moveGroup.push(myItem);
}
}
}
if (moveGroup.length > 1) {
myGroup = myDoc.groups.add(moveGroup);
movePageItems(myGroup , thePage);
else if (moveGroup.length == 1) {
myGroup = moveGroup[0];
movePageItems(myGroup , thePage);
}
moveGroup = [];
}
Anyone able to point me to how I should rewrite those else statements? Thanks in advance!
Copy link to clipboard
Copied
Hi @Stephanie262131002dcs, this is how I would do it. You can put all the if predicates together. - Mark
function myFunction() {
var moveGroup = [];
var myDoc = app.activeDocument;
var myPages = myDoc.pages;
var myGroup;
for (var p = 0; p < myPages.length; p++) {
var thePage = myPages[p];
for (var i = 0; i < thePage.pageItems.length; i++) {
var myItem = thePage.pageItems[i];
if (
myItem.hasOwnProperty("contentType")
&& myItem.contentType == ContentType.GRAPHIC_TYPE
&& myItem.pdfs.length > 0
)
moveGroup.push(myItem);
}
if (moveGroup.length > 1) {
myGroup = myDoc.groups.add(moveGroup);
movePageItems(myGroup, thePage);
}
else if (moveGroup.length == 1) {
myGroup = moveGroup[0];
movePageItems(myGroup, thePage);
}
moveGroup = [];
}
};