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

Participant ,
Jan 09, 2018

Copy link to clipboard

Copied

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;

                }

        }

}

TOPICS
Scripting

Views

1.4K

Likes

Translate

Translate

Report

Report
Reply
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Valorous Hero ,
Jan 10, 2018

Copy link to clipboard

Copied

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

Likes

Translate

Translate

Report

Report
Reply
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
tmmls AUTHOR
Participant ,
Jan 11, 2018

Copy link to clipboard

Copied

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

Likes

Translate

Translate

Report

Report
Reply
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Adobe Community Professional ,
Jan 11, 2018

Copy link to clipboard

Copied

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

Likes

Translate

Translate

Report

Report
Reply
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Contributor ,
Jan 11, 2018

Copy link to clipboard

Copied

Another possible workaround: Store the page item label in the Item Description field of the library asset. Your script can find the asset by looking at at Item Descriptions, place it on the page, then find the Page Item by looking at the label.

Likes

Translate

Translate

Report

Report
Reply
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Valorous Hero ,
Jan 11, 2018

Copy link to clipboard

Copied

Another option might be to not work with libraries at all and prefer storing snippets on the file system. It would be easy to look at labels as snippets are xml files. But of course it discards the ability of having an interface for manually dropping the items onto the document.

Another option would be to store some kind of "reference" in the app object (app.insertLabel) so you can retrieve this value later on and place the related asset but there could be so many flaws in that approach.

Loic

Likes

Translate

Translate

Report

Report
Reply
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Adobe Community Professional ,
Jan 12, 2018

Copy link to clipboard

Copied

Hi Loic,

yes, the app.insertLabel() thing is not reliable.
If the user has to restore preferences the labels will be gone.

And there is really no chance to remove the labels without a trace by ExtendScript.
( Other than to provide new preferences. )

However the snippet approach is a good one, I think.
Of course that will depend on the current workflow of the enduser.

Regards,
Uwe

Likes

Translate

Translate

Report

Report
Reply
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
tmmls AUTHOR LATEST
Participant ,
Jan 12, 2018

Copy link to clipboard

Copied

Hi Robert,

Thank you for your suggestion. Using the description field seems a solid workaround ...

Thanks

Likes

Translate

Translate

Report

Report
Reply
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more