从PSD Javascript中列出JSON目录和图层

时间:2018-09-08 09:14:19

标签: javascript json photoshop

嗨,我想在json中显示我的所有目录和图层。 这是一个示例:

https://cloud.githubusercontent.com/assets/24947757/21703462/2ee2ce70-d367-11e6-8950-5e978bcc7497.JPG

然后我要像这样的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

0 个答案:

没有答案