Skip to main content
Shulipa Bernad
Inspiring
June 1, 2021
Answered

Run only selected items

  • June 1, 2021
  • 3 replies
  • 6102 views

Hey guys!
I am working on creating a dialog box that displays several checkboxes that correspond to each open document, but I need to create a function that performs something only on the checked items. Any suggestions: Thank you

var w = new Window ("dialog"); w.orientation = "row";
var panel1 = w.add ("panel");

ImgConteudo = documents;
for(i=0;i <ImgConteudo.length;i++){
  var  checkbox=  panel1.add("checkbox",  undefined, decodeURI(ImgConteudo[i].name));  
}

var  b1= w.add("button"); b1.text="Run";  
b1.onClick = function(){runCkeckoxs()};

function runCkeckoxs() {
        for (var i = 0; i < checkbox.length; i++) {
            if(checkbox[i].value) {
                    ImgConteudo[i];
                   alert("My Script");
              }
           }
}

w.show();
This topic has been closed for replies.
Correct answer Kukurykus

In runCkexkoxs function change first and second checkbox to panel1.children

3 replies

JJMack
Community Expert
Community Expert
June 1, 2021

I feel left out I tried to help told you checkbox does not seem to be an array. r-bin made it an array for you.....

JJMack
Shulipa Bernad
Inspiring
June 1, 2021
quote

I feel left out I tried to help told you checkbox does not seem to be an array. r-bin made it an array for you.....


By @JJMack

@r-bin  add the array and also that line of code app.activeDocument= ImgConteudo[i]; in the runCkeckoxs function; I will add your credits also in thanks.
@Kukurykus  relax buddy, I made the modifications you suggested and it wouldn't make sense for an action to work only on the active document or you didn't read the title ?, which differs from an alert for any action ??.

Kukurykus
Legend
June 1, 2021

In your original code there wasn't any action to perfrom like I said in the other post. If there was, there would be no doubt to additionally add or else change a command that selects other document than active one (that after your another post I pointed too). In other words saying, if you originally would have posted the code with 'desaturation', and then I've left a suggestion like I did, you had the full right to say it doesn't work. I'd have no problem to completely agree it fails. But when later you add something to code (when we're not aware you also don't know basic command how to select by script active document) and say it doesn't work with original code that already makes no sense.

 

It's the same like lately with smithcgl9043167, who expected the code I made for his specific case will work also in full range of possible situations he originally did not mention to me.

JJMack
Community Expert
Community Expert
June 1, 2021

checkbox does not seem to be an array.

var w = new Window ("dialog"); w.orientation = "row";
var panel1 = w.add ("panel");

ImgConteudo = documents;
for(i=0;i <ImgConteudo.length;i++){
  var  checkbox=  panel1.add("checkbox",  undefined, decodeURI(ImgConteudo[i].name));  
}

var  b1= w.add("button"); b1.text="Run";  
b1.onClick = function(){runCkeckoxs()};

function runCkeckoxs() {
        alert(checkbox.length); 
        for (var i = 0; i < checkbox.length; i++) {
            if(checkbox[i].value) {
                    ImgConteudo[i];
                   alert("My Script");
              }
           }
}

w.show();

 

JJMack
Kukurykus
Legend
June 1, 2021

You missed my answer 🙂

Kukurykus
KukurykusCorrect answer
Legend
June 1, 2021

In runCkexkoxs function change first and second checkbox to panel1.children

Shulipa Bernad
Inspiring
June 1, 2021

The alert actually triggered according to the number of documents, but it did not go through all the documents marked to apply a specific task, but only in the active document.

var w = new Window ("dialog"); w.orientation = "row";
var panel1 = w.add ("panel");

ImgConteudo = documents;
for(i=0;i <ImgConteudo.length;i++){
  var  checkbox=  panel1.add("checkbox",  undefined, decodeURI(ImgConteudo[i].name));  
}

var  b1= w.add("button"); b1.text="Run";  
b1.onClick = function(){runCkeckoxs()};

function runCkeckoxs() {
        for (var i = 0; i < panel1.children.length; i++) {
            if(panel1.children[i].value) {
                    ImgConteudo[i];
                   //alert("My Script");
                   executeAction(app.charIDToTypeID('Dstt'), undefined, DialogModes.NO);
              }
           }
}

w.show();
Legend
June 1, 2021

Check out this code. And don't listen to what Kukurykus says. 🙂

 

var w = new Window ("dialog"); w.orientation = "row";
var panel1 = w.add ("panel");

var ImgConteudo = documents;
var checkbox = [];
for(i=0;i <ImgConteudo.length;i++)
  checkbox[i] =  panel1.add("checkbox",  undefined, ImgConteudo[i].name);  

var  b1= w.add("button", undefined, "Run");  
b1.onClick = function(){runCkeckoxs()};

function runCkeckoxs() {
        for (var i = 0; i < checkbox.length; i++) {
            if(checkbox[i].value) {
                   app.activeDocument= ImgConteudo[i];
                   executeAction(app.charIDToTypeID('Dstt'), undefined, DialogModes.NO);
              }
           }
}

w.show();