Skip to main content
Known Participant
May 24, 2024
Question

Trying to automate inserting Text Anchors

  • May 24, 2024
  • 2 replies
  • 1003 views

Hi all!

 

I'm trying to write a script that goes to the start of each line in a certain style and creates a text anchor. Does anyone know if you can code the action of creating a text anchor? Problem two is that it needs to be named with the text following it (>_<).

So, in the following text which is all styled the same, it will go, create an anchor at the start of each line, and name it with the text on that line?

 

Dedication

Chapter 1

Chater 2

 

etc

 

Does that make sense? I'm not even sure if this is possible to put in a script but I figured if it is, here's where someone can help me with it!

 

Thanks for reading, 

 

Eubhal

This topic has been closed for replies.

2 replies

Robert at ID-Tasker
Legend
May 28, 2024

@EubhaLiath

 

Why do you need to do this?

 

Known Participant
May 28, 2024

Hi! I need it in order to have a script that inserts text anchors so I can link to them later in the document so that an epub converted from the file will have the chapter heads linked to the contents and vice-versa.

 

Thanks!

 

Eubhal

Robert at ID-Tasker
Legend
May 28, 2024
quote

Hi! I need it in order to have a script that inserts text anchors so I can link to them later in the document so that an epub converted from the file will have the chapter heads linked to the contents and vice-versa.


By @EubhaLiath

 

You mean Table Of Contents? "Links" will be created automatically. 

 

For everything else - Bookmarks, Hyperlinks and Cross-References should be used. 

 

brian_p_dts
Community Expert
Community Expert
May 24, 2024

Yes you can. Roughly speaking without seeing what you've tried, assuming you've found the paragraph:

var tf = someParagraph.insertionPoints[0].textFrames.add();

 

Then If you want the (layer) name of the anchor to be be what's on the line: 

tf.name = somePara.contents;

 

If you want that anchor to contain the text of that line, use tf.contents = somePara.contents;

 

If you also have the take into account fitting and styling the anchor. I'd recommend using object styles since you can set anchor settings with one. Then you'd do: 

tf.applyObjectStyle("somestylename");

Known Participant
May 28, 2024

This is great, I'm so glad it's possible! I'm afraid I tried to use this in a script and it's just beyond my current level of coding (I'm a novice, I'm afraid). If you have the time, could you possibly write out the script as a whole? I'm sorry to ask! 

 

Many thanks for your reply!

 

Eubhal

brian_p_dts
Community Expert
Community Expert
May 28, 2024

...I'm trying to write a script...

 

So did you try writing a script? Do you want to learn how? This is a good project to start on. I'm too busy I'm afraid.