I am building a script that automates new document creation for our company and have run into a problem with placing library assets.
I want to add a library asset to a specific master page by name, but I cannot find a way to do this.
I can get assets to place into my document with this:
var t = app.libraries.item(0);
var libTapeStrip= t.assets.itemByName('Tape Strip');
var myTapeStrip = libTapeStrip.placeAsset(myDocument);
However, the asset is being placed on a master spread that I had previously added to the document. It seems to be the active or front most spread because when the script is complete and I create a new window that spread is what is displayed with the asset on it.
I would like to place the asset on another master spread, but placeAsset() only accepts documents and text boxes. I have also looked on a way to bring the master spread I want to the front, but cannot find this either.
If anyone can lead me in the right direction I would appreciate it!!
@Benjamin – You could make the spread (or the page) where you want to place that asset the "activeSpread" or "activePage", place the asset and then go back to the old active one.
Something like this:
(Here I assume that you want to place your asset on a master spread named "A-Master" and the asset is the first in the one and only library file that is open.)
var myDocument = app.documents; var myMaster = app.documents.masterSpreads.itemByName("A-Master"); var myLibrary = app.libraries; var myAsset = myLibrary.assets; var myOLDActiveSpread = myDocument.windows.activeSpread; myDocument.windows.activeSpread = myMaster; myAsset.placeAsset(myDocument); myDocument.windows.activeSpread = myOLDActiveSpread;
Message was edited by: Laubender
Message was edited by: Laubender [Nothing edited in the code.]
It works well. I realized I was trying to manipulate the window without adding one until after I was placing the asset.
I appreciate your time and help!