Welcome Dialog

Welcome to the Community!

We have a brand new look! Take a tour with us and explore the latest updates on Adobe Support Community.


got to anchor behavior on a button

Community Beginner ,
Feb 17, 2021 Feb 17, 2021

Copy link to clipboard

Copied

Hello everyone,

I just started using scripting in Indesign (version 15.0.1) and I am making a script for generating a doc with buttons leading to bookmarks throughout the pdf. I have been able to generate bookmarks for each page, also generate the buttons and my issue with the gotoAnchor behavior. The gotoAnchor is supposed to take in an anchorItem (a bookmark, a hyperlink text or a hyperlink page), but when I pass my bookmark into the anchorItem the generated buttons always lead to the very first bookmark, no matter which one I pass in. I attach a part of the code here and would appreciate any help - it seems this would either be a bug, or I am unaware of something specific in regards to the bookmarks. For additional information, the bookmark object gets passed and prints out the right name in console, for image handling I am using basil.js.

TOPICS
Scripting

Views

163

Likes

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
Adobe Community Professional ,
Feb 17, 2021 Feb 17, 2021

Copy link to clipboard

Copied

Please use "Insert Photos"; not "Insert Link"

Mike Witherell

Likes

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
Adobe Community Professional ,
Feb 17, 2021 Feb 17, 2021

Copy link to clipboard

Copied

My guess what's going wrong:

Try to set all property/value pairs of the gotoAnchorBehavior while adding the behavior to the new button.

Don't forget enableBehavior that should be set to true.

Hm. I'd set the behaviorEvent to MOUSE_UP.

 

Here a code snippet where I simply assume the first bookmark in the document is the one for anchorItem:

 

newButton.gotoAnchorBehaviors.add
(
	{
		behaviorEvent : BehaviorEvents.MOUSE_UP ,
		enableBehavior : true ,
		anchorItem : doc.bookmarks[0]
	}
);

 

Please provide an InDesign sample document so I or others could have a look.

Put it on Dropbox or a similar service and post the download link.

 

Thanks,
Uwe Laubender

( ACP )

 

Likes

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 Beginner ,
Feb 17, 2021 Feb 17, 2021

Copy link to clipboard

Copied

Thank you so much for the reply! I am adding the script here as well as the indesign doc and the image and text files, so it's easy to test. I tried setting all properties on adding the behavior, but all buttons still link to the very first bookmark, even if I go anchorItem: doc.bookmarks[3] for example.

Here is a dropbox link: https://www.dropbox.com/sh/voktvuoebqzj0br/AAAf1WBBXEVcn95ikGSbEJ6da?dl=0

Thanks in advance!

Likes

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 Beginner ,
Feb 19, 2021 Feb 19, 2021

Copy link to clipboard

Copied

Hello!

Just wondering if you had any ideas, I dug around more, but not much changed, the same happens even on an empty doc with just one button, it doesn't pick up the anchor item. Another quirky thing is that in the dropdown destination list the bookmarks appear out of order, and also buttons don't work unless before exporting to interactive pdf I click on them within Indesign itself. I attach a picture of the list order. Would really appreciate any help, I have a project finishing next Friday and everything else is working so far, just this thing is really dragging it all down. Thanks in advance!

1.png

Likes

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
Adobe Community Professional ,
Feb 20, 2021 Feb 20, 2021

Copy link to clipboard

Copied

Hi VytautasBik,

did some tests with your document, also with one of my own documents and my own code where I assigned different bookmarks as value for property anchorItem of the gotoAnchorBehavior.

 

Yes, we have a problem, I can confirm:

Always the first bookmark is added as anchorItem to the behavior.

That's a bug! ( Or DOM documentation is misleading. )

 

Let's see if we can work around the issue if we address bookmark.destination instead of bookmark.

Yep! This works!

 

Regards,
Uwe Laubender

( ACP )

Likes

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 Beginner ,
Feb 20, 2021 Feb 20, 2021

Copy link to clipboard

Copied

Hello!

Gotcha, this is both good and bad news, thank you so much for checking it for me! I was wondering if you could attach a snippet of code where you use bookmark.destination for the button, were you still using that inside the gotoAnchorBehavior?

Ultimately what I wanted was a randomly assigned page destination for each button (for Interactive PDF), so I just really need the buttons to be leading to different pages after running the script. Since gotoPage behavior is not supported for PDF I resorted to gotoAnchor. Would there be a better way to do this randomized page destination assigning?

 

Best,

Vytautas

Likes

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 Beginner ,
Feb 20, 2021 Feb 20, 2021

Copy link to clipboard

Copied

Oh my I just used a hyperlinkPageDestination as the anchorItem and that worked perfectly - feel incredibly dim for not thinking of that earlier. Thank you so much for your help, have a great day!!

Likes

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
Adobe Community Professional ,
Feb 22, 2021 Feb 22, 2021

Copy link to clipboard

Copied

LATEST

VytautasBik said:
"…I was wondering if you could attach a snippet of code where you use bookmark.destination for the button, were you still using that inside the gotoAnchorBehavior?"

 

Looking at the code you presented in your screenshot with your initial post this would be:

behavior.anchorItem = anchor.destination;

The anchor variable holds a bookmark. Just use the destination of that bookmark.

 

Regards,
Uwe Laubender

( ACP )

Likes

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