Populate a dialog with multi selectable functions

Anyone, especially newbies, asking for help with Photoshop Scripting and Photoshop Automation - as opposed to those contributing to discussion about an aspect of Photoshop Scripting

Moderators: Tom, Kukurykus

essejesse

Populate a dialog with multi selectable functions

Post by essejesse »

It's been a while since I've posted, because the work that this site helped me do has been going great. I've had to tweak some scripts here and there, but now I'm back with a bigger conundrum. I always feel like I'm operating on a level 1 or 2 steps below where my knowledge needs to be to actually do the stuff I want to.

Here's the situation. Earlier this year, I created multiple scripts that do similar things, but with different specifications. We save images at three standard resolutions for the marketing team, and I automated the whole process. That rocks.

We also save images for specific vendors from time to time. I've created separate scripts for them, but now the frequency of needing them is getting so high, I've been asked to combine them in a specific way.

What I need it to do is for the first three resolutions happen normally, but then a dialog comes up and asks if the user wants to do any of the vendor specific sizes, the user can select multiple options, and hit OK, the script takes the selected options and runs corresponding functions, in order.

Creating this dialog is what I need help with. I'm trying to create the dialog in isolation so I can more easily see what is going on. I've repurposed an old dialog, so some of the things here are commented because they don't actually apply. There are four sample functions in there as well, here is where I'm at:

Code: Select allvar dlg = new Window('dialog', "Would you like to run any .com processes?", [500,300,840,525]);
dlg.functionList = dlg.add('listbox', [15,15,325,137], 'field', {multiselect: true});
// populate the list with the script functions names;
//for (var o = 0; o < myDoc.pathItems.length; o++) { //this is not right yet and was meant for paths originally
//dlg.functionList.add ("item", myDoc.pathItems[o].name); //this is not right yet and was meant for paths originally
//};
dlg.functionList.add (alert(), alert2(), alert3(), alert4()) //my lame attempt to add the functions, does not work
dlg.functionList.items[0].selected = true;
// buttons for ok, and cancel;
dlg.buttons = dlg.add('panel', [15,152,325,210], '');
dlg.buttons.buildBtn = dlg.buttons.add('button', [160,14,291,39], 'Run!', {name:'ok'});
dlg.buttons.cancelBtn = dlg.buttons.add('button', [14,14,145,39], 'Nope', {name:'cancel'});
// show the dialog;
dlg.center();
var myReturn = dlg.show ();
    if (myReturn == true) {
    alert()
    alert2()
    alert3()
    alert4()
    } //I know that this would mean selecting anything runs all of them. That's something else I need help with
   
function alert() {
    alert ("This is function 1")
    }
   
function alert2() {
    alert ("This is function 2")
    }
   
function alert3() {
    alert ("This is function 3")
    }
   
function alert4() {
    alert ("This is function 4")
    }

I also mention in one of the notes in there, the selection and clicking of Run! will just do all 4 functions. That's my other question.

To sum up:
• How would I populate the selection dialog with the functions contained within the script?
• How would I determine which selections were made and run the corresponding function, leaving out the ones that weren't selected?


Thanks for any advice, I'll be poking around in the meantime and will update with any potential breakthroughs.
essejesse

Populate a dialog with multi selectable functions

Post by essejesse »

I'm thinking I can just ask if the user wants to save any of the vendor specific files, and if so, then ask this one? that one? etc. if yes, then it does it, otherwise, move on to next step.

I'd still like to be able to add these all to a list box and have a user select which, because that seems like a smarter way to do it, but I think a workaround might get me through it for today.

Please do let me know if anyone has any thoughts on this though. I'm always looking to improve my scripts.

EDIT: Also, I realized that I shouldn't be calling one of the alert functions "alert" so I put a 1 at the end. Now that portion looks like this:
Code: Select all    if (myReturn == true) {
    alert1()
    alert2()
    alert3()
    alert4()
    }
pfaffenbichler

Populate a dialog with multi selectable functions

Post by pfaffenbichler »

Does this help?
Code: Select all2014, use it at your own risk;
#target photoshop
var dlg = new Window('dialog', "Would you like to run any .com processes?", [500,300,840,525]);
dlg.functionList = dlg.add('listbox', [15,15,325,137], 'field', {multiselect: true});
dlg.functionList.add ("item", "alert1()");
dlg.functionList.add ("item", "alert2()");
dlg.functionList.add ("item", "alert3()");
dlg.functionList.add ("item", "alert4()");
dlg.functionList.items[0].selected = true;
// buttons for ok, and cancel;
dlg.buttons = dlg.add('panel', [15,152,325,210], '');
dlg.buttons.buildBtn = dlg.buttons.add('button', [160,14,291,39], 'Run!', {name:'ok'});
dlg.buttons.cancelBtn = dlg.buttons.add('button', [14,14,145,39], 'Nope', {name:'cancel'});
// show the dialog;
dlg.center();
var myReturn = dlg.show ();
if (myReturn == true) {
if (dlg.functionList.items[0].selected == true) {alert1 ()}
if (dlg.functionList.items[1].selected == true) {alert2 ()}
if (dlg.functionList.items[2].selected == true) {alert3 ()}
if (dlg.functionList.items[3].selected == true) {alert4 ()}
};

function alert1() {
alert ("This is function 1")
};

function alert2() {
alert ("This is function 2")
};

function alert3() {
alert ("This is function 3")
};

function alert4() {
alert ("This is function 4")
};
edited
essejesse

Populate a dialog with multi selectable functions

Post by essejesse »

Wow, yes, it totally does. So I see the difference, but if you have time, could you explain the different ways you can add things to a listbox? For example, I see that you specified things four separate times, and that you first specified that they are items, and then specified what item they were. Are there other types of things you can add to list boxes? Are there other fields you can fill out within the () to change how things work?

I also now understand how you delineated between which were selected and made each function only for that one, rather than my original. That one frustrates me, because I'm pretty sure I should have known that.

Thanks a ton, this really is exactly what I was looking for and I'm pretty sure I can make it work for the exact purposes I have, given what you've provided.
pfaffenbichler

Populate a dialog with multi selectable functions

Post by pfaffenbichler »

You could define the items on creation of the listbox.
Code: Select alldlg.functionList = dlg.add('listbox', [15,15,325,137], [1,2,3,4], {multiselect: true});

As for the Properties of ListBoxes and ListItems please refer to ESTK’s Help > Object Model Viewer > ScriptUIClasses.
essejesse

Populate a dialog with multi selectable functions

Post by essejesse »

Thanks again, you've actually just shown me the biggest mistake I have been making when trying to figure things out with ESTK. I had, for no good reason, never bothered to look into anything but Photoshop's object model. Switching to ScriptUI Classes is going to help me answer a ton of my own questions.

Like I said before, in terms of Javascript and specifically scripting for Photoshop, I always feel like I'm 1 or 2 levels of knowledge below where I need to be (maybe more). It's nowhere even close to my primary job function to do this, but I'm lucky enough to have people around me here who see the value in it, and I find it enjoyable.