5 Replies Latest reply on Jan 19, 2012 8:21 AM by grefel

    Place Image into Layer

    grefel Level 2

      Hey,

       

      this is my first Photoshop Script. It is running, but I would like to know if there is a more elegant solution without copy & paste.

       

      In short: I would like to compare to images by putting them in two layers. The following scripts achieves this by opening both images, and copy the content of the second into the first. Is there something like place() in the DOM.

       

      var _folderOrig  = _folderOrig.selectDlg ("Original Images");

      var _folderNew = new Folder (_folderOrig.parent + "/split-epub");

      var _fileArray = _folderOrig.getFiles();

       

      for (var i = 0; i < _fileArray.length; i++) {

          var _file = _fileArray[i];

          var _dok1= app.open(_file);

          var _copyDok = app.open(new File (_folderNew + "/" + _file.name));

          _copyDok.activeLayer.copy();

          app.activeDocument = _dok1;

          _dok1.paste(false);

          _dok1.activeLayer.opacity = 50;

      }

       

       

      Thanks!

      Gregor

        • 1. Re: Place Image into Layer
          Muppet Mark Level 5

          app.open() has 'as smart object' boolean as it's last parameter… or you can use scriptlistener too… If you want to compair 2 files don't you just want difference? as a blend mode?

          • 2. Re: Place Image into Layer
            grefel Level 2

            How does a SmartObject helps? Can i move Layers between Documents? The straighforward approach does not work:

             

            _copyDok.activeLayer.move(_dok1.artLayers[0], ElementPlacement.PLACEAFTER)

             

            Blendmode is a good idea! I've set:

             

            _dok1.activeLayer.blendMode = BlendMode.DIFFERENCE;

             

            thanks.

            • 3. Re: Place Image into Layer
              Muppet Mark Level 5

              Can you duplicate layers between documents… Personally I would use the scriptlistener function for this ( you will find that in this forum ) over the DOM… Difference mode is a commonly used method…

              1 person found this helpful
              • 4. Re: Place Image into Layer
                Michael L Hale Level 5

                Try _copyDok.activeLayer.duplicate( _dok1 );

                 

                That will dupe the activeLayer of copyDok to dok1 above the activeLayer in dok1. You can then use move to order the layer if you wish. The only advantage scriptlistener code has over the DOM duplicate method is it lets you rename the layer as you make the dupe.

                 

                For the place command you need to use scriptlistener. Something like this

                 

                function placeSmartObject( fileRef ){// file object or path as strng

                    try {

                        var desc = new ActionDescriptor();

                            desc.putPath( charIDToTypeID( "null" ), new File( fileRef ) );

                            desc.putEnumerated( charIDToTypeID( "FTcs" ), charIDToTypeID( "QCSt" ),charIDToTypeID( "Qcsa" ));

                            desc.putUnitDouble( charIDToTypeID( "Wdth" ),charIDToTypeID( "#Prc" ), 100 );

                            desc.putUnitDouble( charIDToTypeID( "Hght" ), charIDToTypeID( "#Prc" ), 100 );

                            desc.putUnitDouble( charIDToTypeID( "Angl" ), charIDToTypeID( "#Ang" ), 0 );

                            desc.putBoolean( charIDToTypeID( "Lnkd" ), true );

                            executeAction( charIDToTypeID( "Plc " ), desc, DialogModes.NO );

                            activeDocument.activeLayer.resize(100 ,100,AnchorPosition.MIDDLECENTER);

                            activeDocument.revealAll();

                            return true;

                      } catch (e) {

                          return false;

                  }

                };

                 


                • 5. Re: Place Image into Layer
                  grefel Level 2

                  thanks all of you!