1 Reply Latest reply on Oct 22, 2016 10:44 AM by urban.space.man

    Accessing Layer Comp visibility and position without applying it

    urban.space.man Level 1

      I'm trying to find out if I can read what a Layer Comp has recorded, like visibility and position, without applying the Layer Comp.  I'm exploring this because when running my script on PSD files with hundreds of layers and 50 Layer Comps it's very slow to have to apply every layer comp.

       

      I've been looking at some of the discussions on GitHub concerning Photoshop Generator, and when that plugin exports document information it creates something like this:

       

      "comps": [{
            "name": "Comp 1",  
            "visibility": true,
            "position": true, 
            "appearance": true, 
            "hasWarning": false, 
            "id": 48804065, 
            "layerSettings": [
               {"layerID": 1, "enabled": true }, 
               {"layerID": 12, "enabled": true, "blendOptions": {"mode": "passThrough"} },
               {"layerID": 16, "enabled": true, "blendOptions": {"mode": "passThrough"} },
               {"layerID": 20, "enabled": true, "offset": {"horizontal": -181, "vertical": -1} },
               {"layerID": 22, "enabled": true, "FXRefPoint": {"horizontal": 47.280848, "vertical": 1.925534} }, 
               {"layerID": 27, "enabled": false }
            ]
         }]
      

       

      So there is layer information inside the layer comps, but I don't know how to reference it in ExtendScript.

       

      I've written my own script to dump the contents of the layer comps and I get this:

       

      <ActionList> [
          0 <Object> : compsClass {
               title <String> : "Comp 1"
               itemIndex <Integer> : 1
               ID <Integer> : 48804065
               selection <Boolean> : false
               useVisibility <Boolean> : true
               usePosition <Boolean> : true
               useAppearance <Boolean> : true
          }
      ]
      

       

      No layer information at all. How does Generator extract that?  Anyone have any ideas?

        • 1. Re: Accessing Layer Comp visibility and position without applying it
          urban.space.man Level 1

          Thanks to Thomas Ruark and Tim Wright at Adobe (two Generator developers) for pointing me in the right direction for this.  You can get Photoshop to tell you all the Layer Comp settings as a JSON string by using the json property.  I've written this function:

           

          /*---------------------------------------------------*/
          function getJSONStringForComps ()
          /*---------------------------------------------------*/
          {
            var docRef = new ActionReference();
            var desc = new ActionDescriptor();
            var JSON = stringIDToTypeID("json");
            docRef.putProperty(charIDToTypeID('Prpr'), JSON);
            docRef.putEnumerated(stringIDToTypeID("document"), charIDToTypeID('Ordn'), charIDToTypeID('Trgt'));
            desc.putReference(charIDToTypeID('null'), docRef);
            desc.putBoolean(stringIDToTypeID("compInfo"), true);  // just return the Layer Comp settings
            desc.putBoolean(stringIDToTypeID( "getCompLayerSettings" ), true); // return Layer Comp settings for each layer
            return executeAction(charIDToTypeID( "getd" ), desc, DialogModes.NO).getString(JSON);
          }
          

           

          Setting 'compInfo' to true will just return the comp settings, and 'getCompLayerSettings' to true will turn the layer information on.  The layer values remain hidden without the the last setting turned on. Then you get something like this for the output:

           

          {
            "id": 326,
            "count": 49,
            "timeStamp": 1477153891.92,
            "version": "1.5.0"
            "comps": [
            {
                "name": "Layer Comp 1",
                "position": true,
                "visibility": true,
                "appearance": false,
                "id": 462551238,
                "layerSettings": [
                  {
                    "layerID": 34,
                    "enabled": true,
                    "FXRefPoint": {"horizontal": -576, "vertical": -296},
                    "vectorMask": {"offset": {"horizontal": -1, "vertical": -1}}
                  },
                  {
                    "layerID": 40,
                    "enabled": false,
                    "layerSpecific": {"textLayerSettings": {"textLayerSettingsWarpRect": [0,0,0,0], "warpPerspective": 0, "warpPerspectiveOther": 0,"warpRotate": "horizontal", "warpStyle": "warpNone","warpValue": 0}}
                  }
                ],
              },
              {
                "name": "Layer Comp 2",
                "position": true,
                "visibility": true,
                "appearance": false,
                "id": 523795946,
                "layerSettings": [
                  {
                    "layerID": 34,
                    "enabled": true,
                    "FXRefPoint": {"horizontal": -576,"vertical": -54},
                    "offset": {"horizontal": 0, "vertical": 242},
                    "vectorMask": {"offset": {"horizontal": -1, "vertical": 241}}
                  },
                  {
                    "layerID": 40,
                    "enabled": false,
                    "layerSpecific": {"textLayerSettings": {"textLayerSettingsWarpRect": [0,0,0,0], "warpPerspective": 0, "warpPerspectiveOther": 0,"warpRotate": "horizontal", "warpStyle": "warpNone","warpValue": 0}}
                  }
                ],
              },
              {
                "name": "Layer Comp 3",
                "position": true,
                "visibility": true
                "appearance": false,
                "id": 717392943,
                "layerSettings": [
                  {
                    "layerID": 34,
                    "enabled": true,
                    "FXRefPoint": {"horizontal": -576, "vertical": 220},
                    "offset": {"horizontal": 0, "vertical": 516},
                    "vectorMask": {"offset": {"horizontal": -1, "vertical": 515}}
                  },
                  {
                    "layerID": 40,
                    "enabled": false,
                    "layerSpecific": {"textLayerSettings": {"textLayerSettingsWarpRect": [0,0,0,0], "warpPerspective": 0, "warpPerspectiveOther": 0,"warpRotate": "horizontal", "warpStyle": "warpNone","warpValue": 0}}
                  }
                ],
              }
            ],
          }
          

          So I'll have to spend extra time parsing the string to get the info I want, but at least I won't have to apply a Layer Comp to get it's values!

          2 people found this helpful