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

Unlocking Background Layer with lots of other layers

Community Beginner ,
Sep 27, 2010 Sep 27, 2010

I've been looking at the similar questions, but no script has worked perfectly yet. I have a series of phoshop actions that I run on a regular basis. I have two version of each, one for if there's a locked background layer, and one for when its already been unlocked. Otherwise my actions error.

I'd like to simplify the process and have a script run that finds any locked layers (ie: background) and unlocks it, even if there are 15 other layers and even if I have another layer selected. It should also run without errors if there are no locked (background) layers to be found.

I don't know the first thing about writing my own scripts, so can somebody tell me what lines of code I'd need? Thank you Thank you!

TOPICS
Actions and scripting
10.1K
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
Adobe
Community Expert ,
Sep 27, 2010 Sep 27, 2010

ishook187 wrote:

I've been looking at the similar questions, but no script has worked perfectly yet. I have a series of phoshop actions that I run on a regular basis. I have two version of each, one for if there's a locked background layer, and one for when its already been unlocked. Otherwise my actions error.

A Photoshop background layer can not be completely unlocked because a Photoshop background layer does not support transparency that will alway be locked at 100% opacity and fill and can not be changed, no layer can be moved below it and it can not be moved up in the layer stack..  You can convert a background layer to a normal layer which will unlock the layer but it is no longer a background layer.  It is very easy in a script to target the bottom layer and make it a  normal layer just by setting the bottom layer not to be a background.

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
Community Beginner ,
Sep 27, 2010 Sep 27, 2010

I understand the limitations of the Background layer, and don't have a need to keep any properties of the Background layer. The limitations of the background layer have led me to the forums to find a script that can eliminate the limitations. In the end, I'd like to end up with an unlocked Layer 0, without first having to select the Background layer. It should also not error if there isn't a background layer to begin with (like a previously worked on photoshop file)

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 ,
Sep 27, 2010 Sep 27, 2010

Just a couple quick questions:

1. Did you want ALL locked layers in the stack to be unlocked or just the bottom layer on the stack?

2. When you start your action, which layer is active? Or is it random?

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 Beginner ,
Sep 27, 2010 Sep 27, 2010

1) I want all Locked layers (99% of the time this is just the background layer) to be unlocked

2) Random

(thank you for looking into 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
Guru ,
Sep 27, 2010 Sep 27, 2010

The script below will check all the layers in a document and make sure that there is no layer locking of any kind. Will work with layers in layersets and unlock layersets.

var topLayer = app.activeDocument.layers[0];
app.activeDocument.activeLayer = topLayer;
do{
    unlockLayer();
    selectLayerBelow();
}while(topLayer != app.activeDocument.activeLayer)
function unlockLayer(){
    if(app.activeDocument.activeLayer.isBackgroundLayer ) app.activeDocument.activeLayer.name = 'From Background';
    if(app.activeDocument.activeLayer.allLocked) app.activeDocument.activeLayer.allLocked = false;
    if(app.activeDocument.activeLayer.pixelsLocked) app.activeDocument.activeLayer.pixelsLocked = false;
    if(app.activeDocument.activeLayer.positionLocked) app.activeDocument.activeLayer.positionLocked = false;
    if(app.activeDocument.activeLayer.transparentPixelsLocked) app.activeDocument.activeLayer.transparentPixelsLocked = false;
};
function selectLayerBelow(){
    var desc = new ActionDescriptor();
        var ref = new ActionReference();
        ref.putEnumerated( charIDToTypeID( "Lyr " ), charIDToTypeID( "Ordn" ), charIDToTypeID( "Bckw" ) );
    desc.putReference( charIDToTypeID( "null" ), ref );
    desc.putBoolean( charIDToTypeID( "MkVs" ), false );
    executeAction( charIDToTypeID( "slct" ), desc, DialogModes.NO );
};

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
Guest
Mar 06, 2018 Mar 06, 2018
LATEST

thank you

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 ,
Sep 27, 2010 Sep 27, 2010

docLay=app.activeDocument.layers;
l=app.activeDocument.layers.length;

while (l>0) {
    l--;
    docLay.isBackgroundLayer = false;
    docLay.allLocked = false;
}

Quick and simple. It should do what you want, though.

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
Guru ,
Sep 27, 2010 Sep 27, 2010

jugenjury wrote:

docLay.allLocked = false;

That will only unlock the layer if alllocked is set to true. It will not lock if one of the other layer locking types are used.

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 Beginner ,
Sep 27, 2010 Sep 27, 2010

Both of your scripts work perfectly. I'm trying to find a flaw. The one thing I liked about the longer script from you Michael is that I get to name the (un)locked layer whatever I'd like in the script.

Thanks guys!

ian shook | lead artist | farm | cp |312.243.0044 x 104

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
New Here ,
Nov 04, 2013 Nov 04, 2013

Hi Mike,

Great and useful script, but is it possible to also unlock "invisible" layers or folders too?

I need to enable "Delete Hidden Layers" and need all visible and invisible layers unlocked.

Thx.

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
Guru ,
Nov 04, 2013 Nov 04, 2013

When a script makes an invisible layer active it also makes it visible. That script starts at the top of the layer stack and works it's way down until it cycles off the bottom and reaches the top again. Because of the way it handles the layers there is no way to check the visibility of a layer before it is made active. So this will not work for what you need.

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
New Here ,
Nov 04, 2013 Nov 04, 2013

what about making the invisible layer visible/active, then check if it's locked, then unlock and turn off visiblity again?

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
Guru ,
Nov 04, 2013 Nov 04, 2013

function makeActiveByIndex( index, visible ){

    var desc = new ActionDescriptor();

    var ref = new ActionReference();

    ref.putIndex(charIDToTypeID( 'Lyr ' ), index )

    desc.putReference( charIDToTypeID( 'null' ), ref );

    desc.putBoolean( charIDToTypeID( 'MkVs' ), visible );

    executeAction( charIDToTypeID( 'slct' ), desc, DialogModes.NO );   

};

function getNumberOfLayers(){

    var ref = new ActionReference();

    ref.putProperty( charIDToTypeID( 'Prpr' ), charIDToTypeID( 'NmbL' ) );

    ref.putEnumerated( charIDToTypeID('Dcmn'), charIDToTypeID( 'Ordn' ), charIDToTypeID( 'Trgt' ) );

    return executeActionGet( ref ).getInteger( charIDToTypeID( 'NmbL' )) ;

};

function getProperty( psClass, psKey, index ){// integer:Class, integer:key

    var ref = new ActionReference();

    if( psKey != undefined ) ref.putProperty( charIDToTypeID( "Prpr" ), psKey );

    if(index != undefined ){

        ref.putIndex( psClass, index );

    }else{

        ref.putEnumerated( psClass , charIDToTypeID( "Ordn" ), charIDToTypeID( "Trgt" ) );

    }

    try{

        var desc = executeActionGet(ref);

    }catch(e){ return; }// return on error

    if(desc.count == 0) return;// return undefined if property doesn't exists

    var dataType = desc.getType(psKey);

    switch(dataType){// not all types supported - returns undefined if not supported

        case DescValueType.INTEGERTYPE:

            return desc.getInteger(psKey);

            break;

        case DescValueType.ALIASTYPE:

            return desc.getPath(psKey);

            break;

        case DescValueType.BOOLEANTYPE:

            return desc.getBoolean(psKey);

            break;

        case DescValueType.BOOLEANTYPE:

            return desc.getBoolean(psKey);

            break;

        case DescValueType.UNITDOUBLE:

            return desc.getUnitDoubleValue(psKey);

            break;

        case DescValueType.STRINGTYPE:

            return desc.getString(psKey);

            break;

        case  DescValueType.OBJECTTYPE:

            return desc.getObjectValue(psKey);

            break;

        case  DescValueType.LISTTYPE:

            return desc.getList(psKey);

            break;

        case  DescValueType.ENUMERATEDTYPE:

            return desc.getEnumerationValue(psKey);

            break;

    }

};

var doc = app.activeDocument;

var layerCount = getNumberOfLayers();

var invisibleLayers = [];

var loopStart = Number(!doc.layers[doc.layers.length-1].isBackgroundLayer);

for(var layerIndex = loopStart;layerIndex<=layerCount;layerIndex++){

    if(!getProperty( charIDToTypeID('Lyr '), stringIDToTypeID( 'visible' ), layerIndex )) invisibleLayers.push(layerIndex);

}

for(var hiddenIndex=0;hiddenIndex<invisibleLayers.length;hiddenIndex++){

    makeActiveByIndex( invisibleLayers[hiddenIndex], true);

    if(doc.activeLayer.allLocked) doc.activeLayer.allLocked = false;

    if(doc.activeLayer.pixelsLocked) doc.activeLayer.pixelsLocked = false;

    if(doc.activeLayer.positionLocked) doc.activeLayer.positionLocked = false;

    if(doc.activeLayer.transparentPixelsLocked) doc.activeLayer.transparentPixelsLocked = false;

    doc.activeLayer.visible =  false;

}

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
New Here ,
Nov 05, 2013 Nov 05, 2013

Thanks mike for taking the time for this, really appreciate. I tried it but getting an error on text layers.....see my attached screenshot.

2013-11-05 10.01.27 am.png

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
Guru ,
Nov 05, 2013 Nov 05, 2013

Replace these lines

if(doc.activeLayer.kind != LayerKind.TEXT && doc.activeLayer.pixelsLocked) doc.activeLayer.pixelsLocked = false;

if(doc.activeLayer.kind != LayerKind.TEXT && doc.activeLayer.transparentPixelsLocked) doc.activeLayer.transparentPixelsLocked = false;

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
New Here ,
Nov 05, 2013 Nov 05, 2013

great, it fixed this bug but it seems there's specific use cases that doesn't work on:

- Does not unlock folders

- Does not unlock layers inside a folder

- For locked invisible layers, it seems to leave this layer visible after unlocking when it should be returned to it's original invisible state.

Thx.

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
Guru ,
Nov 05, 2013 Nov 05, 2013

Seems this needs more time than I have. I can't reproduce most of those issuses. For me it does unlock folders( if they are insisible ). It does work with nested layer and layerSets. And I can't get it to leave a layer visible that was not visible at the start.

The one thing I did notice was if a layer is in a hidden layerSet it is not visible regardless of it's visible property. Because the script checks that property it fails to unlock.

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
New Here ,
Nov 05, 2013 Nov 05, 2013

hi mike, thanks for your time. im on CS6, are you on CC? still not working but thanks alot anyways and always appreciate your time and effort on this.

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
Guest
Mar 06, 2018 Mar 06, 2018

How do I copy this script? text edit and save as a .jsx?

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