Need help with applying hypertext markers with specific commands to paragraphs
Hi all. I'm new here and new to scripting. Been reading a lot and watching some videos but it still hasn't quite clicked. I'm am trying to write a script that will apply a hypertext marker to a specific paragraph format, and customize each marker with a specific newlink command based on the contents of the paragraph. For example, the following paragraph, which has the format CaptionFigure, would need a hypertext marker called newlink f3 to correspond with Figure F3:
Figure F3. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec non pretiu
Figure F4 will have newlink f4, Figure F5 will have newlink f5, and so on.
There are sometimes up to 50 or 60 figures in a document, thus I’m looking to streamline it with ExtendScript. I found this code to apply a marker to a paragraph format in the forum (thanks mrsjackharkness) and modified it, and it works great. Now I need help with the next step, to customize the marker.
var doc = app.ActiveDoc;
var flow = doc.MainFlowInDoc;
var tframe = flow.FirstTextFrameInFlow;
var pgf = tframe.FirstPgf;
var target1 = doc.GetNamedObject(Constants.FO_PgfFmt, "CaptionFigure");
var target2 = doc.GetNamedObject(Constants.FO_PgfFmt, "CaptionTable");
while (pgf.ObjectValid()) {
if (pgf.Name == target1.Name) {
createMarker (doc, pgf, 0, "Hypertext", "Newlink f");
}
else if (pgf.Name == target2.Name) {
createMarker (doc, pgf, 0, "Hypertext", "Newlink t");
}
pgf = pgf.NextPgfInDoc;
}
function createMarker(doc, pgf, offset, type, text) {
var tLoc = new TextLoc(pgf, offset);
var marker = doc.NewAnchoredObject(Constants.FO_Marker, tLoc);
var markerType = doc.GetNamedObject(Constants.FO_MarkerType, type);
marker.MarkerTypeId = markerType;
marker.MarkerText = text;
return 1;
}
Any advice will be much appreciated. Please and thank you!
Julie
