Copy link to clipboard
Copied
Hi all.
I'm trying to get a blue stripe to highlight a layer.
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?
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;
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
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
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;
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");
Copy link to clipboard
Copied
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();
}