• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

InDesign Move to Pasteboard Script Tweak

New Here ,
Sep 20, 2022 Sep 20, 2022

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!

TOPICS
Scripting

Views

108

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Sep 20, 2022 Sep 20, 2022

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"
...

Votes

Translate

Translate
Community Expert ,
Sep 20, 2022 Sep 20, 2022

Copy link to clipboard

Copied

LATEST

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 = [];

    }

};

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines