2 Replies Latest reply on Mar 21, 2017 1:16 AM by johny roger

    Streamline ScriptingListener code?

    johny roger Level 1

      Hello All

       

      as i'm pretty new to scripting for PS and i haven't found an answer to this. Is there a good resource page (i haven't found) or a tutorial about it?

       

      • Does it make sense or is it even possible to streamline the code generated by the ScriptingListener plugin?

       

      I have the following code and it would be awesome to combine it into one function and get rid of unnecessary code:

      function Selecttexures() {
        // Select
        function step1(enabled, withDialog) {
          if (enabled != undefined && !enabled)
            return;
          var dialogMode = (withDialog ? DialogModes.ALL : DialogModes.NO);
          var desc1 = new ActionDescriptor();
          var ref1 = new ActionReference();
          ref1.putName(cTID('Lyr '), "LIGHT FABRIC TEXTURE");
          desc1.putReference(cTID('null'), ref1);
          desc1.putBoolean(cTID('MkVs'), false);
          var list1 = new ActionList();
          list1.putInteger(43);
          desc1.putList(cTID('LyrI'), list1);
          executeAction(cTID('slct'), desc1, dialogMode);
        };
      
      
        // Select Linked Layers
        function step2(enabled, withDialog) {
          if (enabled != undefined && !enabled)
            return;
          var dialogMode = (withDialog ? DialogModes.ALL : DialogModes.NO);
          var desc1 = new ActionDescriptor();
          var ref1 = new ActionReference();
          ref1.putEnumerated(cTID('Lyr '), cTID('Ordn'), cTID('Trgt'));
          desc1.putReference(cTID('null'), ref1);
          executeAction(sTID('selectLinkedLayers'), desc1, dialogMode);
        };
      
      
        // Hide
        function step3(enabled, withDialog) {
          if (enabled != undefined && !enabled)
            return;
          var dialogMode = (withDialog ? DialogModes.ALL : DialogModes.NO);
          var desc1 = new ActionDescriptor();
          var list1 = new ActionList();
          var ref1 = new ActionReference();
          ref1.putEnumerated(cTID('Lyr '), cTID('Ordn'), cTID('Trgt'));
          list1.putReference(ref1);
          desc1.putList(cTID('null'), list1);
          executeAction(cTID('Hd  '), desc1, dialogMode);
        };
        step1();      // Select
        step2();      // Select Linked Layers
        step3();      // Hide
      };