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!
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.
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?
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.
North America
Europe, Middle East and Africa
Asia Pacific