I am trying to develop a script to obtain a list of elements in each library asset, and the link status of each. The workaround has been to place each asset onto a page and then use the Links window to check the status of the elements.
This code returns [object Asset]:
var libList = app.libraries.item(0).assets.item(0).getElements();
This returns the name of the asset:
var libName = app.libraries.item(0).assets.item(0).name;
The eventual goal is to write a script for off-site disaster recovery. It would relink each library asset element to a backup copy in the new location.
Is this possible without writing a script to place each asset, update the links and then put it back in the library?
Thanks.
Dick Conrad
Hi,
Sure it is, however, it's basically consisting in placing library item, editing item, replacing ( or updating* ) item, removing placed content.
Quite time consuming but still quicker than manual operations.
I wrote a snippet that you need to set for your own needs :
function updateAllAssetsInLib ( lib )
{
var libAssets = lib.assets.everyItem().getElements(), libAsset, placedAsset, doc = app.activeDocument;
while ( libAsset = libAssets.pop() )
{
placedAsset = libAsset.placeAsset ( doc );
placedAsset = placedAsset[0];
// do your stuff;
libAsset.remove();
lib.store ( placedAsset );
placedAsset.remove();
}
}
updateAllAssetsInLib ( app.libraries.itemByName ( "foo.indl" ) );
Hope it helps,
Loic
*Pretty sure there is a "update library item" that you can call with meanuAction.invoke() but recently it disappeared from my UI to the point I started wondering if I had dreamed about it.
*Pretty sure there is a "update library item" that you can call with meanuAction.invoke() but recently it disappeared from my UI to the point I started wondering if I had dreamed about it.
@Loic – you are not dreaming ;-)
Try the following:
//Invoke the menu "Update Library Item":
try{app.scriptMenuActions.itemByID(34410).invoke()}catch(e){};
I got the ID from InDesign CS4 and it is still the same in InDesign CS5 and CS5.5.
Uwe
@Uwe Thanks, I feel safer now
However, I don't know if it's a bug. I used it intensively ( invokinbg the update ). And then it really vanished from the UI, the contextual menu just doesn't display the command any longer. I had to modify my script in order to place asset, edit placed item, store edited item, remove former asset. That's dumb but it's all I have left ![]()
Loic:
Your code was very helpful in building a script to batch-change the paths of library items. I did find a quirk with Indesign CS.
I tested my script in CS5. An asset with three elements (two images plus text) ended up with the new paths! I then ran it against a large CS library, omitting the image swap and just generating a list of assets and links. Each replacement asset received the name 'untitled.' The production use of the script will be in CS5 so I am not concerned, and I have not tried forcing the asset name into the replacement for use with CS.
Dick
Hi Dick,
Yes, it's "normal"; To be complete the snippet should include the asset name
function updateAllAssetsInLib ( lib )
{
var libAssets = lib.assets.everyItem().getElements(), libAsset, assetName, placedAsset, doc = app.activeDocument;
while ( libAsset = libAssets.pop() )
{
assetName = libAsset.name;
placedAsset = libAsset.placeAsset ( doc );
placedAsset = placedAsset[0];
// do your stuff;
libAsset.remove();
lib.store ( placedAsset, {name:assetName} );
placedAsset.remove();
}
}
updateAllAssetsInLib ( app.libraries.itemByName ( "foo.indl" ) );
North America
Europe, Middle East and Africa
Asia Pacific