Welcome Dialog

Welcome to the Community!

We have a brand new look! Take a tour with us and explore the latest updates on Adobe Support Community.


javascript placedItem.add() issue

Community Beginner ,
Mar 03, 2021 Mar 03, 2021

Copy link to clipboard

Copied

Hi everybody,

I'm new to both javascript and scripting for Illustrator, however, I'm not new to programming in general.

 

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.

 

Thanks

TOPICS
Import and export, Scripting, SDK, Tools

Views

138

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Beginner , Mar 04, 2021 Mar 04, 2021
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.

Likes

Translate

Translate
Advocate ,
Mar 03, 2021 Mar 03, 2021

Copy link to clipboard

Copied

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[0].file.absoluteURI );

 

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Mar 03, 2021 Mar 03, 2021

Copy link to clipboard

Copied

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);

app.open(printFile);

 

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?

 

Thanks

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Mar 03, 2021 Mar 03, 2021

Copy link to clipboard

Copied

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.

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
Mar 03, 2021 Mar 03, 2021

Copy link to clipboard

Copied

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.)

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Mar 04, 2021 Mar 04, 2021

Copy link to clipboard

Copied

Hi @Erica5FEC 

How about:

 

// the file must exist
var aFile = File('~/Desktop/test_file.jpg');
var aDoc = app.activeDocument;
var aPlaced = aDoc.placedItems.add();
aPlaced.file = aFile;

 

 

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Mar 04, 2021 Mar 04, 2021

Copy link to clipboard

Copied

LATEST

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.

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines