Need script that check selection content and count layers

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

DanielR

Need script that check selection content and count layers

Post by DanielR »

Some forum told me to add...

<menu>automate</menu>

To the script, and it is possible to show in the automate section instead. Here I can assign a keyboard shortcut to it ?

What do you think ?

Thank you.
txuku

Need script that check selection content and count layers

Post by txuku »

I found the error :

You add line 31 after the line docRef.selection.load (selAlpha);
Code: Select alldocRef.activeLayer = docRef.layers[i+1];
docRef.activeLayer = docRef.layers;

Yes a keyboard shortcut or a .atn script.
DanielR

Need script that check selection content and count layers

Post by DanielR »

thank you very much. No it work perfectly except two things...

1) The last layer is always visible, even if there are color inside selection there or not, but it is not counted if no color as it should. How do i make last layer deselect if no color ?

2) The script does not show in Photoshop CS6 script menu, what can I do to make it show ?

Thank you VERY VERY much.
pfaffenbichler

Need script that check selection content and count layers

Post by pfaffenbichler »

2) The script does not show in Photoshop CS6 script menu, what can I do to make it show ?
Have you put the jsx-file into the program’s Presets/Scripts-folder?
DanielR

Need script that check selection content and count layers

Post by DanielR »

yes.. the .jsx file is in the photoshop>presets>scripts folder. It shows in PSCS5, but not in PSCS6. Very strange.
txuku

Need script that check selection content and count layers

Post by txuku »

DanielR wrote:thank you very much. No it work perfectly except two things...

1) The last layer is always visible, even if there are color inside selection there or not, but it is not counted if no color as it should. How do i make last layer deselect if no color ?

.....................................................


I do not understand???

Can you send me the. Psd with the saved selection ?



DanielR wrote:.........................................
2) The script does not show in Photoshop CS6 script menu, what can I do to make it show ?
...............


Indeed scripts. Jsx pre-installed do not appear in the menu ???
DanielR

Need script that check selection content and count layers

Post by DanielR »

Thanks for your answer.

I have attached the file I use to test the script CS6 file, and also the .jsx file with your script. There are two lines of black color on different layers.

When I run script while having the upper left black line selected, it counts correctly but leaves the last layer visible even if there are no color in selection there.

If I select the lower right black line, and run script, it counts the colored layer with one number to small. It counts 5, when it should be 6, but the visible layers are correct.

Is it possible to fix script you think ? And make it show in CS6 script menu somehow ? Thank you VERY much for your help.

------------------------------------

Merci pour votre réponse.

J'ai joint le fichier que j'utilise pour tester le script CS6 fichier, ainsi que le fichier. Jsx avec votre script. Il ya deux lignes de couleur noire sur des calques différents.

Quand je lance le script tout en ayant la ligne supérieure gauche noir sélectionné, il compte correctement mais laisse la dernière couche visible, même s'il n'y a pas de couleur dans le choix là-bas.

Si je sélectionne la ligne inférieure droite noir, et exécuter un script, il compte la couche colorée avec un certain nombre de petits. Il compte 5, alors qu'il devrait être de 6, mais les calques visibles sont corrects.

Est-il possible de fixer le script que vous en pensez? Et faire apparaître dans les CS6 menu script en quelque sorte? Merci beaucoup pour votre aide.
txuku

Need script that check selection content and count layers

Post by txuku »

hum .............

Without background ?

Code: Select all//desactiveTransparent.jsx

var docRef = activeDocument;
var selAlpha = docRef.channels.add();
//selAlpha.name = "test";
docRef.selection.store(selAlpha) //Memoriser la selection
var calcOpacity = 50; //opacite des calques en %
var num = new Array;
var k = 0;

for ( j=0;j<docRef.layers.length;j++) //masquer tous les calques
     {
        docRef.layers[j].visible=false;
     }
//var Blanc = new SolidColor();
//Blanc.rgb.red=Blanc.rgb.green=Blanc.rgb.blue=255;

if (docRef.layers.length > 1)
{
  // docRef.layers[docRef.layers.length].visible=false; //masque le calque d arriere plan
   
   for(i=0; i < docRef.layers.length; i++)
  {
      docRef.activeLayer = docRef.layers;
      docRef.layers.visible = true;
     
      try
      {
        //docRef.selection.selectAll();
        docRef.selection.load(selAlpha); //docRef.channels["test"] );//selAlpha
      docRef.activeLayer = docRef.layers[i+1];
        docRef.activeLayer = docRef.layers;
        docRef.selection.copy();
        docRef.selection.deselect();
        docRef.layers.visible = false;
     
      }
      catch(e)  //si la selection est vide : erreur pour copy()
      {
          docRef.layers.visible = false;
          num[k] = i;
          k=k+1;
          docRef.selection.deselect();
      }
   }   
}

//alert(num)

for(i=0; i < docRef.layers.length - 1; i++)  // rend tous les calques visibles
{
      docRef.activeLayer = docRef.layers;
      docRef.layers.visible = true;
      docRef.layers.opacity = calcOpacity;
}       

//docRef.layers[docRef.layers.length].visible=true;  //arriere plan visible

for(i=0; i < num.length; i++)   // masque les calques selectionnes tout blancs
{
      docRef.activeLayer = docRef.layers[num];
      docRef.layers[num].visible = false;
}

//docRef.activeLayer = docRef.layers[docRef.layers.length-1] //rend l arriere plan actif
docRef.selection.load(selAlpha); //docRef.channels["test"] );//selAlpha
var calcVis = (docRef.layers.length) - num.length;
alert( "Number of Dots in position = " + calcVis );// JavaScript Document
DanielR

Need script that check selection content and count layers

Post by DanielR »

Thank you !!! Now the script showed up in script menu one time I opened CS6, but next time did not show ? Strange.. I think it is CS6 bug.

Script works almost perfect now, except that it does not check last layer. If there is a dot there, it will not count it and not make layer visible.

I must thank you again for all your help, you are very helpful. I tried to change the loop criteria from < to <=, but it didn't work, the script crashed. I believe it is some kind of minor loop error checking one layer less than in stack.

What do you think ?
DanielR

Need script that check selection content and count layers

Post by DanielR »

Je vous remercie! Maintenant, le script est apparu dans le menu script d'une fois que j'ai ouvert CS6, mais la prochaine fois ne pas montrer? Étrange .. Je pense qu'il est CS6 bug.

Script fonctionne presque parfait maintenant, sauf qu'il ne vérifie pas la dernière couche. S'il ya un point là-bas, ce ne sera pas le compter et ne pas faire calque visible.

Je dois vous remercier encore une fois pour votre aide, vous êtes très utile. J'ai essayé de changer les critères de boucle <à <=, mais il ne fonctionne pas, le script s'est écrasé. Je crois que c'est une sorte d'erreur de boucle mineure vérifier une couche inférieure dans la pile.

Que pensez-vous?