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 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");
- The marker type
- The marker text
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");
Hi Debra,
ReplyDeletethank 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
Hi Andreas,
ReplyDeleteI 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.
Debra
Hi Andreas,
ReplyDeleteA 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.
Debra
Hi again,
ReplyDeleteI have posted a correction in a new post dated Jan 27, 2012. Thanks for Andreas for finding this error.
Where can I find the corrected script. I'm trying to use it for cross-refs as well.
DeleteThanks.
Michael
Nevermind my last post. I found it. :)
DeleteThanks a lot.
Michael