0 Replies Latest reply on Apr 9, 2015 12:08 AM by mlp.lt

    Copy/Capture Adjustment Layer settings using Javascript




      For last couple of days I'm trying to copy adjustment layer settings via Javascript after adjustment layer has been already created.


      General idea is to capture adjustment layer settings and save them to JSON file for future preset etc. I was hoping to capture raw data ( getData(stringIDToTypeID('legacyContentData'))) and store it in JSON file base64 encoded.


      I'm able to capture raw data but I'm not able to restore it to the adjustment layer using putData or something similar.


      Capture raw data of adjustment layer:

      var doc = app.activeDocument;
      var layer = doc.activeLayer;
      ref.putEnumerated(charIDToTypeID("Lyr "), charIDToTypeID("Ordn"), charIDToTypeID("Trgt"));
      var desc = executeActionGet(ref).getList(stringIDToTypeID('adjustment')).getObjectValue(0);
      rawData = desc.getData(stringIDToTypeID('legacyContentData'));


      Trying to restore raw data:

         var desc = new ActionDescriptor();
              var ref = new ActionReference();
              ref.putEnumerated(cTID('AdjL'), cTID('Ordn'), cTID('Trgt'));
              desc.putReference(cTID('null'), ref);
              aldesc = new ActionDescriptor();
              aldesc.putEnumerated(sTID("presetKind"), sTID("presetKindType"), sTID("presetKindCustom"));
              var list1 = new ActionList();
      // Not sure what to do here ... 
              aldesc.putList(cTID('Adjs'), list1);
              desc.putObject(cTID('T   '), id, aldesc);
              executeAction(cTID('setd'), desc, mode);

      If I'm using above code with code generated by i.e. script listener or action translated into javascript it works (at least for curves), but I'd rather use getData/putData so I can capture already created adjustment layers with out need to code each layer separately. toStream and fromStream also would work, but I wasn't able to restore data using these methods too.


      Help would be appreciated.