嗨,我想在json中显示我的所有目录和图层。 这是一个示例:
然后我要像这样的JSON:
[{"Catalogs" : [
{ "name" : "LArm",
"layers" : [
{"name" : "LShoulrde"},
{"name" : "LForearm"},
{"name" : "LHand_D"}...
这是我的代码:
#include 'json.jsx'
var doc = app.activeDocument;
var allLayers = new Array;
var rv = new Object;
var allLayers = collectAllLayers(doc, allLayers);
var rv = toObject(allLayers, rv);
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.name);
}else{
collectAllLayers(theLayer, allLayers);
}
}
return allLayers;
}
function toObject(allLayers, rv) {
for (var i = 0; i < allLayers.length; ++i)
if (allLayers[i] !== undefined) rv[i] = allLayers[i];
return rv;
}
alert(JSON(rv,1));
目前,我不知道如何将目录名称添加到对象,然后像我的示例一样将其转换为JSON。感谢您的答复和事先的帮助。
我使用json.jsx
来自:
https://github.com/indiscripts/extendscript/blob/master/JSON/json.jsx