I've been working on a script for placing artwork on artboards for my wife's and my business. I'm having a hard time getting the placedItems working consistently. I was previously able to place artwork with:
var currentDoc = app.activeDocument;
var placedImages = currentDoc.placedItems.add();
placedImages.file = artFile variable; (where artFile variable is the variable containing the path to the artwork file.
The add() function call is not working now though and I'm struggling to figure out why. I'm not totally familiar with ESTK, so I'm not really sure if there is any form of error reporting.
Is a <Linked File> added to the layers panel? If so, the add() function has done it's job (adding an empty placedItem), which implies that the problem is assigning the file, possibly with the path (assuming you are using a new File object with a path argument). Test that you are using the correct path by placing the image manually (File > Place), selecting it and using
alert( selection.file.absoluteURI );
It isn't adding the linked file because the add() function statement won't complete. I think I found out why, but I'm not really sure how to fix it...
if I create a new document with app.documents.add(), the following placedItem.add() statement works. However, I'm trying to use an existing artboard, so I'm doing the following:
var printFile = FILE(fileLocation);
Then I try to do a placedItem.add() and it fails. I'm not sure if there is a data type issue, or maybe an issue with not "adding" a data file?
Is your current doc being set to the app.open result?
Also use a try-catch to alert errors in case you are writing and running in a way that has Illustrator silent on some of these errors.
Are you able to open the doc? Because "FILE" is not a function/constructor. This opens the doc Untitled-1.ai on my desktop and adds a <Linked File> to the layers panel:
var printFile = new File("~/Desktop/Untitled-1.ai"); app.open(printFile); var currentDoc = app.activeDocument; var placedImages = currentDoc.placedItems.add();
(Illustrator alerts me that the linked file is missing because I haven't assigned it, which would be the next step.)
Well, I feel a little dumb about this, but to my defense I don't really know Illustrator all that well... but I kept having this issue because the layer I was trying to place the art file into was locked. It worked perfectly fine after I unlocked it...
Thanks for the suggestions.