• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

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

Contributor ,
Jan 09, 2018 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.8K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
People's Champ ,
Jan 10, 2018 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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Jan 11, 2018 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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 11, 2018 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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Jan 11, 2018 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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
People's Champ ,
Jan 11, 2018 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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 12, 2018 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

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

Hi Robert,

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

Thanks

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Apr 06, 2023 Apr 06, 2023

Copy link to clipboard

Copied

LATEST

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

Votes

Translate

Translate

Report

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