Skip navigation
Currently Being Moderated

JS Obtain list of elements in library asset

Jun 1, 2012 8:00 AM

Tags: #javascript #library_assets #getelements

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

 
Replies
  • Currently Being Moderated
    Jun 4, 2012 3:36 PM   in reply to secondgradersrule

    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.

     
    |
    Mark as:
  • Currently Being Moderated
    Jun 5, 2012 2:42 PM   in reply to secondgradersrule

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

     
    |
    Mark as:
  • Currently Being Moderated
    Jun 9, 2012 12:56 AM   in reply to Loic_aigon

    *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

     
    |
    Mark as:
  • Currently Being Moderated
    Jun 9, 2012 2:09 AM   in reply to Laubender

    @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

     
    |
    Mark as:
  • Currently Being Moderated
    Jun 10, 2012 6:16 AM   in reply to secondgradersrule

    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" ) );
    
     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points