• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Text Range not working as expected

Community Expert ,
Aug 25, 2021 Aug 25, 2021

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

 

 

TOPICS
Scripting

Views

162

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Aug 27, 2021 Aug 27, 2021

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
...

Votes

Translate

Translate
Community Expert ,
Aug 26, 2021 Aug 26, 2021

Copy link to clipboard

Copied

It turns out that...

  • The auto number can not be selected (neither with the UI, nor with the Text Range)
  • There is no pgf property PgfNumString, although it exists in MIF
  • There is no Constants.FTI_xxx to get the autonumber by means of GetTextForRange

So for t he time being I'm at the wall...

Edit

  • I'm currently developing a function along these lines
  • Creante new document (portrait
  • Modify the first paragraph to Autonumbering with, for example <Indic n=1234>
  • ave the document as z-miftour.fm
  • Save the document as ...mif
  • Read from the MIF file the line containing "<PgfNumString `١٢٣٤'>"
  • Extract what is need for further processing (١٢٣٤)
  • Delete both the fm and the mif file
  • Return the extracted value

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Aug 27, 2021 Aug 27, 2021

Copy link to clipboard

Copied

LATEST

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines