Skip to main content
jasonp49818280
Inspiring
December 30, 2020
Answered

Javascript: Placing an Item with multiple artboards

  • December 30, 2020
  • 2 replies
  • 445 views

Is there a way to access the import options on a placed item?

 

if you place an ai file with multiple artboards you are allowed to choose which "page" is placed, but when using the javascript it defaults to the first page. Is there a way to access that? I have looked through the javascript guide, but havent found anything.

This topic has been closed for replies.
Correct answer CarlosCanto
// place a specific Artboard from an ai doc

var idoc = app.activeDocument;

var pdfOptions = app.preferences.PDFFileOptions;
pdfOptions.pageToOpen = 4; // it works for Artboards since placing an ai file places the pdf version

var iplaced = idoc.placedItems.add();

iplaced.file = File( '/c/...full path.../your file.ai');

2 replies

CarlosCanto
Community Expert
CarlosCantoCommunity ExpertCorrect answer
Community Expert
December 31, 2020
// place a specific Artboard from an ai doc

var idoc = app.activeDocument;

var pdfOptions = app.preferences.PDFFileOptions;
pdfOptions.pageToOpen = 4; // it works for Artboards since placing an ai file places the pdf version

var iplaced = idoc.placedItems.add();

iplaced.file = File( '/c/...full path.../your file.ai');
femkeblanco
Legend
December 30, 2020

My understanding is that artboards are not container objects; i.e. artboards do not contain items (e.g. placedItems). But you can position an item "on" an artboard; you just position the item in relation to the artboard in question.

 

var yourFile = new File(path);
var yourPic = app.activeDocument.placedItems.add();
yourPic.file = yourFile;

var AB = app.activeDocument.artboards[index];
// var AB = app.activeDocument.artboards.getByName(name);
yourPic.position = [AB.artboardRect[0], AB.artboardRect[1]];

 

Edit:  It seems I misunderstood the question.