Skip to main content
June 1, 2012
Pregunta

JS Obtain list of elements in library asset

  • June 1, 2012
  • 1 respuesta
  • 2225 visualizaciones

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

Este tema ha sido cerrado para respuestas.

1 respuesta

Loic.Aigon
Legend
June 4, 2012

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.

June 5, 2012

Thanks for the help.  I will enjoy stepping through this and watching the action.  In the meantime, I am wondering why the link status of an element can't be obtained via a property.  Apparently InDesign has to place the item before attemping to resolve the source.

Thanks again.

Dick Conrad

Loic.Aigon
Legend
June 5, 2012

No I don't think you can check at link status while asset is in the library.