Copy link to clipboard
Copied
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();
}
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"
...
Copy link to clipboard
Copied
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
}
}
}
Copy link to clipboard
Copied
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();
}
Copy link to clipboard
Copied
Hi Phlume,
Like that you change for all dropdownlist string.
Best
Sunil
Copy link to clipboard
Copied
Thank you for the asist with the selection.toString() syntax. This was what ai was missing.
I'm now left with two issues... one more troublesome than the other.
If I run the script, it seems to run smoothly with no errors. I still need to adjust the code to fit my needs, but that is the second problem. The MAIN problem is whenever the script is run a second time, Indesign crashes. I have no idea what may be left "open" on the back end that causes a crash when the script initializes a second time. I have tried to set w = null; and myDoc = null; at the beginning, just to make certian they are emptied, but i think the w.close(); at the end does that for me, correct?
Here is the full script to test in case I missed something with the panel creation at the beginning:
#targetengine "session";
var myDoc = null;
var w = null;
var myDoc = app.activeDocument;
var myPages = app.activeDocument.pages;
var w = new Window("palette", "Export JPG Images");
app.activate();
w.alignChildren = "left";
// PANEL SETUP
var byStyle = w.add("group");
var exportSettingsPanel = byStyle.add('panel', undefined, 'Export Settings', {borderStyle: 'gray'});
exportSettingsPanel.alignChildren = ["left","top"];
exportSettingsPanel.orientation = "column";
exportSettingsPanel.spacing = 10;
exportSettingsPanel.margins = 10;
exportSettingsPanel.preferredSize.width = 250;
//==========
// DROPDOWN ARRAYS
var expArray = ["Low", "Medium", "High", "Maximum"];
var formArray = ["Baseline", "Progressive"];
var resArray = ["72", "150", "300", "600"];
//=======
// LAYER SELECT
var group2 = exportSettingsPanel.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 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;
var divider1 = exportSettingsPanel.add("panel", undefined, undefined, {name: "divider1"});
divider1.alignment = "fill";
//========
// QUALITY GROUP 1
var settingGroup1 = exportSettingsPanel.add("group");
settingGroup1.orientation = "row";
settingGroup1.alignChildren = ["left","center"];
settingGroup1.spacing = 10;
settingGroup1.margins = 0;
var statictext1 = settingGroup1.add("statictext", undefined, "Export Quality: ");
statictext1.preferredSize.width = 100;
settingGroup1 = settingGroup1.add("dropdownlist", undefined , expArray);
settingGroup1.alignChildren = ["left","center"];
settingGroup1.preferredSize.width = 150;
//======
// JPEG FORMAT GROUP 2
var settingGroup2 = exportSettingsPanel.add("group");
settingGroup2.orientation = "row";
settingGroup2.alignChildren = ["left","center"];
settingGroup2.spacing = 10;
settingGroup2.margins = 0;
var statictext2 = settingGroup2.add("statictext", undefined, "JPEG Format : ");
statictext2.preferredSize.width = 100;
settingGroup2 = settingGroup2.add("dropdownlist", undefined , formArray);
settingGroup2.alignChildren = ["left","center"];
settingGroup2.preferredSize.width = 150;
//=====
// RESOLUTION GROUP 3
var settingGroup3 = exportSettingsPanel.add("group");
settingGroup3.orientation = "row";
settingGroup3.alignChildren = ["left","center"];
settingGroup3.spacing = 10;
settingGroup3.margins = 0;
var statictext3 = settingGroup3.add("statictext", undefined, "Resolution : ");
statictext3.preferredSize.width = 100;
settingGroup3 = settingGroup3.add("dropdownlist", undefined , resArray);
settingGroup3.alignChildren = ["left","center"];
settingGroup3.preferredSize.width = 150;
//======
/*PROGRESS GROUP
var myProgressPanel,
myMaximumValue = 300,
myProgressBarWidth = 300;
myCreateProgressPanel(myMaximumValue, myProgressBarWidth);
function myCreateProgressPanel(myMaximumValue, myProgressBarWidth){
myProgressPanel = new Window("window", "Processing Images");
with (myProgressPanel) {
myProgressPanel.myProgressBar = add("progressbar", [12, 12, myProgressBarWidth, 24], 0, myMaximumValue);
}
return
}
//================= */
settingGroup1.enabled = true
settingGroup1.selection = 2;
settingGroup2.enabled = true
settingGroup2.selection = 1;
settingGroup3.enabled = true
settingGroup3.selection = 0;
// Choose Folder ------------------------------------------------------
var folder_group = w.add('group');
folder_group.add("statictext", undefined, "Output Folder: ");
var outfolder = folder_group.add('edittext {characters: 15}');
var pick_button = folder_group.add('iconbutton', undefined, folder_icon(), {
style: 'toolbutton'
});
pick_button.onClick = function () {
var f = Folder(outfolder.text).selectDlg('Save in...')
if (f != null) {
outfolder.text = f.fullName + '/';
}
}
outfolder.onDeactivate = function () {
if (outfolder.text !== "" && !Folder(outfolder.text).exists) {
outfolder.text = folder.text += " does not exist";
w.layout.layout();
outfolder.active = true;
} else
if (outfolder.text !== "" && outfolder.text.slice(-1) !== "/") outfolder.text += "/";
}
// 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, gr,
myDoc = app.activeDocument,
myLayer = myDoc.layers.itemByName( layerSelect.selection.toString() ),
myGroups = myDoc.layers.itemByName( layerSelect.selection.toString() ).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 == "Low"){
app.jpegExportPreferences.jpegQuality =JPEGOptionsQuality.LOW;
}
if (settingGroup1.selection == "Medium"){
app.jpegExportPreferences.jpegQuality = JPEGOptionsQuality.MEDIUM;
}
if (settingGroup1.selection == "High"){
app.jpegExportPreferences.jpegQuality = JPEGOptionsQuality.HIGH;
}
if (settingGroup1.selection == "Maximum"){
app.jpegExportPreferences.jpegQuality = JPEGOptionsQuality.MAXIMUM;
}
if (settingGroup2.selection == "Baseline"){
app.jpegExportPreferences.jpegRenderingStyle = JPEGOptionsFormat.BASELINE_ENCODING;
}
if (settingGroup2.selection == "Progressive"){
app.jpegExportPreferences.jpegRenderingStyle = JPEGOptionsFormat.PROGRESSIVE_ENCODING;
}
if (settingGroup3.selection == "72"){
app.jpegExportPreferences.exportResolution = 72;
}
if (settingGroup3.selection == "150"){
app.jpegExportPreferences.exportResolution = 150;
}
if (settingGroup3.selection == "300"){
app.jpegExportPreferences.exportResolution = 300;
}
if (settingGroup3.selection == "600"){
app.jpegExportPreferences.exportResolution = 600;
}
for(var myCount= 0; myCount< myPages.length; myCount++) {
if (myPages.item(myCount).appliedSection.name != "") {
myPages.item(myCount).appliedSection.name = "";
//myProgressPanel = myCreateProgressPanel (100, 400);
//myProgressPanel.show();
//myProgressPanel.myProgressBar.value = (100/myPages.length)*myCount;
//$.write ("images" + myPages.length[myCount]);
}
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 ( gr = 0; gr < myGroups.length; gr++ ) {
var fol2 = Folder(String(myFolder ) + "/groups/");
if (!fol2.exists) {
fol2.create();
}
var grpFile = new File( String(myFolder) + "/groups/" + gr + '.jpg' );
myGroups[gr].exportFile( ExportFormat.JPG, grpFile, false );
}
}
//var myFile = new File (String(myFolder) + newPageName + fileName);
//rect.exportFile(ExportFormat.JPG, myFile);
}
}
alert ("Done.");
w.close();
}
function folder_icon() {
return "\u0089PNG\r\n\x1A\n\x00\x00\x00\rIHDR\x00\x00\x00\x16\x00\x00\x00\x12\b\x06\x00\x00\x00_%.-\x00\x00\x00\tpHYs\x00\x00\x0B\x13\x00\x00\x0B\x13\x01\x00\u009A\u009C\x18\x00\x00\x00\x04gAMA\x00\x00\u00B1\u008E|\u00FBQ\u0093\x00\x00\x00 cHRM\x00\x00z%\x00\x00\u0080\u0083\x00\x00\u00F9\u00FF\x00\x00\u0080\u00E9\x00\x00u0\x00\x00\u00EA`\x00\x00:\u0098\x00\x00\x17o\u0092_\u00C5F\x00\x00\x02\u00DEIDATx\u00DAb\u00FC\u00FF\u00FF?\x03-\x00@\x0011\u00D0\b\x00\x04\x10\u00CD\f\x06\b \x16\x18CFR\x12L\u00CF*\u0092e\u00FE\u00F7\u009F!\u008C\u0097\u008By\x19\u0088\u00FF\u00F7\u00EF\x7F\u0086\u00CF\u00DF\u00FE\u00C6dOz\u00B2\x1C\u00C8\u00FD\x0F\u00C5\x04\x01@\x00\u00A1\u00B8\x18f(##C\u00AD\u009Ak9\u0083\u008E_\x17\u0083i\u00D4<\x06\x16f\u00C6\u009A\t\u00D9\u00D21@%\u00CC@\u00CCH\u008C\u00C1\x00\x01\u00C4\b\u008B<\u0090\u008Bg\x14\u00CAF212,\u00D3q\u00CDb\u00E0\x16Rf`\u00E3\x14f`\u00E5\x14d\u00F8\u00FF\u00E7'\u00C3\u00FE\u00D9a\x18\u009A\u00FF\u00FE\u00FB\u009Fq\u00F3\u00F1\u00CF%\x13\u00D6\u00BE\u00FE\u0086\u00EE\x13\u0080\x00bA\u00B6\x04d\u00A8\u00A1_\x15\u00D8@\u0098\u00A1\u00AC\u00EC\u00FC\f\u00CC<\\\f^\u00A5\u00A7P\f\u00FD\u00F6\u00EE.\u00C3\u00DD\x03\x1D3\u00BE\u00FF<\u00FF\f\u00C8\u00DD\x01\u00C4\x7F\u0090\r\x07\b \x14\u0083A\x04\u00CCP6\x0E!\u0086\u00A3s\x03\x18XY\x19\x19\u00FE\x01\u00C3\x07\x14\u00D6\x7F\u00A1\u00F4\u009F\u00BF\f`\fb\x03}\u00BC\u00A9+U\u0092\u00E1\u00F9\u009B\u00BF\u00BA\u00FD\u00EB_]\u0083\u00C5\x03@\x00\u00B1\u00A0\u00877\u00CC\u00A5\u00F7\x0F\u00F72\u00C8\x1B\x052p\n(\u0080\u00A5\u00FE\u00FD\u00F9\u00C5\u00F0\u00F7\u00F7o\u0086?\u00BF\x7F1\u00FC\u00F9\x05\u00A1\u00FF\u00FE\u00F9\r\u00C6\u009F\u009E_\x00\u00C6\u00C3\u00FDI@\u0085^@\u00FC\x1B\x14J\x00\x01\u00C4\u0084\u00EEb\u0090\u00A1\u00BF>\u00BFd\u00F8\u00FC\u00EA:\x03\u00A7\u00A0\"\u00C3\u00BF\u00BF\u00BF\x19\u00FE\u00FF\u00FD\x034\u00F8\x0F\u00D8\u0090\x7F\u00BFAl \u00FD\u00EF/P\u00EE\x0FX\u00FE\u00C0\u00B1+\f\u008F^\u00FD<\b\u00D4\u00CE\x01\u008B`\u0080\x00\u00C2\b\n\x0E\x1EI\u0086\u009B\u00DB\u00CA\x19\u0084\u0094\u00EC\u0081\u0081\u00CE\u00CA\u00C0\u00C4\x04\u00F4\u00FE\u00AF_`\u0083A\u0086\u0082]\u00F9\x17j8\u0090\u00FE\u00F1\u00E9)\u00C3\u00D6\x13/\x19\u00EE\u00BFa\u00D8\u00C2\u00CE\u00C6\u00CE\n5\u00F8\x0F@\x00ad\u0090W7\u00B60\u00FC\u00FB\u00FF\u0087\u0081KX\x05\u00E8\u00D2\u00DF`\x03\u00FE\u0082]\x0Bq\u00DD\u00BF\u00BF0\u0097\u00FE\x05\u0086\u00EF_\u0086\u00C3G\u008E1\u00DCy\u00FE}9\u00D0\u00D0O\u00C8I\x11 \u00800\f~xr\x06\u0083\u00A0\u00825\u00C3\u00FF\x7FPW\x01\r\x04Y\x00q\u00E9_ \u0086\x1A\x0E\u0094\u00FF\t\f\u00B2\u0095\u00FB\u009F20\u00B3p\u00CC\u0082\u00A6\n\x10\u00FE\x07\u008A<\u0080\x00\u00C20\u0098\u009DO\u0082\u0081\u009DG\x02\x12\u00AE@\u00CD \u0083\u00C0^\x07bP\u00E4\u00FD\u0083\x1A\u00FE\x1F\u00E8\u00ABS'\u008F2\u00DC{\u00FE}\x1D;;\u00C7\x0B\u00A0\u00D6\u009F@\u00FC\x0B\x14q \u0083\x01\x02\u0088\x05\u00C5P6&\u0086\u00F6i\u00DB\x18^\u00BE[\x0FNJ\u00BF\u00FF\u00FCc\x00&\x00\u0086\u00DF\u00BF!l`\x10\x03\u0093\u00D9\x7F0\u00FE\x0B\u00CCX\u00DF\x7F\u00FEe`e\u00E3\u009C\t5\u00F0'\u0092\u008B\x19\x00\x02\b9\u00E7\u0081\x02\u009E\x0B\u0088\u00F9\u00A14+\x119\u00F7\x1F\u00D4\u00D0/P\u00FC\x1Dj8\x03@\x00!\u00BB\u00F8?T\u00F0'\u0096\u00CCC\u00C8\u00E0\u00EFP\u00FA\x1FL\x02 \u0080X\u00D0\x14\u00FD\u0086\u00DA\u00FC\u0083\u00C8\"\x15\u00E6\u0098\u00DF\u00C8\u00C1\x00\x02\x00\x01\x06\x000\u00B2{\u009A\u00B3\x1C#o\x00\x00\x00\x00IEND\u00AEB`\u0082";
}
w.show();
Copy link to clipboard
Copied
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%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%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
Copy link to clipboard
Copied
oi