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

    Import PSD to AI layer

    lilsmokie Community Member

      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 Community Member

          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?

          • 2. Re: Import PSD to AI layer
            lilsmokie Community Member

            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 Community Member

              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 Community Member

                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.