Skip to main content
Participating Frequently
February 19, 2020
Answered

Exporting jpegs from pages to specific folders

  • February 19, 2020
  • 2 replies
  • 1742 views

I have a script set up to export images/links and groups as jpegs with specified settings. It looks for the images/links and groups on a specified layer (ProdLayer) and exports them to a local path designated through a panel:

I am trying to have the script run through a series of pages and export the images (links) and groups from each page to a designated folder locally. The script works fine to export everything, however, each iteration through the loop exports all images and groups from all pages into each folder.

 

How can I force the export to only push the images on the page designated in the loop?

(also, any suggestions to clean up the redundant code woudl be swell 😉 )

 

function extract() {
var i,
myDoc = app.activeDocument,
myLayer = myDoc.layers.itemByName( "ProdLayer" ),
myGroups = myDoc.layers.itemByName( "ProdLayer" ).groups,
apis = myDoc.links.everyItem().getElements(), rect, fileName;

alert("Script is running. Press OK and wait until done...");

var myFilePath = outfolder.text;
if (myFilePath !== ""){
} else {
alert ("Error!\nNo Output folder was selected. Please select a Folder and try again")
return;
}

var myFolder = (String(myFilePath)); // Create a new file path

while ( rect = apis.pop() ) {
rect = rect.parent.parent;
if( rect.itemLayer != myLayer ){ continue }
if ( !(rect.hasOwnProperty ("graphics") ) ){ continue }

fileName = File ( rect.graphics[0].itemLink.filePath ).name;
fileName = fileName.replace( /\.[a-z]{2,4}$/i, '.jpg' );

if (settingGroup.selection == 0){
app.jpegExportPreferences.jpegQuality =JPEGOptionsQuality.LOW;
}
if (settingGroup.selection == 1){
app.jpegExportPreferences.jpegQuality = JPEGOptionsQuality.MEDIUM;
}
if (settingGroup.selection == 2){
app.jpegExportPreferences.jpegQuality = JPEGOptionsQuality.HIGH;
}
if (settingGroup.selection == 4){
app.jpegExportPreferences.jpegQuality = JPEGOptionsQuality.MAXIMUM;
}
if (settingGroup2.selection == 0){
app.jpegExportPreferences.jpegRenderingStyle = JPEGOptionsFormat.BASELINE_ENCODING;
}
if (settingGroup2.selection == 1){
app.jpegExportPreferences.jpegRenderingStyle = JPEGOptionsFormat.PROGRESSIVE_ENCODING;
}
if (settingGroup3.selection == 0){
app.jpegExportPreferences.exportResolution = 72;
}
if (settingGroup3.selection == 1){
app.jpegExportPreferences.exportResolution = 150;
}
if (settingGroup3.selection == 2){
app.jpegExportPreferences.exportResolution = 300;
}
if (settingGroup3.selection == 3){
app.jpegExportPreferences.exportResolution = 600;
}

for(var myCount= 0; myCount< myPages.length; myCount++) {
if (myPages.item(myCount).appliedSection.name != "") {
myPages.item(myCount).appliedSection.name = "";
}

var myPageName = myPages.item(myCount).name;
if (myPageName == 1){
// if (rect.itemPage != myPageName){ continue }
newPageName = "RTW";
var fol1 = Folder(String(myFolder ) + "/RTW/");
if (!fol1.exists) {
fol1.create();
}
var myFile1 = new File (String(myFolder) + "/RTW/" + fileName);
rect.exportFile(ExportFormat.JPG, myFile1);
}
if (myPageName == 2){
// if (rect.itemPage != myPageName){ continue }
newPageName = "HOME";
var fol1 = Folder(String(myFolder ) + "/Home/");
if (!fol1.exists) {
fol1.create();
}
var myFile2 = new File (String(myFolder) + "/Home/" + fileName);
rect.exportFile(ExportFormat.JPG, myFile2);
}
if (myPageName == 3){
// if (rect.itemPage != myPageName){ continue }
newPageName = "KIDS";
var fol1 = Folder(String(myFolder ) + "/Kids/");
if (!fol1.exists) {
fol1.create();
}
var myFile3 = new File (String(myFolder) + "/Kids/" + fileName);
rect.exportFile(ExportFormat.JPG, myFile3);
}
if (myPageName == 4){
// if (rect.itemPage != myPageName){ continue }
newPageName = "MOBILE";
var fol1 = Folder(String(myFolder ) + "/Mobile/");
if (!fol1.exists) {
fol1.create();
}
var myFile4 = new File (String(myFolder) + "/Mobile/" + fileName);
rect.exportFile(ExportFormat.JPG, myFile4);

// alert ("Exporting Groups...");

for ( i = 0; i < myGroups.length; i++ ) {
// var fol2 = Folder(String(myFolder ) + "/groups/");
// if (!fol2.exists) {
// fol2.create();
// }
var grpFile = new File( String(myFolder) + "/Mobile/" + i + '.jpg' );
myGroups[i].exportFile( ExportFormat.JPG, grpFile, false );
}
}
//var myFile = new File (String(myFolder) + newPageName + fileName);
//rect.exportFile(ExportFormat.JPG, myFile);
}
}

alert ("Done.");
w.close();
}

 

This topic has been closed for replies.
Correct answer Sunil Yadav

Add this code for your script UI for better understanding : 

if(app.documents.length > 0){
    // DIALOG
    // ======
    var dialog = new Window("dialog"); 
        dialog.text = "Export AS PNG"; 
        dialog.preferredSize.width = 300; 
        dialog.preferredSize.height = 300; 
        dialog.orientation = "column"; 
        dialog.alignChildren = ["center","top"]; 
        dialog.spacing = 10; 
        dialog.margins = 16; 

    // GROUP1
    // ======
    var group1 = dialog.add("group", undefined, {name: "group1"}); 
        group1.orientation = "row"; 
        group1.alignChildren = ["left","center"]; 
        group1.spacing = 10; 
        group1.margins = 0; 

    // PANEL1
    // ======
    var panel1 = group1.add("panel", undefined, undefined, {name: "panel1"}); 
        panel1.text = "Export Settings"; 
        panel1.preferredSize.width = 300; 
        panel1.orientation = "column"; 
        panel1.alignChildren = ["left","top"]; 
        panel1.spacing = 10; 
        panel1.margins = 10; 

    // GROUP2
    // ======
    var group2 = panel1.add("group", undefined, {name: "group2"}); 
        group2.orientation = "row"; 
        group2.alignChildren = ["left","center"]; 
        group2.spacing = 10; 
        group2.margins = 0; 

    var statictext1 = group2.add("statictext", undefined, undefined, {name: "statictext1"}); 
        statictext1.text = "Select Layer"; 
        statictext1.preferredSize.width = 100; 

    var dropdown1_array = []; 
    for(var p = 0; p < app.documents[0].layers.length; p++){
        dropdown1_array.push(app.documents[0].layers[p].name);
        }

    var dropdown1 = group2.add("dropdownlist", undefined, undefined, {name: "dropdown1", items: dropdown1_array}); 
        dropdown1.selection = 0; 
        dropdown1.preferredSize.width = 150; 
        

    // PANEL1
    // ======
    var divider1 = panel1.add("panel", undefined, undefined, {name: "divider1"}); 
        divider1.alignment = "fill"; 

    // GROUP3
    // ======
    var group3 = panel1.add("group", undefined, {name: "group3"}); 
        group3.orientation = "row"; 
        group3.alignChildren = ["left","center"]; 
        group3.spacing = 10; 
        group3.margins = 0; 

    var statictext2 = group3.add("statictext", undefined, undefined, {name: "statictext2"}); 
        statictext2.text = "Export Quality : "; 
        statictext2.preferredSize.width = 100; 

    var dropdown2_array = ["Low","Medium","High","Maximum"]; 
    var dropdown2 = group3.add("dropdownlist", undefined, undefined, {name: "dropdown2", items: dropdown2_array}); 
        dropdown2.selection = 0; 
        dropdown2.preferredSize.width = 150; 

    // GROUP4
    // ======
    var group4 = panel1.add("group", undefined, {name: "group4"}); 
        group4.orientation = "row"; 
        group4.alignChildren = ["left","center"]; 
        group4.spacing = 10; 
        group4.margins = 0; 

    var statictext3 = group4.add("statictext", undefined, undefined, {name: "statictext3"}); 
        statictext3.text = "JPEG Format : "; 
        statictext3.preferredSize.width = 100; 

    var dropdown3_array = ["Baseline Encoding","Progressive"]; 
    var dropdown3 = group4.add("dropdownlist", undefined, undefined, {name: "dropdown3", items: dropdown3_array}); 
        dropdown3.selection = 1; 
        dropdown3.preferredSize.width = 150; 

    // GROUP5
    // ======
    var group5 = panel1.add("group", undefined, {name: "group5"}); 
        group5.orientation = "row"; 
        group5.alignChildren = ["left","center"]; 
        group5.spacing = 10; 
        group5.margins = 0; 

    var statictext4 = group5.add("statictext", undefined, undefined, {name: "statictext4"}); 
        statictext4.text = "Resolution : "; 
        statictext4.preferredSize.width = 100; 

    var dropdown4_array = ["72","150","300","600"]; 
    var dropdown4 = group5.add("dropdownlist", undefined, undefined, {name: "dropdown4", items: dropdown4_array}); 
        dropdown4.selection = 0; 
        dropdown4.preferredSize.width = 150; 

    // GROUP6
    // ======
    var group6 = panel1.add("group", undefined, {name: "group6"}); 
        group6.orientation = "row"; 
        group6.alignChildren = ["left","center"]; 
        group6.spacing = 10; 
        group6.margins = 0; 

    var divider2 = panel1.add("panel", undefined, undefined, {name: "divider2"}); 
        divider2.alignment = "fill"; 

    // GROUP7
    // ======
    var group7 = panel1.add("group", undefined, {name: "group7"}); 
        group7.orientation = "column"; 
        group7.alignChildren = ["left","top"]; 
        group7.spacing = 10; 
        group7.margins = 0; 

    var statictext5 = group7.add("statictext", undefined, undefined, {name: "statictext5"}); 
    if(app.documents[0].saved){
        statictext5.text = app.documents[0].filePath.fsName.replace(/\\/g,'/'); 
        }
    else{
        statictext5.text = "Choose a folder for exporting PNGs..."; 
        }
    statictext5.preferredSize.width = 278; 

    var image1_imgString = "%C2%89PNG%0D%0A%1A%0A%00%00%00%0DIHDR%00%00%00!%00%00%00%1F%08%06%00%00%00i%C2%94%C2%A4%C2%B2%00%00%00%09pHYs%00%00%0B%12%00%00%0B%12%01%C3%92%C3%9D~%C3%BC%00%00%03uIDATXG%C3%85%C2%97%C3%8B%C2%8B%5CE%14%C3%86%C2%BFs%C2%AAnw%C3%9F%C3%AE%C3%8E%24c%C3%84%C2%88%12%C3%90%40v!%C3%A8B3n%C3%B4%0F%10%C3%BF%C2%81%C2%AC%04%17%C3%A2Jp%C3%A1%C2%80q%C2%A5Y%C2%88%22%C3%89%C2%80%1BA%04%09%08n%05AD%C2%94%C2%B8%C2%901%C2%BE%26N2czf%3A%C2%93%C3%97%C2%BC%C2%9F%C3%BD%C2%9C%C2%BE%C2%8F%C3%BA%5C%5C%C3%AF0%C2%8E%C2%9D%C2%9En2%C3%A9%C3%B9A%C3%81%C2%AD%C3%87%C2%A9%C3%BA%C2%AA%C3%AA%C2%9C%C2%AA%C2%BAB%12%07%C2%8D%C3%AE%C3%95%60'%5E%C3%86%C3%AB%C2%A9%7D%C2%B7%C3%98%C3%81%23%C3%85%C3%82%5B%C2%AF%3E%C3%BD%C3%81%C3%A1%C2%82%1E%0B%22%C2%B6%04%C2%80%10%C2%A0%00%04%C3%A0g%C3%95_X%0D%C3%8B%17%C2%BF%C2%B89%1C%06%C2%A1%C3%B3%C2%AC%C3%950%C2%8A%C3%9C%5E%1D%C3%B7%C2%82%C3%BC%C3%BC%C3%95%C3%A9%C2%9Bg%C2%86%C2%9Ex%C3%8AE%C3%87!j%00%12%C2%90%C2%A4%C2%92ppQ%00%C3%ABMc%C3%A2%C2%AF%C3%B5%C2%B9S%C2%AF%5C%7F%C2%B2sw%C3%9D%23%22%C3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%2B%06%C2%92iw%C2%BC%C2%96%0B%C2%B5h%C3%85%C2%8CK%C2%97s%C3%9E%C2%A1%C2%A3%C3%A9%C3%BD%C2%B5%7C%C2%A8E%13%04%C2%8E%1D%1FO%C3%87c%C2%83%C2%B5%7C%C2%A8E3%01%23Wr%C2%99%C3%8C%C2%99k%C3%B9%3A%C2%BE%5D%40%18%40D%C2%B8%C2%91%C3%82%C2%99F%3E%C3%94%C2%A2%C2%95%C2%A1q%C3%A8x%C3%AE%C2%8FF%3E%C3%94%C2%A2%09%C2%84%C2%B1%C2%AC%7B%C2%BE%C2%91%0F%C2%AFh%C2%81%C3%84%C2%BA%2C%C3%AC%3B%C2%9A%C3%B9%C2%8D%C2%A8%C2%BE%C3%B2%C2%85V%C2%B4e%10%5DK%C2%BA%C3%B9%7C%C3%81kj%C2%AAs%C3%8Cfp%08%2B%C3%B8%C3%BD%3D6%C3%B6%1E%C3%B6%7Ft%1C%C3%97m%C2%B4%C3%91%C3%AA%C2%95%C2%8B%3F%C3%B8%C3%BA%C2%A3%C2%9E%C3%AF%C3%A6%C3%B5%C3%98%C3%95%C3%A68Aj%1A%C3%A5S%C2%8ET%C3%A9%C3%84%C2%8A%08%C2%88%04%C3%92%C3%A1%07p%60o%C3%A7Wm%C2%AA%C2%B7%C3%B1!E%C2%B8x9_Z%C2%B1v%60%C3%89%C2%B9%C2%81%C3%8C%C3%85%C2%A6x%11%C3%81%C2%BC%C2%B9%C2%899%2B_%5E%C2%B0%C2%86%C2%88%22%00*MBj%C3%9D%C2%B2i%C3%9Balc%C3%AF%C3%A4%C3%9F%C3%8A%26%00%2B%C2%86%C2%B3y%C3%A7%C3%B0%C2%A6%C3%B4Xn%C3%82%C2%B4L%C3%B6J%5E%C3%9D%C2%BFW%C3%BF%00%06%C3%AE%16%08%0E%C3%93%C3%9C%C2%93%00%00%00%00IEND%C2%AEB%60%C2%82"; 
    var image1 = group7.add("image", undefined, File.decode(image1_imgString), {name: "image1"}); 

    image1.addEventListener("click",function(event){
        if(statictext5.text == "Choose a folder for exporting PNGs..."){
            var myFolder = Folder.selectDialog("Choose Folder for exporting PNGs");
            }
        else{
            var myFolder = new Folder(statictext5.text).selectDlg("Choose Folder for exporting PNGs");
            }
        if(myFolder != null){
            statictext5.text = myFolder.fsName.toString().replace(/\\/g,'/');
            }
        });

    // GROUP8
    // ======
    var group8 = dialog.add("group", undefined, {name: "group8"}); 
        group8.preferredSize.width = 300; 
        group8.orientation = "row"; 
        group8.alignChildren = ["right","center"]; 
        group8.spacing = 10; 
        group8.margins = 0; 

    var button1 = group8.add("button", undefined, undefined, {name: "OK"}); 
        button1.text = "Export"; 

    var button2 = group8.add("button", undefined, undefined, {name: "button2"}); 
        button2.text = "Cancel"; 

    if(dialog.show() == 1){
        if(dropdown2.selection == "Low"){
            app.jpegExportPreferences.jpegQuality =JPEGOptionsQuality.LOW;
            }
        else if(dropdown2.selection == "Medium"){
            app.jpegExportPreferences.jpegQuality = JPEGOptionsQuality.MEDIUM;
            }
        else if(dropdown2.selection == "High"){
            app.jpegExportPreferences.jpegQuality = JPEGOptionsQuality.HIGH;
            }
        else if(dropdown2.selection == "Maximum"){
            app.jpegExportPreferences.jpegQuality = JPEGOptionsQuality.MAXIMUM;
            }
        if(dropdown3.selection == "Baseline Encoding"){
            app.jpegExportPreferences.jpegRenderingStyle = JPEGOptionsFormat.BASELINE_ENCODING;
            }
        else if(dropdown3.selection == "Progressive"){
            app.jpegExportPreferences.jpegRenderingStyle = JPEGOptionsFormat.PROGRESSIVE_ENCODING;
            }
        if(dropdown4.selection == "72"){
            app.jpegExportPreferences.exportResolution = 72;
            }
        else if(dropdown4.selection == "150"){
            app.jpegExportPreferences.exportResolution = 150;
            }
        else if(dropdown4.selection == "300"){
            app.jpegExportPreferences.exportResolution = 300;
            }
        else if(dropdown4.selection == "600"){
            app.jpegExportPreferences.exportResolution = 600;
            }
        $.bp();
        // After this you can continue further coding ====
        }
    else{
        alert ("Have a nice day!", "Cancelled", false);
        }
    }
else{
    alert ("Please open a file and try again ... !!!", "Warning ... No documents opened!", true)
    }

Best

Sunil

2 replies

Sunil Yadav
Sunil YadavCorrect answer
Brainiac
February 20, 2020

Add this code for your script UI for better understanding : 

if(app.documents.length > 0){
    // DIALOG
    // ======
    var dialog = new Window("dialog"); 
        dialog.text = "Export AS PNG"; 
        dialog.preferredSize.width = 300; 
        dialog.preferredSize.height = 300; 
        dialog.orientation = "column"; 
        dialog.alignChildren = ["center","top"]; 
        dialog.spacing = 10; 
        dialog.margins = 16; 

    // GROUP1
    // ======
    var group1 = dialog.add("group", undefined, {name: "group1"}); 
        group1.orientation = "row"; 
        group1.alignChildren = ["left","center"]; 
        group1.spacing = 10; 
        group1.margins = 0; 

    // PANEL1
    // ======
    var panel1 = group1.add("panel", undefined, undefined, {name: "panel1"}); 
        panel1.text = "Export Settings"; 
        panel1.preferredSize.width = 300; 
        panel1.orientation = "column"; 
        panel1.alignChildren = ["left","top"]; 
        panel1.spacing = 10; 
        panel1.margins = 10; 

    // GROUP2
    // ======
    var group2 = panel1.add("group", undefined, {name: "group2"}); 
        group2.orientation = "row"; 
        group2.alignChildren = ["left","center"]; 
        group2.spacing = 10; 
        group2.margins = 0; 

    var statictext1 = group2.add("statictext", undefined, undefined, {name: "statictext1"}); 
        statictext1.text = "Select Layer"; 
        statictext1.preferredSize.width = 100; 

    var dropdown1_array = []; 
    for(var p = 0; p < app.documents[0].layers.length; p++){
        dropdown1_array.push(app.documents[0].layers[p].name);
        }

    var dropdown1 = group2.add("dropdownlist", undefined, undefined, {name: "dropdown1", items: dropdown1_array}); 
        dropdown1.selection = 0; 
        dropdown1.preferredSize.width = 150; 
        

    // PANEL1
    // ======
    var divider1 = panel1.add("panel", undefined, undefined, {name: "divider1"}); 
        divider1.alignment = "fill"; 

    // GROUP3
    // ======
    var group3 = panel1.add("group", undefined, {name: "group3"}); 
        group3.orientation = "row"; 
        group3.alignChildren = ["left","center"]; 
        group3.spacing = 10; 
        group3.margins = 0; 

    var statictext2 = group3.add("statictext", undefined, undefined, {name: "statictext2"}); 
        statictext2.text = "Export Quality : "; 
        statictext2.preferredSize.width = 100; 

    var dropdown2_array = ["Low","Medium","High","Maximum"]; 
    var dropdown2 = group3.add("dropdownlist", undefined, undefined, {name: "dropdown2", items: dropdown2_array}); 
        dropdown2.selection = 0; 
        dropdown2.preferredSize.width = 150; 

    // GROUP4
    // ======
    var group4 = panel1.add("group", undefined, {name: "group4"}); 
        group4.orientation = "row"; 
        group4.alignChildren = ["left","center"]; 
        group4.spacing = 10; 
        group4.margins = 0; 

    var statictext3 = group4.add("statictext", undefined, undefined, {name: "statictext3"}); 
        statictext3.text = "JPEG Format : "; 
        statictext3.preferredSize.width = 100; 

    var dropdown3_array = ["Baseline Encoding","Progressive"]; 
    var dropdown3 = group4.add("dropdownlist", undefined, undefined, {name: "dropdown3", items: dropdown3_array}); 
        dropdown3.selection = 1; 
        dropdown3.preferredSize.width = 150; 

    // GROUP5
    // ======
    var group5 = panel1.add("group", undefined, {name: "group5"}); 
        group5.orientation = "row"; 
        group5.alignChildren = ["left","center"]; 
        group5.spacing = 10; 
        group5.margins = 0; 

    var statictext4 = group5.add("statictext", undefined, undefined, {name: "statictext4"}); 
        statictext4.text = "Resolution : "; 
        statictext4.preferredSize.width = 100; 

    var dropdown4_array = ["72","150","300","600"]; 
    var dropdown4 = group5.add("dropdownlist", undefined, undefined, {name: "dropdown4", items: dropdown4_array}); 
        dropdown4.selection = 0; 
        dropdown4.preferredSize.width = 150; 

    // GROUP6
    // ======
    var group6 = panel1.add("group", undefined, {name: "group6"}); 
        group6.orientation = "row"; 
        group6.alignChildren = ["left","center"]; 
        group6.spacing = 10; 
        group6.margins = 0; 

    var divider2 = panel1.add("panel", undefined, undefined, {name: "divider2"}); 
        divider2.alignment = "fill"; 

    // GROUP7
    // ======
    var group7 = panel1.add("group", undefined, {name: "group7"}); 
        group7.orientation = "column"; 
        group7.alignChildren = ["left","top"]; 
        group7.spacing = 10; 
        group7.margins = 0; 

    var statictext5 = group7.add("statictext", undefined, undefined, {name: "statictext5"}); 
    if(app.documents[0].saved){
        statictext5.text = app.documents[0].filePath.fsName.replace(/\\/g,'/'); 
        }
    else{
        statictext5.text = "Choose a folder for exporting PNGs..."; 
        }
    statictext5.preferredSize.width = 278; 

    var image1_imgString = "%C2%89PNG%0D%0A%1A%0A%00%00%00%0DIHDR%00%00%00!%00%00%00%1F%08%06%00%00%00i%C2%94%C2%A4%C2%B2%00%00%00%09pHYs%00%00%0B%12%00%00%0B%12%01%C3%92%C3%9D~%C3%BC%00%00%03uIDATXG%C3%85%C2%97%C3%8B%C2%8B%5CE%14%C3%86%C2%BFs%C2%AAnw%C3%9F%C3%AE%C3%8E%24c%C3%84%C2%88%12%C3%90%40v!%C3%A8B3n%C3%B4%0F%10%C3%BF%C2%81%C2%AC%04%17%C3%A2Jp%C3%A1%C2%80q%C2%A5Y%C2%88%22%C3%89%C2%80%1BA%04%09%08n%05AD%C2%94%C2%B8%C2%901%C2%BE%26N2czf%3A%C2%93%C3%97%C2%BC%C2%9F%C3%BD%C2%9C%C2%BE%C2%8F%C3%BA%5C%5C%C3%AF0%C2%8E%C2%9D%C2%9En2%C3%A9%C3%B9A%C3%81%C2%AD%C3%87%C2%A9%C3%BA%C2%AA%C3%AA%C2%9C%C2%AA%C2%BAB%12%07%C2%8D%C3%AE%C3%95%60'%5E%C3%86%C3%AB%C2%A9%7D%C2%B7%C3%98%C3%81%23%C3%85%C3%82%5B%C2%AF%3E%C3%BD%C3%81%C3%A1%C2%82%1E%0B%22%C2%B6%04%C2%80%10%C2%A0%00%04%C3%A0g%C3%95_X%0D%C3%8B%17%C2%BF%C2%B89%1C%06%C2%A1%C3%B3%C2%AC%C3%950%C2%8A%C3%9C%5E%1D%C3%B7%C2%82%C3%BC%C3%BC%C3%95%C3%A9%C2%9Bg%C2%86%C2%9Ex%C3%8AE%C3%87!j%00%12%C2%90%C2%A4%C2%92ppQ%00%C3%ABMc%C3%A2%C2%AF%C3%B5%C2%B9S%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1%C2%BF%C3%9C%3D%C2%B5%5C%C3%A8E%2B%06%C2%92iw%C2%BC%C2%96%0B%C2%B5h%C3%85%C2%8CK%C2%97s%C3%9E%C2%A1%C2%A3%C3%A9%C3%BD%C2%B5%7C%C2%A8E%13%04%C2%8E%1D%1FO%C3%87c%C2%83%C2%B5%7C%C2%A8E3%01%23Wr%C2%99%C3%8C%C2%99k%C3%B9%3A%C2%BE%5D%40%18%40D%C2%B8%C2%91%C3%82%C2%99F%3E%C3%94%C2%A2%C2%95%C2%A1q%C3%A8x%C3%AE%C2%8FF%3E%C3%94%C2%A2%09%C2%84%C2%B1%C2%AC%7B%C2%BE%C2%91%0F%C2%AFh%C2%81%C3%84%C2%BA%2C%C3%AC%3B%C2%9A%C3%B9%C2%8D%C2%A8%C2%BE%C3%B2%C2%85V%C2%B4e%10%5DK%C2%BA%C3%B9%7C%C3%81kj%C2%AAs%C3%8Cfp%08%2B%C3%B8%C3%BD%3D6%C3%B6%1E%C3%B6%7Ft%1C%C3%97m%C2%B4%C3%91%C3%AA%C2%95%C2%8B%3F%C3%B8%C3%BA%C2%A3%C2%9E%C3%AF%C3%A6%C3%B5%C3%98%C3%95%C3%A68Aj%1A%C3%A5S%C2%8ET%C3%A9%C3%84%C2%8A%08%C2%88%04%C3%92%C3%A1%07p%60o%C3%A7Wm%C2%AA%C2%B7%C3%B1!E%C2%B8x9_Z%C2%B1v%60%C3%89%C2%B9%C2%81%C3%8C%C3%85%C2%A6x%11%C3%81%C2%BC%C2%B9%C2%899%2B_%5E%C2%B0%C2%86%C2%88%22%00*MBj%C3%9D%C2%B2i%C3%9Balc%C3%AF%C3%A4%C3%9F%C3%8A%26%00%2B%C2%86%C2%B3y%C3%A7%C3%B0%C2%A6%C3%B4Xn%C3%82%C2%B4L%C3%B6J%5E%C3%9D%C2%BFW%C3%BF%00%06%C3%AE%16%08%0E%C3%93%C3%9C%C2%93%00%00%00%00IEND%C2%AEB%60%C2%82"; 
    var image1 = group7.add("image", undefined, File.decode(image1_imgString), {name: "image1"}); 

    image1.addEventListener("click",function(event){
        if(statictext5.text == "Choose a folder for exporting PNGs..."){
            var myFolder = Folder.selectDialog("Choose Folder for exporting PNGs");
            }
        else{
            var myFolder = new Folder(statictext5.text).selectDlg("Choose Folder for exporting PNGs");
            }
        if(myFolder != null){
            statictext5.text = myFolder.fsName.toString().replace(/\\/g,'/');
            }
        });

    // GROUP8
    // ======
    var group8 = dialog.add("group", undefined, {name: "group8"}); 
        group8.preferredSize.width = 300; 
        group8.orientation = "row"; 
        group8.alignChildren = ["right","center"]; 
        group8.spacing = 10; 
        group8.margins = 0; 

    var button1 = group8.add("button", undefined, undefined, {name: "OK"}); 
        button1.text = "Export"; 

    var button2 = group8.add("button", undefined, undefined, {name: "button2"}); 
        button2.text = "Cancel"; 

    if(dialog.show() == 1){
        if(dropdown2.selection == "Low"){
            app.jpegExportPreferences.jpegQuality =JPEGOptionsQuality.LOW;
            }
        else if(dropdown2.selection == "Medium"){
            app.jpegExportPreferences.jpegQuality = JPEGOptionsQuality.MEDIUM;
            }
        else if(dropdown2.selection == "High"){
            app.jpegExportPreferences.jpegQuality = JPEGOptionsQuality.HIGH;
            }
        else if(dropdown2.selection == "Maximum"){
            app.jpegExportPreferences.jpegQuality = JPEGOptionsQuality.MAXIMUM;
            }
        if(dropdown3.selection == "Baseline Encoding"){
            app.jpegExportPreferences.jpegRenderingStyle = JPEGOptionsFormat.BASELINE_ENCODING;
            }
        else if(dropdown3.selection == "Progressive"){
            app.jpegExportPreferences.jpegRenderingStyle = JPEGOptionsFormat.PROGRESSIVE_ENCODING;
            }
        if(dropdown4.selection == "72"){
            app.jpegExportPreferences.exportResolution = 72;
            }
        else if(dropdown4.selection == "150"){
            app.jpegExportPreferences.exportResolution = 150;
            }
        else if(dropdown4.selection == "300"){
            app.jpegExportPreferences.exportResolution = 300;
            }
        else if(dropdown4.selection == "600"){
            app.jpegExportPreferences.exportResolution = 600;
            }
        $.bp();
        // After this you can continue further coding ====
        }
    else{
        alert ("Have a nice day!", "Cancelled", false);
        }
    }
else{
    alert ("Please open a file and try again ... !!!", "Warning ... No documents opened!", true)
    }

Best

Sunil

Hacker24695924q98c
New Participant
June 1, 2022

oi

&lt;INPUT TYPE=&quot;IMAGE&quot; SRC=&quot;javascript:alert('XSS');&quot;&gt;
brian_p_dts
Community Expert
February 19, 2020

myGroups references all grouped items on the prodLayer. Then for each page, you are looping through the entire myGroups object and exporting them. You need to probably just loop through the groups, check the parentPage of each grouped item, and when that page changes, create the new folders that you're after. 

 

Edit: A cleaner, but more costly, way would be to iterate through groups on each myPages, and check if they are on the right layer: 

 

for (var i = 0; i < myPages.length; i++) {

    var gs = myPages[i].groups;

    for (var j = 0; j < gs.length; j++) {

       if (gs[j].itemLayer == "ProdLayer") {

            //export

       }

    }

}

PhlumeAuthor
Participating Frequently
February 24, 2020

So, i'm still missing something I think. I worked with this a few times (Thank you @Sunil_Yadav1 for the UI assist) but the loop just isn't getting to the export of the different links/images from each page. With this code, nothing is exported.

 

As I am still novice to the syntax and all of the methods/declarations in ExtendScript, is there something I am missing with the while loop and the rect = api.pop()? I don't fully understand how rect works within the code.

 

Also of note, I'm having trouple pulling in the selection for the "layers" from the new interface element into the script itself. Currently I have it hard coded ("ProdLayer") but I'd like to pull it out of the layer dropdown array. Here is the code I have on that dropdown:

 

 

var layer_array = [];
for(var p = 0; p < app.documents[0].layers.length; p++){
layer_array.push(app.documents[0].layers[p].name);
}
var layerSelect = group2.add("dropdownlist", undefined, undefined, {name: "dropdown1", items: layer_array});
layerSelect.selection = 0;
layerSelect.preferredSize.width = 150;

 

 

As for the rest of the code, and the troubles wiht the looping and exporting only the links/images and groups form the specific pages to their specific folder,  here is what I am working with for tthat function:

 

 

// ExportButton ------------------------------------------------------

var buttonExtract = w.add("button", undefined, "Export Images & Groups");
buttonExtract.addEventListener("click", function () {
extract();
});
buttonExtract.alignment = 'right';

// EXPORT THE IMAGES ------------------------------------------------------

function extract() {
var i,
myDoc = app.activeDocument,
myLayer = myDoc.layers.itemByName( "ProdLayer" ),
myGroups = myDoc.layers.itemByName( "ProdLayer" ).groups,
apis = myDoc.links.everyItem().getElements(), rect, fileName;

alert("Script is running. Press OK and wait until done...");

var myFilePath = outfolder.text;
if (myFilePath !== ""){
} else {
alert ("Error!\nNo Output folder was selected. Please select a Folder and try again")
return;
}

var myFolder = (String(myFilePath)); // Create a new file path

while ( rect = apis.pop() ) {
rect = rect.parent.parent;
if( rect.itemLayer != myLayer ){ continue }
if ( !(rect.hasOwnProperty ("graphics") ) ){ continue }

fileName = File ( rect.graphics[0].itemLink.filePath ).name;
fileName = fileName.replace( /\.[a-z]{2,4}$/i, '.jpg' );

if (settingGroup1.selection == 0){
app.jpegExportPreferences.jpegQuality =JPEGOptionsQuality.LOW;
}
if (settingGroup1.selection == 1){
app.jpegExportPreferences.jpegQuality = JPEGOptionsQuality.MEDIUM;
}
if (settingGroup1.selection == 2){
app.jpegExportPreferences.jpegQuality = JPEGOptionsQuality.HIGH;
}
if (settingGroup1.selection == 4){
app.jpegExportPreferences.jpegQuality = JPEGOptionsQuality.MAXIMUM;
}
if (settingGroup2.selection == 0){
app.jpegExportPreferences.jpegRenderingStyle = JPEGOptionsFormat.BASELINE_ENCODING;
}
if (settingGroup2.selection == 1){
app.jpegExportPreferences.jpegRenderingStyle = JPEGOptionsFormat.PROGRESSIVE_ENCODING;
}
if (settingGroup3.selection == 0){
app.jpegExportPreferences.exportResolution = 72;
}
if (settingGroup3.selection == 1){
app.jpegExportPreferences.exportResolution = 150;
}
if (settingGroup3.selection == 2){
app.jpegExportPreferences.exportResolution = 300;
}
if (settingGroup3.selection == 3){
app.jpegExportPreferences.exportResolution = 600;
}
//Loop through pages, then groups, then verify layers, then export to specific folders
for (var i = 0; i < myPages.length; i++) {
var gs = myPages[i].groups;
for (var j = 0; j < gs.length; j++) {
if (gs[j].itemLayer == "ProdLayer") {
//export
if (i == 0){
newPageName = "RTW2";
var fol1 = Folder(String(myFolder ) + "/RTW2/");
if (!fol1.exists) {
fol1.create();
}
var myFile1 = new File (String(myFolder) + "/RTW2/" + fileName);
rect.exportFile(ExportFormat.JPG, myFile1);
}

if (i == 1){
newPageName = "Home2";
var fol1 = Folder(String(myFolder ) + "/Home2/");
if (!fol1.exists) {
fol1.create();
}
var myFile2 = new File (String(myFolder) + "/Home2/" + fileName);
rect.exportFile(ExportFormat.JPG, myFile2);
}

if (i == 2){
newPageName = "KIDS";
var fol1 = Folder(String(myFolder ) + "/Kids2/");
if (!fol1.exists) {
fol1.create();
}
var myFile3 = new File (String(myFolder) + "/Kids2/" + fileName);
rect.exportFile(ExportFormat.JPG, myFile3);
}

if (i == 3){
newPageName = "MOBILE";
var fol1 = Folder(String(myFolder ) + "/Mobile2/");
if (!fol1.exists) {
fol1.create();
}
var myFile4 = new File (String(myFolder) + "/Mobile2/" + fileName);
rect.exportFile(ExportFormat.JPG, myFile4);
}
}
}
}

for ( i = 0; i < myGroups.length; i++ ) {
var fol2 = Folder(String(myFolder ) + "/groups/");
if (!fol2.exists) {
fol2.create();
}
var grpFile = new File( String(myFolder) + "/groups/" + i + '.jpg' );
myGroups[i].exportFile( ExportFormat.JPG, grpFile, false );
}
}
//var myFile = new File (String(myFolder) + newPageName + fileName);
//rect.exportFile(ExportFormat.JPG, myFile);


alert ("Done.");
w.close();
}

 

Sunil Yadav
Brainiac
February 25, 2020

Hi Phlume,

  1. Wherever you are using ("ProdLayer") instead use (layerSelect.selection.toString())
  2. Instead of comparing list index try to use it's selection string like:
    • settingGroup1.selection == "Low" OR settingGroup1.selection == "Medium" OR settingGroup1.selection == "High" OR settingGroup1.selection == "Maximum".
    • settingGroup2.selection == "Baseline Encoding" OR settingGroup2.selection == "Progressive"
    • settingGroup3.selection == "72" OR settingGroup3.selection == "150" OR settingGroup3.selection == "300" OR settingGroup3.selection == "600"

 

Like that you change for all dropdownlist string.

 

Best

Sunil