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

access text in library asset- undefined

Explorer ,
May 07, 2018 May 07, 2018

I have a library of text snippets in text frames.

I can place the asset on my page -- but my script is unable to access the text:

    var myObj = myAsset.placeAsset(app.activeDocument); // works -- text frame placed on page

    alert(myObj.contents); // undefined

the asset was created:

     tf=app.activeDocument.pages[0].textFrames.add();

    sel.duplicate(LocationOptions.AT_BEGINNING,tf);

        asset= lib.store([tf]);

        asset.name=name;

    tf.remove();

I can manually select/copy the text in the asset - but I need to select and then duplicate the snippet in my main text.

Any idea why it's not working?

Thanks

TOPICS
Scripting
606
Translate
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

correct answers 1 Correct answer

People's Champ , May 07, 2018 May 07, 2018

Place method returns an array of placed objects. So even if object is an unique instance, you need to access it through the index of place array.

var placed = ….place ( … ) [0];

FWIW

Loic

Translate
Explorer ,
May 07, 2018 May 07, 2018

Or is there some way to add just the text to a library without using a text frame?

Translate
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 ,
May 07, 2018 May 07, 2018

Place method returns an array of placed objects. So even if object is an unique instance, you need to access it through the index of place array.

var placed = ….place ( … ) [0];

FWIW

Loic

Translate
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 ,
May 07, 2018 May 07, 2018

What does placeAsset actually return?

Without experimenting, just looking at the documentation, it seems it returns an Array.

So perhaps this will work:

var myObj = myAsset.placeAsset(app.activeDocument)[0];

Ariel

Translate
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
Explorer ,
May 07, 2018 May 07, 2018
LATEST

Thanks to Loic.Aigon and TaW - that solved it

Translate
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