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

Mysterious behavior, layer becomes visible, why?

Participant ,
Dec 17, 2023 Dec 17, 2023

I encountered strange behavior of a complex function where the originally active layer becomes visible for no reason. After allot of testing, I isolated the issue, and I still have no clue why it is happening.

The following script demonstrates the issue.

When you have a document with 10 layers, you make layer 8 invisible, and select layer 8 when running this script, this script simply saves the initially active layer 8 to a variable first, than selects layer 4 using action manager code (select layer by ID), and then restores the originally active layer 8. And for some reason, making the original layer 8 active again, it also making it visible. And this only happens in this combination, selecting by id using action manager code and than selecting it using the API.

Anyone any ideas on whats happening here?

 

 

function actionManagerSelectLayerById(layer, makeVisible){

    var d1 = new ActionDescriptor();
    var r1 = new ActionReference();
    
    r1.putIdentifier(app.charIDToTypeID('Lyr '), layer.id);
    d1.putReference(app.charIDToTypeID('null'), r1);
    d1.putBoolean(app.charIDToTypeID('MkVs'), makeVisible);

    executeAction(app.charIDToTypeID('slct'), d1, DialogModes.NO);
}


var initialLayer = app.activeDocument.activeLayer
actionManagerSelectLayerById(app.activeDocument.layers[3], false)
app.activeDocument.activeLayer = initialLayer;

 

 

Update...

I noticed just now it's because making a layer active using the API is simply making it visible. I guess this is default behaviour that I didn't realise. This post can be deleted

TOPICS
Actions and scripting
156
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

correct answers 1 Correct answer

Community Expert , Dec 17, 2023 Dec 17, 2023

Just in case this helps somebody else (I know it helped me)...

 

It's a hack as that is how DOM code works... To select a target layer while retaining its current visibility:

 

if (activeDocument.layers[3].visible === false) {
    activeDocument.activeLayer = activeDocument.layers[3];
    activeDocument.activeLayer.visible = false;
} else {
    activeDocument.activeLayer = activeDocument.layers[3];
}

 

Or to toggle the current visibility off/on or on/off:

 

app.activeDocument.activeLayer = app.a
...
Translate
Adobe
Community Expert ,
Dec 17, 2023 Dec 17, 2023

You seem to be mistaken. (edit: with regard to this only happening with Layer 8)

Any invisible Layer appears to be made visible by selecting it via DOM-code. 

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 Expert ,
Dec 17, 2023 Dec 17, 2023
LATEST

Just in case this helps somebody else (I know it helped me)...

 

It's a hack as that is how DOM code works... To select a target layer while retaining its current visibility:

 

if (activeDocument.layers[3].visible === false) {
    activeDocument.activeLayer = activeDocument.layers[3];
    activeDocument.activeLayer.visible = false;
} else {
    activeDocument.activeLayer = activeDocument.layers[3];
}

 

Or to toggle the current visibility off/on or on/off:

 

app.activeDocument.activeLayer = app.activeDocument.layers[3];
var currentLayer = app.activeDocument.activeLayer;
currentLayer.visible = !currentLayer.visible;

 

Using the original code with modifications:

 

function actionManagerSelectLayerById(layer, makeVisible){

    var d1 = new ActionDescriptor();
    var r1 = new ActionReference();
    
    r1.putIdentifier(app.charIDToTypeID('Lyr '), layer.id);
    d1.putReference(app.charIDToTypeID('null'), r1);
    d1.putBoolean(app.charIDToTypeID('MkVs'), makeVisible);

    executeAction(app.charIDToTypeID('slct'), d1, DialogModes.NO);
}


var initialLayer = app.activeDocument.activeLayer;
actionManagerSelectLayerById(app.activeDocument.layers[3], false);
app.activeDocument.activeLayer = initialLayer;

initialLayer.visible = !initialLayer.visible;
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