Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Run only selected items

Engaged ,
May 31, 2021 May 31, 2021

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();
TOPICS
Actions and scripting
5.9K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

LEGEND , May 31, 2021 May 31, 2021

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

Translate
Adobe
LEGEND ,
Jun 01, 2021 Jun 01, 2021

Of course it doesn't work because you had not in your code any action to be performed yet. So there was nothing to correct, until you updated your code to see something doesn't work for you. The hints I gave you made the script to work as should. The other question you meet is another problem to solve as noone can know you don't know document must be active to use the command on it. Though previous answer of me is already correct solution change:

 

ImgConteudo[i];

 

to:

 

activeDocument = ImgConteudo[i]

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 31, 2021 May 31, 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
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
May 31, 2021 May 31, 2021

You missed my answer 🙂

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jun 01, 2021 Jun 01, 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_0-1622563701183.png

JJMack
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Jun 01, 2021 Jun 01, 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.....

JJMack_0-1622563701183.png


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 ??.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jun 01, 2021 Jun 01, 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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
People's Champ ,
Jun 01, 2021 Jun 01, 2021

This is not a reliable solution because there may be other elements in the panel. Your code is usually not modifiable. It solves the current minor problem, and not in the best way.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jun 01, 2021 Jun 01, 2021

If there were other elements you were right, but there're not of them, like many circumstances that may happen, 'noone' prepares code for, unless someone say it must be ready for them too.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
People's Champ ,
Jun 01, 2021 Jun 01, 2021

It was necessary to explain to the person that he was using the "var checkbox =" variable incorrectly, and not to offer a "clever" solution, understandable to a few.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jun 01, 2021 Jun 01, 2021

checkbox variable can be removed from '6th' line since the latter part of code dosn't use it.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Jun 01, 2021 Jun 01, 2021

@Kukurykus  All I did was just this:
1: I ran my script: Nothing worked.
2: Added the code snippet you gave me: The alert only fires on the active document and not on everyone, so I added a saturation action to check if it works correctly.
3: I ran script modified by @r-bin: It worked 100% as I imagined.
You can check the video illustration, see and draw all your conclusions.

I used google chrome browser.
20210601_200052.mp4
thanks

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jun 02, 2021 Jun 02, 2021

The title of your topic is 'Run only selected items'. Then in your description you wrote, you have script where each checkbox corresponds to each open document, and you need other one, that performs something on checked items.

 

First off all, the title doesn't say to perform an action on the document bound to selected item. Corresponded boxes to open documents also doesn't mean anything than only representation of each document yet. So we can't know what exactly had to happen as result. And finally you say to perform something on checked item. That is not clear what is that "something" and if checked items aren't just box items, that later let you update script on your own of anything you want.

 

The topic title confuses and leads into mistake. In your head you know what you want, but someone reading your post is not in your mind so is able to see only the plain text. You did not say you want to make any of documents active one after clicking appropriate checkbox. There is nothing about it. You also did not say if that 'something' is for you for example taking informations of related document, to do so, any document does not have to be set foremost. Similary is when you want to close that document, or else make it active, what after all is perfoming an action on that certain document. Yes, making specified document an active object is surely one of things you can do with document 😉


Next problem is that the content of runCkeckoxs function can't be executed as there were code mistakes made earlier in the code, the function items relate to. Before fixing significant bugs there's no clue are you aware of functionality of anything that happens in the aftermatch, so we can not know the intention of using ImgConteudo[i]; in your function. Whether that is something you put for other time, or you believed it makes document active, or else that's an remainder after in first instance you tried to alert it before doing the same with "My Script".


The solution you assume as correct was provided not after posting your original code, but later, when additionally you put in the code something that finally makes things clearer for audience. Then, even without asking the question, just posting sole code your desire clarify for others. Just see a code you have finally shared contains desaturation part, with which anyone later with minimum Photoshop coding experience understands mismatch in the snippet and that you surely don't look for unselected documents properties.


Due to your question, the answer I left is not what you needed, but what you wrote you want. More precise description on your side wouldn't make any extra posts like this one. If you said you want documents were set active for specific task then it was enough to say it. How we can know you wanted to do so whether via DOM or ActionManager and whatever way you would choose, prevent us from guessing you don't understand that selecting document manually in Photoshop needs the same scripting approach? Take into consideration my hint was given 6 minutes after your original post, then you were 'outside' for 16 hours. If my solution didn't fit your problem, why there weren't other users within this time suggesting its inconsistency, but only after you informed it desaturates the same document 3 times, the problem was solved immediatelly? You simply showed again with an update to code, so in no time got solution also not to already working lines but to something new that wasn't part of initial question.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines