4 Replies Latest reply on Sep 8, 2012 2:32 PM by lilsmokie

    Import PSD to AI layer

    lilsmokie Level 1

      I am new to scripting in Illustrator.

      I am trying to import PSD files into an AI layer.

      So far this is my solution.

       

      var TRGdoc = app.documents.add(DocumentColorSpace.RGB, "1920", "1080");

       

      var onFile = File( '~/Desktop/jpeger/illDanceREFon_00642.psd' );

      var REFon = app.open(onFile);

      var LAYon = REFon.layers[0];

      var LAYstuffon = LAYon.pageItems[0];

      LAYstuffon.selected = true;

      app.copy();

      TRGdoc.activate();

      var TRGlayer = TRGdoc.layers[0];

      TRGlayer.selected = true;

      app.paste();

       

      It works most of the time but sometimes it hangs up on the paste.  It feels sloppy.

      Just wondering if a more elegant solution exists.

       

      Thanks for looking!

        • 1. Re: Import PSD to AI layer
          Muppet Mark Level 5

          You are opening the *.psd file then using the clipboard to copy to another doc? Why don't you just place the *.psd, move it where ever then embed if you want?

          1 person found this helpful
          • 2. Re: Import PSD to AI layer
            lilsmokie Level 1

            That sounds like the way to go!  Exactly the kind of thing I'm looking for.

             

            Like I said I am new.

            So I seached the docmentation for place.

            I found placed items when used with add() should do what I need.

            So this was a fail: 

            var TRGdoc = app.documents.add(DocumentColorSpace.RGB, "1920", "1080");

            var onFile = File( '~/Desktop/jpeger/illDanceREFon_00642.psd' );

            var poop = TRGdoc.placedItems.add(onFile);

            TRGdoc.layers[0].move(poop, ElementPlacement.INSIDE);

             

            Not sure how to do this.  I haven't been able to pull up just a simple example online.  So I am working through the documentation.

            If you know of any examples of code I would appreciate it.

             

            Just knowing that this is possible is a big help.

            Thanks.

            • 3. Re: Import PSD to AI layer
              Muppet Mark Level 5

              Untested but placedItems.add() does not have any parameters for your file object… You can set the property after creation… Like so…

               

              var TRGdoc = app.documents.add(DocumentColorSpace.RGB, "1920", "1080");
              var onFile = File( '~/Desktop/jpeger/illDanceREFon_00642.psd' );
              var poop = TRGdoc.placedItems.add();
              poop.file = onFile;
              //poop.move(TRGdoc.layers[0], ElementPlacement.INSIDE); should be here by default?
              
              • 4. Re: Import PSD to AI layer
                lilsmokie Level 1

                Then to embed:

                var TRGdoc = app.documents.add(DocumentColorSpace.RGB, "1920", "1080");

                var onFile = File( '~/Desktop/jpeger/illDanceREFon_00642.psd' );

                var poop = TRGdoc.placedItems.add();

                poop.file = onFile;

                poop.embed();

                 

                Yes that worked.

                I know it seems easy but I just don't have the hang of how this works yet.

                So helpful I really appreciate it.

                Thanks so much.