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

[CS5][JS] Bookmark name problem (Bug?)

Explorer ,
Jun 20, 2011 Jun 20, 2011

Hi,

Can anyone please help me?

I'm trying to create a bookmark from a text selection. When running the script from indesign, in 80% of the tests, the name will not change to the selected text. In 20% of the cases it does change the name. I can't find any reason why. There is no pattern. No error occurs when running the script. When encapsulation the script in a try/catch, no exception is thrown.

When running the script from extendscript toolkit it ALWAYS works. It's driving me nuts.

The code:

                                var myText = app.selection[0].contents;

                                var myDoc = app.activeDocument;

                                var currPage = app.selection[0].parentTextFrames[0].parentPage;

                                var curBookmark = myDoc.bookmarks.add(currPage);

                                curBookmark.label = myText;

                                curBookmark.name = myText;

Any help would be great.

John

TOPICS
Scripting
1.4K
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
Community Expert ,
Jun 20, 2011 Jun 20, 2011

I remember that at some stage (CS4, I believe) you had to hide the Bookmarks panel before adding bookmarks (app.panels.item ('Bookmarks').visible = false;). I don't know if that'll help you but you'll find out soon enough.

Peter

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
Community Expert ,
Jun 21, 2011 Jun 21, 2011
LATEST

@Peter:

it's all the same with CS5. Same bug as in CS4 and CS3.

Hiding the panel, adding the bookmark, showing the panel.
That's the way it works.

@All:

What is really unfortunate with bookmarks:
If you have a couple of bookmarks and ask for myDoc.bookmarks.length you only get the ones at level 0.
You have to loop over bookmarks in bookmarks etc. to get them all. I'm missing a allBookmarks property 😉

And when we're at it: is it possible to indent a bookmark scriptwise? The property is read-only, but who knows?

Plus: beware of all kind of spaces inside the text you use for the name property.
See example here of a RegEx to eliminate the problem:

http://forums.adobe.com/message/1106334#1106334

In your code use:

curBookmark.name = myText.replace (/\s+/g, " ");

Otherwise you could end up with something like that:


Bookmarks_2lines.png

Uwe

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
LEGEND ,
Jun 20, 2011 Jun 20, 2011

Can you loop and keep trying until it works?

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
Community Beginner ,
Jun 21, 2011 Jun 21, 2011

Hi,

I recently had the same problem. I tried your solution and it seems to work.
For my part, I used another option in two steps :
1 - create all bookmarks and put their names in a label ;
2 - scan all bookmarks to set their names with thier label values if necessary.

Your solution is better. Thanks.

--
Manu

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
Community Expert ,
Jun 21, 2011 Jun 21, 2011

CS5, eh? This 3-yr-old post described the same problem for CS3 ...

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
LEGEND ,
Jun 21, 2011 Jun 21, 2011

But did you file a bug? If not., well...

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