/ Forums / Id-Extras Forum / Loop through pages, loop through files

  • Author
  • #6200 Reply
    Wonderboy
    Participant

    I want to loop through my documents pages, each page will have a rectangle for a graphic. each page will be the same layout. for each page i want to loop through a folder, and place an image from that folder into the rectangle on each page. For example, Page 1 will have image 1, page 2 will have image 2, page 3 will have image 3 and so on.

    Below is the code i’ve been working with. it will loop though pages and loops through the files, but in the end it still places the last image in the loop on the first page.

    Code:
    var myDocument = app.activeDocument;
    var docLength = myDocument.pages.length;
    var myPages = myDocument.pages
    var DocName = app.activeDocument.name;
    var docPath = “Y:/Art Department/Shared Resources/Test Projects/Place artwork/pdf”
    var JobNum = DocName.split(“_”);
    var SplitPath = docPath.split(“/”);
    // var PDFLocation = SplitPath.slice(4,-1)
    // alert(myDocument.fullName)

    var sourceFolder = Folder(docPath);

    var files = sourceFolder.getFiles();

    try {

    var parPage = app.selection[0].parentPage;

    }

    catch(e) {

    alert(“Select a rectangle with your black arrow tool on the desired page”);

    exit();

    }

    var rects = parPage.rectangles.everyItem().getElements();

    for (var i = 0; i < docLength; i++) { for (var j = 0; j < files.length; j++) { if (files[j].hidden) { continue; } try { rects[0].place(files[j]); } catch(e) { alert("Couldn't place " + files[j].name); } } }

    • This topic was modified 1 year, 8 months ago by ~~Ariel~~.
    #6441 Reply
    Wonderboy
    Participant

    i figured it out

    Code:
    var sourceFolder = Folder(PathToPDF);

    var files = sourceFolder.getFiles();

    for (var i = 0; i < docLength; i++) { // alert(myPages[i].name); var parPage = myPages[i]; for (var j = 0; j < files.length; j++) { var rects = parPage.rectangles.everyItem().getElements(); rects[0].place(files[i]); break; } }

    #6442 Reply
    ~~Ariel~~
    Participant

    Good!

Viewing 3 posts - 1 through 3 (of 3 total)

Tagged: 

Reply To: Loop through pages, loop through files
Your information: