Skip to main content
Inspiring
September 8, 2012
Answered

Import PSD to AI layer

  • September 8, 2012
  • 1 reply
  • 1608 views

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!

This topic has been closed for replies.
Correct answer Muppet Mark

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?

1 reply

Inspiring
September 8, 2012

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?

lilsmokieAuthor
Inspiring
September 8, 2012

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.

Muppet MarkCorrect answer
Inspiring
September 8, 2012

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?