gpt4 book ai didi

javascript - 如何在 Photoshop 中展平阵列?

转载 作者:搜寻专家 更新时间:2023-11-01 04:34:47 27 4
gpt4 key购买 nike

这是我的代码:

var doc = app.activeDocument;
var allLayers = new Array;
var allLayers = collectAllLayers(doc, allLayers);

function collectAllLayers (doc, allLayers){
for (var m = 0; m < doc.layers.length; m++){
var theLayer = doc.layers[m];
if (theLayer.typename === "ArtLayer"){
allLayers.push(theLayer);
}else{
collectAllLayers(theLayer, allLayers);
}
}
return allLayers;
}
alert("array_layers : " + allLayers);

我正在进入这样的警报数组

[Layer1],[Layer2],[Layer3];

我想让它看起来像这样:

[Layer1,Layer2,Layer3];

提前感谢您的回答和帮助!

最佳答案

有问题的代码已经可以正常工作。引用关于 ArtLayer 的文档,您可以通过打印数组中每个对象的一些属性来证明这一点:

function collectAllLayers (layerSet, layers){
for (var i = 0; i < layerSet.layers.length; i++){
var layer = layerSet.layers[i];

if (layer.typename === "ArtLayer"){
layers.push(layer);
} else {
collectAllLayers(layer, layers);
}
}

return layers;
}

function printable (artLayers) {
var layerDescriptions = [];

for (var i = 0; i < artLayers.length; i++) {
var layer = artLayers[i];

layerDescriptions.push(
'{ name: ' + layer.name +
', kind: ' + layer.kind +
', opacity: ' + layer.opacity +
', visible: ' + layer.visible +
' }'
);
}

return layerDescriptions;
}

var artLayers = collectAllLayers(app.activeDocument, []);
var layerDescriptions = printable(artLayers);

alert(layerDescriptions);

关于javascript - 如何在 Photoshop 中展平阵列?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52081707/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com