skip to Main Content

I am a Photoshop beginner and currently use version Photoshop CS3. I use keyboard shortcut all the time to speed up the design process such as creation of new layers etc.

However, one command I feel Photoshop must have is to create a new layer below the current working layer and therefore I cannot assign it via a shortcut.

I have to create a new layer above the current layer and then manually drag it below the current layer which I feel can be automated using action or scripting, both of which are difficult for me being a beginner.

Can anybody help me in this regard.

Thanks
dkj

3

Answers


  1. It can be scripted with the following:

    I’ve simplified my answer – you don’t need to find the index, you can use the active layer instead.

    create_new_layer("Gwen!");
    
    // function CREATE NEW LAYER (layername)
    // --------------------------------------------------------
    function create_new_layer(layername)
    {
      if (layername == undefined) layername = "Layer";
    
       // create new layer at top of layers
       var originalLayer = app.activeDocument.activeLayer;
       var layerRef = app.activeDocument.artLayers.add();
    
       // name it & set blend mode to normal
       layerRef.name = layername;
       layerRef.blendMode = BlendMode.NORMAL;
    
       // Move the layer below
       layerRef.moveAfter(originalLayer);
    
       // Move the layer above if you desire
       // layerRef.moveBefore(originalLayer);
    }
    

    You can then record this script as an action and put on a keyboard short cut.

    Login or Signup to reply.
  2. Few years ago i thought that native PS API working with DOM is cool and should work faster, but actually under the hood it’s callstack often even bigger than same commands performed via actions. + Also sometimes DOM functions consist of multiple underlying calls, like artLayers.add() for example which is actually make layer + move it to top of the document. So here’s action version of that functionality from my PS scripting library:

    // get current layer number
    function curLyrN(){
        if(app.activeDocument.artLayers.length<2) return 1;
        var idLyr = charIDToTypeID("Lyr ");
        var idItmI = charIDToTypeID("ItmI");
        var aref = new ActionReference(); 
        aref.putEnumerated(idLyr, charIDToTypeID("Ordn"), charIDToTypeID("Trgt")); 
        var id = executeActionGet(aref).getInteger(charIDToTypeID("LyrI"));
        aref = new ActionReference(); 
        aref.putProperty(charIDToTypeID("Prpr"), idItmI); 
        aref.putIdentifier(idLyr, id); 
        id = executeActionGet(aref).getInteger(idItmI);
        if(id) return id;
        return 0; 
    }
    
    // select [LayerNum], optionally [add] to selection (if add=2: with inclusion)
    function selLyr(LyrN,add){
        var adesc = new ActionDescriptor();
        var aref = new ActionReference();
        aref.putIndex(charIDToTypeID("Lyr "), LyrN);
        adesc.putReference(charIDToTypeID("null"), aref);
        if(add){
            add = (add==2) ? stringIDToTypeID("addToSelectionContinuous") : stringIDToTypeID("addToSelection");
            adesc.putEnumerated(stringIDToTypeID("selectionModifier"),stringIDToTypeID("selectionModifierType"),add);
        }
        adesc.putBoolean(charIDToTypeID("MkVs"), false);
        return executeAction(charIDToTypeID("slct"), adesc, DialogModes.NO);
    }
    
    // move current layer to [LayerNum]
    function movLyr(LyrN){
        var idLyr = charIDToTypeID("Lyr ");
        var adesc = new ActionDescriptor();
        var aref = new ActionReference();
        aref.putEnumerated(idLyr, charIDToTypeID("Ordn"), charIDToTypeID("Trgt"));
        adesc.putReference(charIDToTypeID("null"), aref);
        aref = new ActionReference();
        aref.putIndex(idLyr, LyrN);
        adesc.putReference(charIDToTypeID("T   "), aref);
        adesc.putBoolean(charIDToTypeID("Adjs"), false);
        return executeAction(charIDToTypeID("move"), adesc, DialogModes.NO);
    }
    
    // create new empty layer
    function mkLyr(){
        var aref = new ActionReference();
        aref.putClass(charIDToTypeID("Lyr "));
        var adesc = new ActionDescriptor();
        adesc.putReference(charIDToTypeID("null"), aref);
        return executeAction(charIDToTypeID("Mk  "), adesc, DialogModes.NO);
    }
    
    // count all inner layers from layer-set (group)
    function cntLyrS(lyrs,c){
        if(!c){
            if(lyrs.typename!='LayerSet') return 0;
            c = 0;
        }
        var ls = lyrs.layers.length;
        var i = 0;
        while(i<ls){
            c++;
            if(lyrs.layers[i].typename=='LayerSet') c=cntLyrS(lyrs.layers[i],c);
            i++;
        }
        return c+1;
    }
    
    // make new layer below current or [LayerNum], optionally [ignoreGroups]
    function mkLyrBelow(LyrN,noGr){
        var doc = app.activeDocument;
        if(!doc) return false;
        if(LyrN){
            selLyr(LyrN);
        }else{
            LyrN = curLyrN();
            if(!LyrN) return false;
        }
        var actv = doc.activeLayer;
        if(actv.isBackgroundLayer) actv.isBackgroundLayer=false;
        mkLyr();
        if(curLyrN()==LyrN) return true;
        if(!noGr){
            var lc = cntLyrS(actv);
            if(lc && lc<LyrN-1) LyrN -= lc;
        }
        return movLyr(LyrN-1);
    }
    

    And even tho it looks pretty cumbersome and scary – i doubt that it will perform much slower. And as a bonus it will create minimal amount of actions in the history (no unnecessary layer moves) + it will correctly work with background layer + it will work properly with the groups (layer-sets): if group is opened – it will create new layer inside of it, and if group is closed it will correctly move layer under the whole group-structure including other possible groups inside the selected one.

    Use it like that: mkLyrBelow(); to create new layer under selected one, or mkLyrBelow(LayerNumber); to create layer under another one via it’s number, also u can optionally add 2d parameter to ignore groups (it will move new layer inside the group even if it’s closed): mkLyrBelow(LayerNumber,true); or mkLyrBelow(0,1);

    P.S. don’t get me wrong about ActionRefs – they’re not the silver bullet, just oftenly have some more convenience in the end, but ofc best results obtained when u combine ARef’s with native API. Just believe me on that, i’ve coded my first PS script like 8 years ago, so i’ve tried pretty much everything =)

    Login or Signup to reply.
  3. If I understand your question correctly, Photoshop already has these shortcuts

    Ctrl+Shift+N (Creating New Layer)

    Ctrl+] (To move the layer up)

    Ctrl+[ (To move the layer down)

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search