Tuesday, November 15, 2011

Creating an Index Marker

Markers are an instance of anchored objects. As anchored objects they are tied to a text location. Creating a marker means specifying a paragraph and an offset from the start of that paragraph. You also need to provide the same information a user might when creating such a marker. That means you must specify:
  • The marker type
  • The marker text
Use the same type name as appears in the user interface in the Marker Type pop-up menu. The marker text must also mirror that a user would enter.

The example below creates an index marker at the start of the first paragraph in the main flow.

var doc = app.ActiveDoc;
var flow = doc.MainFlowInDoc;
var tFrame = flow.FirstTextFrameInFlow;
var pgf = tFrame.FirstPgf;

function createMarker(doc, pgf, offset, type, text) {
    var tLoc, marker;
    tLoc = new TextLoc(pgf, offset);
    marker = doc.NewAnchoredObject(Constants.FO_Marker, tLoc);
    marker.MarkerType = type;
    marker.MarkerText = text;
    return 1;

createMarker(doc, pgf, 0, "Index", "animal:aardvark");


  1. Hi Debra,

    thank you very much for your very helpful blog.

    Did you ever try to insert another marker type than "Index", e.g. "Crossref"? I'm not sure, whether the line marker.MarkerType = "Index" is correct.

    I want to insert some Crossref markers in my documents and I cannot find the right way - my markers are always of type "Index", no matter which "type" I use.

    Best Regards, Andreas

  2. Hi Andreas,

    I believe I made a mistake in this solution and got lucky as I chose Index Marker. I am working on a corrected solution. Stay tuned.


  3. Hi Andreas,

    A some point the architecture for Frame markers changed to allow for user defined marker types. When I wrote this code, I forgot about the change. I am posting a new blog entry with the right code example.


  4. Hi again,

    I have posted a correction in a new post dated Jan 27, 2012. Thanks for Andreas for finding this error.

    1. Where can I find the corrected script. I'm trying to use it for cross-refs as well.

    2. Nevermind my last post. I found it. :)

      Thanks a lot.