Dear experts,
In continuation of "How to define the offset for a textrange (after a TAB)?" i have implemented the snippet into the existing script-flow (simplefied for the presentation here):
- Read an RTF which contains two parts of tabbed paragraphs. See the file FM-biblio-collected-test.fm
- Reading pgfs in the first part works perfectly. These all start with [[ (script lines 10 ... 26)
- The first pgf of the second part is already read, terminating the first While loop
- Now I take this paragraph (and next ones) and want to handle it as in the previous post (script lines 27 ... 35)
- It turns out that this part of the script does not act on the second part of the file. Function GetTabRange does not get the start of a paragraph, hence issues the error message from line 43.
Why does line 29 not get the same paragraph object as it was handled correctly in the previous While as last object?
// Have the expanded RTF file (FM-biblio-collected-test.fm) open #target framemaker var goRtfDoc = app.ActiveDoc; var pgf = goRtfDoc.MainFlowInDoc.FirstTextFrameInFlow.FirstPgf; // get first pgf in flow var TAB = String.fromCharCode(8); // FM has wrong ASCI for TAB var tabRange // --- read the temp/formatted citations --- "formatted" consist of the reference number only while (pgf.ObjectValid()) { pgfText = GetText (pgf, goRtfDoc); if (pgfText.substring (0,2) === "[[") { // citation lines start with [[ parts = pgfText.split(TAB); // get the two parts of the line parts[0] = parts[0].replace("[[", "{"); // replace [[...]] by {...} for find in user doc parts[0] = parts[0].replace("]]", "}"); if (parts[1].substring (0,1) === "{") { // this placeholder is unresolved, skip it nUnres += 1; pgf = pgf.NextPgfInFlow; continue; } // gasFmtCitsRaw.push (parts[0]); // store the placeholder citation // gasFmtCitsFmt.push (parts[1]); // store the formatted citation (just a number) pgf = pgf.NextPgfInFlow; } else { break } // first line of bibliography encountered } // --- read the bibliography paragraphs while (pgf.ObjectValid()) { // until end of doc tabRange = GetTabRange (pgf, goRtfDoc); // Get the text range starting after the TAB to the end of the paragraph. // gaoBibliography.push(tabRange); // store the paragraph-part in the array goRtfDoc.TextSelection = tabRange; // for later use in tests goRtfDoc.Copy (0); // Check manually what can be copied alert ("are we OK?"); pgf = pgf.NextPgfInFlow; } function GetTabRange (pgf, doc) { var textLoc, textRange, findParams, tabRange; textLoc = new TextLoc (pgf, 0); // Make a text location at the beginning of the paragraph. findParams = GetFindParams ("\x08"); // Get the find parameters for finding a tab. textRange = doc.Find (textLoc, findParams); // Search for the string. if (textRange.beg.obj.ObjectValid ()) { // See if the tab was found. alert (textRange.beg.obj.Unique + " " + pgf.Unique); //?? Is <> if cursor is not at start of pgf. if (textRange.beg.obj.Unique === pgf.Unique) {// Make sure the tab is in the correct paragraph. // Select the text from after the tab up to the end of the paragraph. tabRange = new TextRange (new TextLoc (pgf, textRange.beg.offset+1), new TextLoc (pgf, Constants.FV_OBJ_END_OFFSET - 1)); return tabRange; // Return the text range. } } return 0; // TAB Not found } function GetFindParams (string) { var findParams = AllocatePropVals (1); findParams[0].propIdent.num = Constants.FS_FindText; findParams[0].propVal.valType = Constants.FT_String; findParams[0].propVal.sval = string; return findParams; } // --- end of GetFindParams function GetText (textObj, doc) { var j, text = "", textItems; if (textObj.constructor.name !== "TextRange") { // Get a list of the strings in the text object or text range var textItems = textObj.GetText(Constants.FTI_String); } else { textItems = doc.GetTextForRange(textObj, Constants.FTI_String); } for (var j = 0; j < textItems.len; j += 1) { // Concatenate the strings text += (textItems[j].sdata); } return text; // Return the text } // --- end GetText
Any ideas are welcome
Klaus Daube