Skip to main content
Inspiring
January 9, 2018
Question

[CC2018][Os X][JS] Place asset based on a script label

  • January 9, 2018
  • 2 replies
  • 2292 views

Hi,

With this post I would like to ask a question.

I have a library and I would like to place an asset on my document using the script label (not using the item name).

When looping the library assets, I'm not able to check the label. When checking the label contents, it always seems to be empty.

When placing the asset manually, the script label is filled in.

Is this a bug ?

Thanx

placeAsset();

function placeAsset(){

    var myLib = app.libraries.item("myLibrary.indl");

    var myItem = getItemFromLib(myLib, "import");

    myItem.placeAsset(app.activeDocument);

}

function getItemFromLib(myLib, myLabel){

        for(g = 0; g < myLib.assets.length; g++){

                var myItem = myLib.assets;

                if (myItem.label == myLabel){   // This doesn't work

                        return myItem;

                }

        }

}

This topic has been closed for replies.

2 replies

koes73
Participant
April 6, 2023

Hi,

I know my comment is a little bit late, but I think this line of your code also should be corrected:

var myItem = myLib.assets;

to

var myItem = myLib.assets[g];

 

Bye,

Koes

Loic.Aigon
Legend
January 10, 2018

Your problem is that you an asset isn't a page item but a reference to a internal snippet. It becomes a page item at the moment you actually place them onto the page manually or programatically.

So what is an asset "label" ?  Some property you can read/write and this label will survive as long as the asset stands inside the library. But that will be thrown away when the asset will be placed inside the library.

So if you need a "persistent" label, you need to insert the script label before to put the item onto the library.

Loic

tmmlsAuthor
Inspiring
January 11, 2018

Hi Loic,

The label was applied to the item, before the item was stored in the library. When adding the item to the page again, the label is still applied. So how do I check the label when the item is in the library? Using myLib.assets.label doesn't seem to work.

Thanks

Community Expert
January 11, 2018

Hi,

you simply cannot check that. You have to place the asset or at least load it to the place gun and do a check with that.

As a workaround you could place the assets to a spread of a windowless document if you prefer.

For that try:

app.documents.add( false )

DOM Documentation by Jongware:

Adobe InDesign CS6 (8.0) Object Model JS: Documents

Regards,
Uwe