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

Selecting a document layer.

Engaged ,
May 03, 2024 May 03, 2024

Copy link to clipboard

Copied

 

Hi all.

I'm trying to get a blue stripe to highlight a layer.

Pic01.png

var aiDocument = app.documents[0];
carentLayer = app.documents[0].layers.getByName("WB");
carentLayer.selected = true;

 

But this code does not produce the desired result.
How to do it?

TOPICS
Scripting

Views

348

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 , May 03, 2024 May 03, 2024

Hi @AnyON - Not sure what excatly you are trying to achive but if you want to select items of WB layer with the layer selection in the Layers panel. Try following snippet.

var aiDocument = app.documents[0];
carentLayer = app.documents[0].layers.getByName("WB");
aiDocument.activeLayer = carentLayer;
carentLayer.hasSelectedArtwork = true;

 

Votes

Translate

Translate
Adobe
Community Expert ,
May 03, 2024 May 03, 2024

Copy link to clipboard

Copied

Hi @AnyON, I'm not sure you even can. The Layer object in the scripting API has no "selected" property or "select" method.

 

Can you explain why you want it selected? Maybe there is another approach. For example, in scripts you can target layers specifically, whether or not they are active or selected.

- Mark

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
Engaged ,
May 03, 2024 May 03, 2024

Copy link to clipboard

Copied

Hi m1b!!!

There is a document that has several layers. I want to prepare it for export to Photoshop.

 

var aiDocument = app.documents[0];

var carentLayer;
var useLayersName = [];

// getting the layers you need
for (var j = 0; j < aiDocument.layers.length; j++){ 
    
    carentLayer = aiDocument.layers[j];
    if (carentLayer.pathItems.length > 0) {

        useLayersName.push(carentLayer.name);
    }
}

var arrayLayersPathItemsNames = []; 

for (var j = 0; j < useLayersName.length; j++){ 
    
    arrayLayersPathItemsNames = [];
    carentLayer = aiDocument.layers.getByName(useLayersName[j]);
    carentLayer.hasSelectedArtwork = true; 

    for (var k = 0; k < carentLayer.pathItems.length; k++) { // checking for name existence
        
        if (carentLayer.pathItems[k].name == ""){

            carentLayer.pathItems[k].name = String(carentLayer.name + k);
            arrayLayersPathItemsNames.push(carentLayer.pathItems[k].name);

        } else if(carentLayer.pathItems[k].name != "") {
            
            arrayLayersPathItemsNames.push(carentLayer.pathItems[k].name);

        }

    }   
        
    carentLayer.hasSelectedArtwork = false; 
    carentLayer.selected = true;
    app.doScript("ReliseToLayers","Set 1"); //ReliseToLayers action
    carentLayer.selected = true;
    
    for (var f = carentLayer.layers.length - 1; f > - 1 ; f--) { 
        
        carentLayer.layers[f].name = arrayLayersPathItemsNames[f];
    } 
    
    
    for (var f = carentLayer.layers.length - 1 ; f > -1 ; f--) { 
        
        carentLayer.layers[f].move(carentLayer, ElementPlacement.PLACEBEFORE);
        
    } 

    // var t = 4; -- point for debug
        
    carentLayer.remove();
}

 

But as a result of this script, only one initial layer contains sublayers. It takes a long time to explain the errors that occur. Try it yourself,,, And as I understand it, when performing it there is confusion with the choice of the required layer for the production of sublayers

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 ,
May 03, 2024 May 03, 2024

Copy link to clipboard

Copied

Hi @AnyON - Not sure what excatly you are trying to achive but if you want to select items of WB layer with the layer selection in the Layers panel. Try following snippet.

var aiDocument = app.documents[0];
carentLayer = app.documents[0].layers.getByName("WB");
aiDocument.activeLayer = carentLayer;
carentLayer.hasSelectedArtwork = true;

 

Best regards

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 ,
May 03, 2024 May 03, 2024

Copy link to clipboard

Copied

Hi @AnyON 

I suspect the same as @Charu Rajput: you just want to hightlight the ‘WB’ layer = ‘make it blue’? Then use 'active layer' instead of 'selected'. The layer 'WB" must be present in the document.

app.activeDocument.activeLayer = app.documents[0].layers.getByName("WB");

 

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
Engaged ,
May 03, 2024 May 03, 2024

Copy link to clipboard

Copied

LATEST

Thank you guys, everything worked out

 

var aiDocument = app.documents[0];

var carentLayer;
var useLayersName = [];

// getting the layers you need
for (var j = 0; j < aiDocument.layers.length; j++) {

    carentLayer = aiDocument.layers[j];

    if (carentLayer.pathItems.length > 0) {

        useLayersName.push(carentLayer.name);
    }
}

var arrayLayersPathItemsNames = [];

for (var j = 0; j < useLayersName.length; j++) {

    arrayLayersPathItemsNames = [];

    carentLayer = aiDocument.layers.getByName(useLayersName[j]);
    aiDocument.activeLayer = carentLayer;
    carentLayer.hasSelectedArtwork = true;

    for (var k = 0; k < carentLayer.pathItems.length; k++) { // checking for name existence

        if (carentLayer.pathItems[k].name == "") {

            carentLayer.pathItems[k].name = String(carentLayer.name + k);
            arrayLayersPathItemsNames.push(carentLayer.pathItems[k].name);

        } else if (carentLayer.pathItems[k].name != "") {

            arrayLayersPathItemsNames.push(carentLayer.pathItems[k].name);

        }

    }

    app.doScript("ReliseToLayers", "Set 1"); //ReliseToLayers action

    for (var f = carentLayer.layers.length - 1; f > - 1; f--) {

        carentLayer.layers[f].name = arrayLayersPathItemsNames[f];
    }


    for (var f = carentLayer.layers.length - 1; f > -1; f--) {

        carentLayer.layers[f].move(carentLayer, ElementPlacement.PLACEBEFORE);

    }

    carentLayer.remove();
}

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