7 Replies Latest reply on Apr 28, 2010 4:57 PM by JBL

    How to bring a .jpg into an open PSD file as a layer & smart object

    JBL Level 1

      Note: Posted in MAC section also.

      Goal:
      Using a script - Bring a .jpg an artist chooses, into Photoshop in an existing project into its own layer, and make it a smart object.
      This way, when the artist double-clicks on the smart object in Photoshop, it opens the original .jpg
      Currently, doing this creates a new window and file - a temp file, called xxx.psb.

      Photoshop does this by default to prevent destructive editing.  However, in this case, we purposely want to open the original.

      Why?  the .jpg files are approved art by the organization.


      Here is the script I did and have working in JavaScript.  (Has to be js because it will run on MAC's)

      Currently, it creates a NEW file.  I want it, however to create the SO as a layer in the existing open file.

       

      In JS: (has to be js for MAC's)
      var idOpn = charIDToTypeID( "Opn " );
          var desc4 = new ActionDescriptor();
          var idnull = charIDToTypeID( "null" );
          desc4.putPath( idnull, new File( "C:\\Users\\jleahy\\Desktop\\JPG_Meeting.jpg" ) );
          var idsmartObject = stringIDToTypeID( "smartObject" );
          desc4.putBoolean( idsmartObject, true );
      executeAction( idOpn, desc4, DialogModes.NO );

        • 1. Re: How to bring a .jpg into an open PSD file as a layer & smart object
          Michael L Hale Level 5

          The function below will place an image in the actvieDocument as a smart object.

           

          function placeFile( file) {
              var desc = new ActionDescriptor();
              desc.putPath( charIDToTypeID('null'), file );
              desc.putEnumerated( charIDToTypeID('FTcs'), charIDToTypeID('QCSt'), charIDToTypeID('Qcsa') );
                  var offsetDesc = new ActionDescriptor();
                  offsetDesc.putUnitDouble( charIDToTypeID('Hrzn'), charIDToTypeID('#Pxl'), 0.000000 );
                  offsetDesc.putUnitDouble( charIDToTypeID('Vrtc'), charIDToTypeID('#Pxl'), 0.000000 );
              desc.putObject( charIDToTypeID('Ofst'), charIDToTypeID('Ofst'), offsetDesc );
              executeAction( charIDToTypeID('Plc '), desc, DialogModes.NO );
          };
          • 2. Re: How to bring a .jpg into an open PSD file as a layer & smart object
            Michael L Hale Level 5

            I just re-read this post. The function I posted will place an image as a smart object but when that smart object is edited, it's a copy that will be edited.

             

            I made a 'links' panel that will allow you to place a smart object and edit the original image. You can find the panel at http://ps-scripts.com/bb/viewtopic.php?t=3045

            • 3. Re: How to bring a .jpg into an open PSD file as a layer & smart object
              JBL Level 1

              This is so nice that you took the time, so I don't want to fail in

              appreciation.

               

              Tried runing the script - mouse changes for a moment, so it looks like its

              running, but no result.

              Tried the links panel, but after installing the extension, CS4 crashes when

              choosing 'Window > Extensions > Links;

              Unhandled exception at 0x004d2fd8 in Photoshop.exe: 0xC0000005: Access

              violation reading location 0x0000c07b.

               

              Thanks for taking the time altruistically like this.  I don't want to

              presume further on your kindness, so i'll understand you not taking further

              time on it.

              Jim

              • 4. Re: How to bring a .jpg into an open PSD file as a layer & smart object
                Michael L Hale Level 5

                The script I posted is just a function. You need to set a file reference to an image and have a documet open before calling that function.

                 

                May I ask what platform you are using. Even if you don't care to use the Links panel I would like to try and correct that error.

                • 5. Re: How to bring a .jpg into an open PSD file as a layer & smart object
                  JBL Level 1

                  Hi Michael.

                  Using Win7 32 bit and PS CS4 extended on which it failed. I am remote at the

                  client on this machine.

                  I did try the extension just before leaving on my office machine, and it

                  woked there:

                  Win 7 64-bit PS CS4 extended.

                   

                  Also: how did you build that panel?  Wondering if I may have to ventre

                  there also.

                   

                  Another possibility someone suggested:

                  I suppose one could, though, create a Script that offers a File

                  Selection-dialog for placing images and writes that image’s location into

                  the containing psd’s metadata (or into notes, layer names, …).

                  A second Script could then, if invoked when a Smart Object is selected,

                  evaluate that data and call in/replace the SO with the respective

                  server-file.

                  • 6. Re: How to bring a .jpg into an open PSD file as a layer & smart object
                    Michael L Hale Level 5

                    It's my understanding that Windows 7 has trouble with Flex/Flash panels in gerenal so I may not be able to do anything about that error on Win7.

                     

                    I suppose one could, though, create a Script that offers a File

                    Selection-dialog for placing images and writes that image’s location into

                    the containing psd’s metadata (or into notes, layer names, …).

                    A second Script could then, if invoked when a Smart Object is selected,

                    evaluate that data and call in/replace the SO with the respective

                    server-file.

                     

                    The panel was created with Flex Builder. And that is about how the panel works. When the user places a smart object using the panel it writes the path to the original file into the smart object layer's metadata. It also write the files last mod date. Using event listeners every time a linked smart object layer is selected the panel show the status of the link. And there are buttons at the bottom of the panel that allow a user to update the smart object if the original has been changed, edit the original, or replace the smart object's contents.

                     

                    It was designed to be as close to the InDesign links panel as I could make it given the scripting limits.

                     

                    If you like you might be able to pull some of the functions used in the javascript that goes with that panel and adapt them for standalone scripts.

                    • 7. Re: How to bring a .jpg into an open PSD file as a layer & smart object
                      JBL Level 1

                      I'm half way there, but stuck at:

                      Getting a file location reference when the .jpg is first brought into PS as a layer.

                      Getting a script to write the location of the file into the medata for the PSD in some field

                      Reading back the metadata file location for the .jpg and bringing it back into the PSD again.

                       

                      Any help would really be appreciated.

                      I can make the completed script(s) available when its complete, as this has possibilities for other uses, batch process, and more.