Add a mask on all selected layers.

Hello guys! I'm here looking for a script that adds the mask on all selected layers.

Pictures.png

Sorry, I found that I had made a change of course, it should work now.

#target photoshop;
app.bringToFront();

if(documents.length) main();
function main(){
var selectedlayers = getSelectedLayersIdx();
selectedlayers.reverse();
for(var z in selectedlayers){
    selectLayerByIndex(selectedlayers[z]);
    selectLayerData();
     createMask();
    }
app.activeDocument.selection.deselect();
for(var a in selectedlayers) {selectLayerByIndex(selectedlayers[a],true);}
};
function getSelectedLayersIdx(){
      var selectedLayers = new Array;
      var ref = new ActionReference();
      ref.putProperty(charIDToTypeID('Prpr'), stringIDToTypeID('targetLayers'));
      ref.putEnumerated( charIDToTypeID('Dcmn'), charIDToTypeID('Ordn'), charIDToTypeID('Trgt') );
      var desc = executeActionGet(ref);
      if( desc.hasKey( stringIDToTypeID( 'targetLayers' ) ) ){
         desc = desc.getList( stringIDToTypeID( 'targetLayers' ));
          var c = desc.count;
          var selectedLayers = new Array();
          for(var i=0;i 
         

Tags: Photoshop

Similar Questions

  • create masks at all levels

    Hi all

    I have a problem that I can't solve

    I looked in the forum but have not found answers

    the problem is the following:

    I have a lot of with layered psd files

    I would add to all these levels a white mask

    and if a certain level is already present are not to the update

    you think you can do?

    Thank you

    As c.pfaffenbichler says your caller layers Adjusment as levels, in any case, I understand what you now, the script I posted can be easily modified to put on a mask for all adjustment layers, but I won't... I see this forum as a forum for people who want to learn and not as a forum where people just asked some scripts. That's why I took the time to explain as I understand what makes each line of the script I posted it... Others are more than welcome to complete the description if I did not explain well... I know that there are people with experience of many here since I learned a lot, and for that I am eternally grateful. Here is the script with comments for almost every line:

    app.activeDocument.suspendHistory("BCM_aMaskForEveryLevels", "main()");//this line just creates one step in the history named BCM_aMaskForEveryLevels
    function main(){// the main function
      var currentSlections = getSelectedLayersIds();// store in a variable the selected layers so at the end of the script they could be reselected
      // in the next 5 lines I am founding the number of the layers in the document
      // with AM scripting layers doesn't have parents and childrens, and they have certain attributes that can be read in order to find out what kind of a layers they are
      // the advantage of using AM in looping throw layers it's the fact that it's fast and you don't have to select the layer in order to find something about it
      var ref0 = new ActionReference();//an action reference
      ref0.putProperty( charIDToTypeID( 'Prpr' ), stringIDToTypeID('numberOfLayers') );// define one property for the reference in order to look only for that property later,
      // without this upper line the resulting descriptor will be filled with a lot of information and if you have a lot of layers in the document this step could take a few seconds
      ref0.putEnumerated( charIDToTypeID( "Dcmn" ), charIDToTypeID( "Ordn" ), charIDToTypeID( "Trgt" ) );// here the refence will be for the selected document, usualy when you use an putEnumerated you are getting the selected object
      var desc0 = executeActionGet(ref0);//get's the descriptor for the reference
      var i = desc0.getInteger(stringIDToTypeID('numberOfLayers'));// find the number of the layers in the document and put it to the variable i
    
      var idWithMask = null;// this is a variable that will be used later in the script
      for(i; i > 0 ; i--){//start the loop, at the start of the loop i is equal with the number of layers in the document, and with each itteration it's substracting 1 from i until, i will get to 0, then the loop will stop
        ref = new ActionReference();// create a new reference
        ref.putIndex( charIDToTypeID( 'Lyr ' ), i );// the index it's the position of the layer in the layer pallete, so here the script it's referenceing with each itteration of the loop each layer without selecting it
        var desc = executeActionGet(ref);//get the descriptor of the referenced layer
        var layerName = desc.getString(charIDToTypeID( 'Nm  ' )); //this is how you get the name of the referenced layer
        var Id = desc.getInteger(stringIDToTypeID( 'layerID' ));//this is how you get the id of the referenced layer, the id's are unique and they doesn't change
        var ls = desc.getEnumerationValue(stringIDToTypeID("layerSection"));// this is how you can see if the referenced layer it's a group or not
        ls = typeIDToStringID(ls);// There are 3 values that the layerSection can return: "layerSectionStart", "layerSectionContent", "layerSectionEnd"
        // with AM you have a group like this:
        //   ---- "layerSectionStart" -represented in the layer palette as the folder
        //        "layerSectionContent" - any layer that's inside the group or outside the group
        //        "layerSectionEnd" - you can't see this layer in the layer palette, but when you find one it means that it's the end of some group, and all the previous layers where inside that group.
    
        var vis = desc.getInteger(stringIDToTypeID( 'visible' ));//how you get the visibility of of the referenced layer
    
        if(isAdjusmentLayerLevelsByID(Id) == true){//if it's an levels layer.... go to the decalartion of the function to see what it's doing
          if(hasMaskByID(Id) == false){//if it doesn't has a mask, ...go to the decalartion of the function to see what it is doing
            if(idWithMask == null){//when the script finds the first levels layer that doesn't have a mask, it will select it and create a mask for it
              multiSelectByIDs(Id);//select the layer by it's id
              makeFirstMask();//make a mask, this function it's just copied from the scriptListenerLog
              idWithMask = Id;// change the variable so now it will have the value of the id with the first white mask,
              // I've done these 3 previous lines because I couldn't found a way to create a white mask by referencing the layer id, the only way it worked was just to create it by selecting it and record the creation of the mask
              // also I'm storing the id of the first layer with the white mask because I want to duplicate the mask when finding other levels layers, this will make the script faster and it won't need to select the layer
            }else{//duplicate from the first created mask
              duplicateMaskByID(idWithMask, Id);//I'm duplicating the white mask from the first layer, to the referenced layer that we know it's a levels layer because it's in the if
            }
          }
        }
      }
      multiSelectByIDs(currentSlections);// now the loop was finished, all the script needs to do is to select back the layers that where selected before satrting the script
    }
    function doesIdExists( id ){//this function test to see if the id exists
      var res = true;// the returning variable
      var ref = new ActionReference();// create an reference
      ref.putIdentifier(charIDToTypeID('Lyr '), id);// reference a layer by it's id
        try{var desc = executeActionGet(ref)}catch(err){res = false};// if the layer doesn't exists it should give an error, when tring to get the descriptor for it, that's why I've put this in a try and catch
        return res;// the returned value
    }
    function multiSelectByIDs(ids) { //this function select more than one layer by id's
      if( ids.constructor != Array ) ids = [ ids ];//if the input it's not an array make an array with that single id
        var layers = new Array();//create an empty array
        var desc12 = new ActionDescriptor();// create a descriptor
        var ref9 = new ActionReference();//create a reference
        for (var i = 0; i < ids.length; i++) {// for each id in the input array
          if(doesIdExists(ids[i]) == true){// check to see if the id still exists
              layers[i] = charIDToTypeID( "Lyr " );//append a layer class to the layers array
              ref9.putIdentifier(layers[i], ids[i]);//reference each layer by the id
          }
        }
        desc12.putReference( charIDToTypeID( "null" ), ref9 );//put the reference to the descriptor
        executeAction( charIDToTypeID( "slct" ), desc12, DialogModes.NO );//this executes the select action by using the descriptor that reference the layers by id
    }
    
    function getSelectedLayersIds(){// this function get's the selected layers id's
      var idxs = getSelectedLayersIdx();// first it get's the indexes because in CS4 to CS6 there is no way to get the id's of the selected layers, only the indexes
      var selectedLayersIds = [];//create an empty Array that willbe the returned array
      for( var i=0;i		   
  • Script to add the layer mask to all layers but the background?

    I have been a professional editor/Retoucher for photographers for the past three years. I use a lot of stock, but I've never branched in scripts so far. I am trying to refine my workflow and scripts to not appear to be the next logical step.

    I do a lot of work in the interiors, which is essentially manual HDR. Here's my current generation process, which I would love to find a way to script. I tried to be very clear, but let me know if it needs to expand. I use Photoshop CS5.

    1. pull brackets, color corrected TIFF in Bridge.

    2 re-order as needed, with the main exhibition downstairs. Click on 'Tools' > 'Photoshop' > 'Charge in the form of layers Photoshop"to get a PSD with layers in the correct order and main as exposure layer from bottom (base).

    3. manually go through each layer and add a layer mask hide all each layer except the background layer.

    4. Save as a PSD, using the original name of the background layer as the file name. To do this, I just copy the name of the layer (example.tiff), paste in the Save dialog box and then use the drop-down menu to select PSD (save as example.psd).

    I hope to automate steps 3 and 4 as they are the majority of your time for me. Any contribution is appreciated!

    Thanks again.

    Yes, your change is good.  This way the last layer will not have a mask applied.  I wasn't sure if you wanted that, but in the control for the background layer.

    Regarding the economy, what file format would you save on?  Here's how to save a psd:

    docRef var = activeDocument

    var doneFolder = new Folder('/c/photos/')

    var NomCouche = docRef.activeLayer.name

    var psdOptions = new PhotoshopSaveOptions();

    psdOptions.layers = true;

    app.displayDialogs = DialogModes.ALL;//include this line if you want that the coming dialog box.

    docRef.saveAs (new file (doneFolder + "/" + NomCouche + ".psd"), psdOptions);

    app.displayDialogs = DialogModes.NO;//Resets at ALL - you won't let it work on.

  • by selecting all the blocks of text on all visible layers

    I want to select all the blocks of text on all visible layers.

    the script below will select all the blocks of text, even in groups, but if the layer with the text is invisible the script error. (target layer cannot be changed)

    If (app.documents.length > 0) {}

    var doc = app.activeDocument;

    var numTextFrames = 0;

    for (i = 0; i < doc.textFrames.length; i ++) {}

    textArtRange = doc.textFrames [i];

    textArtRange.selected = true;

    }

    }

    So I made this script to select blocks of text on only visible layers, but now missing text belonging to a group.

    var layerCount = activeDocument.layers.length;

    var docSelected = activeDocument.selection;

    for (i = 0; i < layerCount; i ++)

    {

    currentLayer = activeDocument.layers [i];

    If (currentLayer.visible == visible)

    {

    for (j = 0; j < currentLayer.textFrames.length; j ++) {}

    textArtRange = currentLayer.textFrames [j];

    textArtRange.selected = true;

    }

    }

    }

    can someone tell me why it is not some frames of text bound in a group when made this way and is it possible to get all managers of related texts selected on all visible layers?

    Thank you

    Duane

    Try this:

    if (app.documents.length > 0 ) {
        var doc = app.activeDocument;
        var numTextFrames = 0;
        for (  i = 0; i < doc.textFrames.length; i++ ) {
            try {
            textArtRange = doc.textFrames[i];
            textArtRange.selected = true;
            } catch (e) {}
            }
        }
    

    Have fun

  • Method to select all the layers 'invisible '?

    Hello

    Does anyone know if there is a plugin or a way to select all the invisible layers in a photoshop file automatically with a single click?
    It would be really handy when it comes to huge photoshop with lots of files files and layers...

    Screen shot 2012-11-12 at 15.22.36.png

    Kind regards

    Ben

    Not sure on the hiden targeting all the layers in a single click, but you can filter so that no visible layers only show, then it is easy to target all.  (On the tab of the layer panel, choose attribute, then no Visible)

    Might be possible to write a script or an action recording to do the same thing?

  • How to deal with a document with no selected layers

    Hi all

    I'm writing a script that needs to check the consistency of each layer and rename each layer as a result.

    Apparently, I managed to do it, but it happens that if no layer is selected the script will not work.

    So I came up with this solution (it's just a part of the script):

    #target photoshop

    If {(app.documents.length)

    var strtRulerUnits = app.preferences.rulerUnits;

    var strtTypeUnits = app.preferences.typeUnits;

    app.preferences.rulerUnits = Units.PIXELS;

    app.preferences.typeUnits = TypeUnits.PIXELS;

    var app.activeDocument = docRef;

    DOUBTFUL OF LAYER SELECT SUPERIOR WAY

    var ghostLyr = docRef.artLayers.add)

    ghostLyr.move (docRef, ElementPlacement.PLACEATBEGINNING)

    docRef.activeLayer.remove)

    DOUBTFUL WAY TO SELECT BACKGROUND

    var ghostLyr = docRef.artLayers.add)

    ghostLyr.move (docRef, ElementPlacement.PLACEATEND)

    docRef.activeLayer.remove)

    }

    So basically, I create an empty layer, place it on the top or the bottom and delete it immediately, so the underlying layer selects automatically.

    A better idea?

    He looks to a workaround for me, it works, but it is... doubtful.

    Thanks for all the help!

    MD

    You want to process all the layers then why not just target the background layer and work your way the layers.  If the document contains layer groups, you will have to work through the layer in them as well.

    var layers = activeDocument.layers;
    activeDocument.activeLayer = layers [layers.length - 1] / / bottom layer of target
  • I can't add/subnet mask 31 255.255.255.254 ISP WAN &gt; static IP setting in VPN Firewall SRX5308

    Hello

    I can't add/subnet mask 31 255.255.255.254 ISP WAN > static IP setting in VPN Firewall SRX5308. When I try to apply it, I get the popup error message like "invalid IP subnet mask. Please enter 0/128/192/224/240/248/252 for octet 4 ". I try to add provider NTU fiber optic internet service in one of the 4 WAN settings. The vendor gave me a 31 block IP and the subnet as 255.255.255.254 mask. It is a limitation in this firewall? I have to ask the provider to give me a 30 block the IP instead? With 30 block IP subnet mask will be 255.255.255.252 who is authorized by this firewall setting. I tried this on another (SnapGear SG560) firewall and it works without any problem. See the screenshots below. Can someone please?

    concerning

    Ridwan

    / 31 would be used in specific scenarios where you * really * need to keep the address space and on links only point to point. To be honest I've never met anyone, or any ISP that uses it. It works on point to point, because, well, there no need to broadcast address because there are only two devices on the link (one on each side of the cable)... IP address ranges would be;. 0-. 1,.2-. 3, etc.

    Most (if not all) Netgear devices will prevent you from setting 31, but you will probably be able to use without problem in all 30 cases, according to the setup of the ISP I do not think that it would cause you problems really. But if you can, I would certainly ask a 30 instead.

  • How can I customize the folder icon and add the template to all subfolders

    IM using Windows 7

    In the My Pictures folder, I have many many separate subfolders. I have no problem customizing folders one by one, but check the box "Also add this template to all subfolders" does not work. It does, however, if I check this box to display the same image IN the folder.

    This isn't a matter of life and death but Ive got about 200 subfolders (with graphics) and modify them individually will be soul destroying and dead all simply too short.

    Ive tried select all and change properties, but modifies only the 1 folder which has been a right click

    Ive looked for questions but the problem has not been raised. Any help would be appreciated.

    Of course, here's how with a quick video demo: easily apply Windows folder to all subfolders display

  • Add value in a statement select union

    Hi have following sql,

    Select empname, 't' State, empno from tablename where column01 > 0

    Union of all the

    Select empname, 't' State, empno from tablename where column02 > 0

    Union of all the

    Select empname, condition of "W", empno FROM tablename WHERE COLUMN03 > 0

    Union of all the

    Select empname, condition of "Z", empno FROM tablename WHERE COLUMN04 > 0


    My use case is

    I have what it takes to add an additional column that is based on the slot status

    IN the column State

    If column01 > 0 to condtion 't' then quattiy 0

    If > 1 column02 of condition 'Y' then quatity is 1

    Condition IF COLUMN03 > 0 THAN 'w '.

    If COLUMN04 > 0 that the condition of "Z".

    If more than column 2 is < 0 to point out and it will be a quantity

    Select 't'

    TableName

    where column01 > 0

    Union of all the

    Select "y".

    TableName

    where column02 > 0

    Union of all the

    Select 'W '.

    TABLENAME

    WHERE COLUMN03 > 0

    I have what it takes to show value as it

    EmpName, condition, empno quatity

    Jerry, T, 1, 0158754585

    TOM, Y, 2, 0054789568

    Am in oracle database 11 g 2

    select empname, 'T' condition, empno,column01 + column02 + column03 + column04 quantity from tablename where column01 > 0
    
    union all
    
    select empname, 'T' condition, empno,column01 + column02 + column03 + column04 quantity from tablename where column02 > 0
    
    union all
    
    select empname, 'W' condition, empno,column01 + column02 + column03 + column04 quantity FROM tablename WHERE  COLUMN03 > 0
    
    union all
    
    select empname, 'Z' condition, empno,column01 + column02 + column03 + column04 quantity FROM tablename WHERE  COLUMN04 > 0
    
  • Is it possible to copy all the layers in the layers panel and paste them in a new document?

    The content of each layer will be different on each document so I don't want to copy. I have 12 documents to be used in a calendar and I want all the layers as well as their names and colors to be the same in each document. I already have all the pages designed and built, but personal information is to be added, and I want each of them to match all the others.

    Basically, all I want to do is to copy the contents of the layers panel and past in each of the other documents.

    I just create a page at the end of the document w / layers and on this page, add an item by layer. Also, if you have 15 layers, drag the small fifteen frames on the page and the layer icon to assign each image to another layer.

    Then in the Pages panel menu, choose move Pages. Choose this 'page of layers' to move to your receiving document (another of your calendar documents), Destination: end of the Document.

    The receiving document will get all the layers. Remove all items (15 views) on the extra page and the layers remain.

    Next time you make a schedule, you should check the add-on for InDesign Calendar Wizard. You will cry all the time you wasted it making manually ;-(

    Home Calendar Wizard

    Anne-Marie

    InDesignSecrets.com

  • How to select layers by ID

    My extension HTML Panel listening to JSONEvents, as this SELECTION:

    { "eventID": 1936483188, "eventData": {"layerID":[2,97],"makeVisible":false,"null":{"_name":"back1.jpg","_ref":"layer"},"selectionModifier":{"_enum":"selectionModifierType","_value":"addToSelectionContinuous"}}}
    

    In the event handler, the script is to store the selected layer s 'layerID"in a table.

    How can I select these layers later by the ID stored with a .jsx call?

    Should be simple, but I can't find a way.

    Is it possible to convert the ID of the Index layer?

    Thank you very much!

    selectLayerById(98); //select this layer only
    selectLayerById(80,true); //select this layer along with other selected layers
    
    function selectLayerById(id,add){
    var ref = new ActionReference();
    ref.putIdentifier(charIDToTypeID('Lyr '), id);
    var desc = new ActionDescriptor();
    desc.putReference(charIDToTypeID("null"), ref );
    if(add) desc.putEnumerated( stringIDToTypeID( "selectionModifier" ), stringIDToTypeID( "selectionModifierType" ), stringIDToTypeID( "addToSelection" ) );
    desc.putBoolean( charIDToTypeID( "MkVs" ), false );
    try{
    executeAction(charIDToTypeID("slct"), desc, DialogModes.NO );
    }catch(e){}
    };
    
  • Get all the layers and apply to other documents

    Hello everyone,

    I'm copying all layers from one document to the other. But just copy paste is not enough for several reasons (root document may already be closed, copy at a time when the new document is not open yet,...).

    This means that I have to remember all the layers and use them later.

    At the moment I am sth. Like this:

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

    public static std::vector < PIActionDescriptor > layeractions;

    Sub testGet()

    {

    Result PIActionDescriptor = NULL;

    numLayers Int32;

    SPErr error = kSPNoError;

    DescriptorTypeID typeID = 0;

    Int32 docCounter = 1;

    error = PIUGetInfoByIndex (docCounter,

    classDocument,

    keyNumberOfLayers,

    & numLayers,

    (NULL);

    If (numLayers > 0)

    for (int32 layCounter = 1;

    layCounter < = numLayers & & error == kSPNoError;

    layCounter ++)

    {

    error = PIUGetInfoByIndexIndex (layCounter,

    docCounter,

    classLayer,

    classDocument,

    0,

    and result,

    (NULL);

    layeractions.push_back (result);

    }

    }

    Sub testSet()

    {

    SPErr error = kSPNoError;

    Result PIActionDescriptor = NULL;

    for (auto & it: layeractions)

    {

    error = sPSActionControl-> Play (& result, eventMake, he, NULL);

    }

    }

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

    So what I'm doing, open a doc with some layers. Then testGet(), open new document then testSet().

    But bench always puts "the command 'Make' is not currently available." and error = - 128.

    Hope you get what I'm trying.

    Thanks for any thoughts!

    Who's going to be a difficult path to travel to this topic. Even if you can get all the properties of the active document and the layers within the document, you have not dealt with pixels on a normal layer data. You will need to save this broad as well. And for dynamic objects and linked smart objects... you have a job to do. Any topic of a document is not capable 'get '.

    Trying to cope with this: "document might already be narrow" would be almost impossible IMO.

    Remember, the source document, which is now closed I now want to copy. Then you can do:

    1. open closed source document. (Or make it more if it is already open)

    2. for each layer in the source document

    a. Select the layer

    b. copy of the document target

    3. close source document.

    The Get accessor routines are not for 'read' directly. You must get the interesting bits of information on and then use the game code that you found using listener.

  • Cannot select layers

    I can turn layers market, but I can't select one of them to make adjustments. Any suggestions?

    Thank you, Brett. All select/deselect the button of automatic selection by your suggestion, I noticed that the display controls to turn it was unchecked. I checked it, and I'm in good shape now. Thank you for taking the time to help.

  • How to get through all the layers?

    I would like to write a script to rename all the layers, but I don't know how to do, who can help me?

    function traverse( layerSet, callback )
    {
      for ( var i = 0; i < layerSet.layers.length; i++ ) {
           var l = layerSet.layers[ i ];
           app.activeDocument.activeLayer = l;
           if ( l.typename == "LayerSet" )
           {
                traverse( l, callback );
           }
           callback( l );
      }
    }
    
    function toUpp( l )
    {
        l.name = l.name.toUpperCase();
    }
    
    traverse( app.activeDocument, toUpp );
    

    In this case, the callback is defining the name of the layer in upper case. The app.activeDocument is a layerSet too. For some reason you need to select a layer before running this script.

  • A script to do all my layers into individual groups of live paint?

    Hello!

    I am an architecture student and I often bring into my AutoCAD drawings into Illustrator to color / adjust the lines. A file from CAD can often have 30 + layers (one for the exterior walls, one for the interior walls, one for windows, one for the furniture and so on). When I apply the paint directly to a layer, I have to select and click alt + ctrl + X which is not only a lot of work but when you do it 20 times at the beginning of each drawing, it becomes a bit of a hazzle.

    I was wondering if anyone know or can create a script that can transform all my layers (or at least the links selected) in individual groups of live paint? I know that I can select all via target select and click Live paint, but that creates a live paint group with all my layers. I want that all my 30 processed layers in 30 different live paint groups while running a script.

    Anyone know?

    If you use CC, you can be lucky with this one:

    #target illustrator
    function test(){
        function hideOtherLayersInCollection(layers, layer){
            for(var i=0; i 0){
            var doc = app.activeDocument;
            var eligibleLayers = [];
            for(var i=0; i		   

Maybe you are looking for