1
我知道圖層名稱只能作爲對象訪問。但有沒有辦法使用該對象名稱來查找數組中的索引位置?換句話說,我在文件中有多個圖層。我想找到一個特定的圖層,鎖定並更改其上方所有圖層的可見性,並解鎖並更改其下所有圖層的可見性。我會一直在尋找同一層,但總的圖層數會隨着工作而改變。任何幫助將非常感激!按名稱查找圖層索引#
我知道圖層名稱只能作爲對象訪問。但有沒有辦法使用該對象名稱來查找數組中的索引位置?換句話說,我在文件中有多個圖層。我想找到一個特定的圖層,鎖定並更改其上方所有圖層的可見性,並解鎖並更改其下所有圖層的可見性。我會一直在尋找同一層,但總的圖層數會隨着工作而改變。任何幫助將非常感激!按名稱查找圖層索引#
只需循環遍歷所有圖層,並檢查每個圖層是否與您的名稱相匹配。如果它確實保存了索引(當前循環數)。
// get index (from top layer down) of named layer... expects only one layer with this name
// name of layer you are looking for
var targetLayerName = 'name'
var targetDocument = app.activeDocument;
var layerCount = targetDocument.layers.length;
var namedLayerIndex = 0;
// loop through layers and find the named layer
for (i = 0; i < layerCount; i++) {
if (targetDocument.layers[i].name == targetLayerName) {
namedLayerIndex = i;
}
}