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

turn off layer isolation via script

Participant ,
Mar 05, 2023 Mar 05, 2023

Copy link to clipboard

Copied

Guys is there a way to turn off layer filtering in photoshop via script? I used script listener to run menu item: select-isolate layers, if I run action again it cancels isolation - this is exactly what I need, but if I can the code from script listener again it doesn't cancels isolation, it only applies

Screenshot 2023-03-06 at 13.23.32.png

TOPICS
Actions and scripting

Views

2.1K

Translate

Translate

Report

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

Community Expert , Mar 05, 2023 Mar 05, 2023

@Evgenii Eth 

 

Some menu commands need to be inserted into an action step to be successfully recorded by ScriptListener. Here is the SL code cleaned and put into a function:

 

isolateLayers();

function isolateLayers() {
	function s2t(s) {
        return app.stringIDToTypeID(s);
    }
	var descriptor = new ActionDescriptor();
	var reference = new ActionReference();
	reference.putEnumerated( s2t( "layer" ), s2t( "ordinal" ), s2t( "targetEnum" ));
	descriptor.putReference( s2t( "null" ), referenc
...

Votes

Translate

Translate
Adobe
Community Expert ,
Mar 05, 2023 Mar 05, 2023

Copy link to clipboard

Copied

@Evgenii Eth 

 

Some menu commands need to be inserted into an action step to be successfully recorded by ScriptListener. Here is the SL code cleaned and put into a function:

 

isolateLayers();

function isolateLayers() {
	function s2t(s) {
        return app.stringIDToTypeID(s);
    }
	var descriptor = new ActionDescriptor();
	var reference = new ActionReference();
	reference.putEnumerated( s2t( "layer" ), s2t( "ordinal" ), s2t( "targetEnum" ));
	descriptor.putReference( s2t( "null" ), reference );
	executeAction( s2t( "isolateLayers" ), descriptor, DialogModes.NO );
}

 

Or you can just call the menu item as follows:

 

app.runMenuItem(stringIDToTypeID('isolateLayers'));

 

Hope this helps!

Votes

Translate

Translate

Report

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
Participant ,
Mar 05, 2023 Mar 05, 2023

Copy link to clipboard

Copied

Thank you, Stephen, for clearing this up for me! However my question was on how to undo the isolation or clear filtering layers. The code you provided works in one way - it only enables the isolation, but doesn't disables, however if I run action with the menu item it will do both enable/disable

Votes

Translate

Translate

Report

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 ,
Mar 06, 2023 Mar 06, 2023

Copy link to clipboard

Copied

You undo the isolation by running the call to the function a second time, it's a toggle. Run it once, and isolation is entered. Run it a second time and isolation is exited.

 

What happens "in-between" is something else.

 

Short of some esoteric Action Manager code being hand written by somebody such as @r-bin or @jazz-y , I don't believe that operations performed by the GUI while in isolation are scriptable.

 

The general rule is if it can be recorded into an action as a step, or registered in the SL output log, then it is captured. 

 

We can only do so much...

 

What are you wishing to script while in layer isolation mode? There may be other ways to achieve the same end.

Votes

Translate

Translate

Report

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
Participant ,
Mar 06, 2023 Mar 06, 2023

Copy link to clipboard

Copied

For some reason running the second time doesn't execute undo command on my machine

Yes I know that it is possbile to achive the same results, but isolation is much faster than for example preserving current hide/visible state of all layers and then restoring it afterwards 

Votes

Translate

Translate

Report

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 ,
Mar 06, 2023 Mar 06, 2023

Copy link to clipboard

Copied

The code toggles on/off for me in v2021 and v2022.

 

The code doesn't work in v2023... But the Action does! :]

 

I know it is fast, but we can only do what is possible in scripting when the GUI can't be recorded.

 

When things need to happen fast, using AM code is generally the way to go. For example, @jazz-y has posted some really sweet code in order to be able to "instantly" capture and restore selected layers and layer visibility (great for use with a loop that messes with the original layer selections or visibility).

 

This advanced scripting is beyond my abilities.

 

Votes

Translate

Translate

Report

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
Explorer ,
Aug 19, 2024 Aug 19, 2024

Copy link to clipboard

Copied

Is there a way the code toggles on/off for V 2024 25.11?

Votes

Translate

Translate

Report

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 ,
Aug 19, 2024 Aug 19, 2024

Copy link to clipboard

Copied

@GregCont 

 

Which toggles?

 

Layer isolation? Looks like this has been fixed.

 

Layer visibility?

 

?

 

I just tested the following in 2024 (25.11.0) and it works for selected layers to toggle isolation on (toggle back off doesn't require selected layers):

 

app.runMenuItem(stringIDToTypeID("isolateLayers"));

 

Or:

 

var idisolateLayers = stringIDToTypeID( "isolateLayers" );
    var desc259 = new ActionDescriptor();
    var idnull = stringIDToTypeID( "null" );
        var ref9 = new ActionReference();
        var idlayer = stringIDToTypeID( "layer" );
        var idordinal = stringIDToTypeID( "ordinal" );
        var idtargetEnum = stringIDToTypeID( "targetEnum" );
        ref9.putEnumerated( idlayer, idordinal, idtargetEnum );
    desc259.putReference( idnull, ref9 );
executeAction( idisolateLayers, desc259, DialogModes.NO );

 

Or as BatchPlay UXP:

 

async function actionCommands() {
    let command;
    let result;
    let psAction = require("photoshop").action;

    // Isolate Layers current layer
    command = {"_obj":"isolateLayers","_target":[{"_enum":"ordinal","_ref":"layer","_value":"targetEnum"}]};
    result = await psAction.batchPlay([command], {});
}

async function runModalFunction() {
    await require("photoshop").core.executeAsModal(actionCommands, {"commandName": "Action Commands"});
}

await runModalFunction();

 

 

Votes

Translate

Translate

Report

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
Explorer ,
Aug 19, 2024 Aug 19, 2024

Copy link to clipboard

Copied

 

Sorry I meant, Clearing the layer filter as you can see below,

 

GregCont_0-1724109447375.png

You see when it's off all layers are back

 

GregCont_1-1724109523507.png

 

 

 

Votes

Translate

Translate

Report

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 ,
Aug 19, 2024 Aug 19, 2024

Copy link to clipboard

Copied

Yes, the layer isolation toggle works in 2024 (25.11.0) as per my previous post code samples.

Votes

Translate

Translate

Report

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
Explorer ,
Aug 19, 2024 Aug 19, 2024

Copy link to clipboard

Copied

I have this error, I  use VSCODE for saving the .jsx file and when I run it this is what I got

 

GregCont_0-1724110092821.png

 

Votes

Translate

Translate

Report

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 ,
Aug 19, 2024 Aug 19, 2024

Copy link to clipboard

Copied

You can't use MS Visual Studio Code to run UXP/BatchPlay code. Also note that UXP/BatchPlay code can't be combined with ExtendScript code.

 

Use the two previous ExtendScript code samples that I provided.

Votes

Translate

Translate

Report

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
Explorer ,
Aug 19, 2024 Aug 19, 2024

Copy link to clipboard

Copied

 @Stephen_A_Marsh 

 

I ran them and nothing hapenned that why I asked about the compatibility with 2024. Do I have something going on my settings?

 

Votes

Translate

Translate

Report

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 ,
Aug 19, 2024 Aug 19, 2024

Copy link to clipboard

Copied

If layers are already isolated, there is nothing extra to do, the code should toggle the isolation off.

 

If isolation is already off, you need to select the applicable matching layers before using the isolate toggle.

 

As I mentioned, it works for me on an Intel Mac using 2024 (25.11.0).

Votes

Translate

Translate

Report

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
Explorer ,
Aug 19, 2024 Aug 19, 2024

Copy link to clipboard

Copied

LATEST

I'm using a custom AMD PC build and I tested it on my Mac M1. layes just desapear and leave the panel as below: 

GregCont_0-1724111435341.png

No worries I was looking for a way I have back the standard view (All Layers) with the filter OFF without click the switch buttom.

 

 

Votes

Translate

Translate

Report

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