Copy link to clipboard
Copied
Dear all,
I want to use the automatic numbering for paragraphs to convert an arbitrary integer into a string. The automatic numbering provides a great range of numbering systems (numeric, roman, ...)
In the following script the text range does not behave - although I have used this method in other scripts with success.
//@target framemaker
var KLD_Z = KLD_Z || {}; // global script object
//@include ..\GetText.jsx
KLD_Z.main = function () { // <><><><><><><><><><><><><><><><><><><><><><>
$.bp(true);
var oDoc = app.ActiveDoc, oTL1, oTL2, oTR, sText, oMasterPage, oTxtFrame,
oPgf, PT = 65536;
oMasterPage = oDoc.FirstMasterPageInDoc; // Add a temporary text frame
oTxtFrame = oDoc.NewTextFrame (oMasterPage.PageFrame);
oTxtFrame.Width = 400 * PT;
oPgf = oTxtFrame.FirstPgf;
oPgf.PgfIsAutoNum = 1; // set the value and the numbering format
//oPgf.AutoNumString = "<Indic n=1234>";
oPgf.AutoNumString = "<r=1234>";
oTL1 = new TextLoc (oPgf, 0);
oTL2 = new TextLoc (oPgf, Constants.FV_OBJ_END_OFFSET - 1); // exclude ¶
oTR = new TextRange (oTL1, oTL2);
oDoc.TextSelection = oTR; // → does not select anything
sText = KLD_Z.GetText (oDoc, oTR); // → empty
oTxtFrame.Delete (); // Delete the temp. text frame
return sText;
} //--- end main --------------------------------------------------------
$.writeln("→ " + KLD_Z.main ()); // → empty
Following my idea with the MIF file I have this script:
KLD_Z.EvalAutoNum = function (sAutoNumFmt, iValue) { // =====================
/* Format an integer according to an auto-numbering format
Arguments sAutoNum Auto-number string to be evaluated, e.g. "Indic n"
iValue Integer to evaluated
Calling ReadDataFile (which uses GetSimpleOpenProps)
History 2021-08-16
*/
var aMifLines = [], index1, index2, j, nLines, oDoc, oFlow, oPage, oPgf, oTFr
...
Copy link to clipboard
Copied
It turns out that...
So for t he time being I'm at the wall...
Edit
Copy link to clipboard
Copied
Following my idea with the MIF file I have this script:
KLD_Z.EvalAutoNum = function (sAutoNumFmt, iValue) { // =====================
/* Format an integer according to an auto-numbering format
Arguments sAutoNum Auto-number string to be evaluated, e.g. "Indic n"
iValue Integer to evaluated
Calling ReadDataFile (which uses GetSimpleOpenProps)
History 2021-08-16
*/
var aMifLines = [], index1, index2, j, nLines, oDoc, oFlow, oPage, oPgf, oTFr,
saveParms, saveRetParms, sFilename, sLine, sTempPath, sText, sValue,
CM = 1857713;
// --- Creante new document and save with name (not visible)
sTempPath = app.TmpDir;
sFilename = sTempPath + "\\z-miftour";
// (w, h, nC, cGap, topM, botM, leftM, rightM, sidedness, makeVisible)
oDoc = CustomDoc(21*CM, 21*CM, 1, 0, 1*CM, 1*CM, 2*CM, 2*CM, 0, false);
saveParms = GetSaveDefaultParams(); // Get the save parameters and set the file type
saveRetParms = new PropVals();
j = GetPropIndex (saveParms, Constants.FS_FileType);
saveParms[j].propVal.ival = Constants.FV_SaveFmtBinary;
oDoc.Save (sFilename + ".fm", saveParms, saveRetParms);
// --- Modify the first paragraph to Autonumbering, e.g. <Indic n=1234>
sValue = "<" + sAutoNumFmt + "=" + iValue + ">";
oPgf = oDoc.MainFlowInDoc.FirstTextFrameInFlow.FirstPgf;
oPgf.PgfIsAutoNum = 1;
oPgf.AutoNumString = sValue;
// --- Save the document as mif
saveRetParms = new PropVals();
j = GetPropIndex (saveParms, Constants.FS_FileType);
saveParms[j].propVal.ival = Constants.FV_SaveFmtInterchange;
oDoc.Save (sFilename + ".mif", saveParms, saveRetParms);
// --- Read MIF file, line containing "<PgfNumString `١٢٣٤'>"
KLD_Z.ReadDataFile (sFilename + ".mif", aMifLines);
nLines = aMifLines.length;
for (j = 0; j < nLines; j++) {
if (aMifLines[j].indexOf("<PgfNumString") <= 0) continue;
sLine = aMifLines[j];
break;
}
// --- Extract what is need for further processing (١٢٣٤)
index1 = sLine.indexOf (" `");
index2 = sLine.indexOf ("'>");
sText = sLine.substring (index1, index2);
// --- Delete both files - not necessary, are overwritten next time
// --- Return the extracted value
return sText;
} //--- end EvalAutoNum -----------------------------------------------------
I have tested it with the formats "r", "indic n" and "kanji n". Of couse the target paragraph requires an appropriate font the last one - for the others TNR is sufficient.