Importing FM doc fails miserably
Dear friends,
I try to import an FM file (or later also a txt file) to a text location (current location).
I tried the properties now commented out in the following script, but even with the default import parameters the import does not work. ESTK wheels until i stop it...
► Can you spot my fault?
/* Test_ImportDoc.jsx ====== UTF-8 ======================================
Import a document or text
History 2023-04-18
*/ ; // =================================================================
#target framemaker
main();
function main() { // ====================================================
var oDoc = app.ActiveDoc;
// have text location defined by cursor placement
ImportDoc (oDoc, "E:/_DDDprojects/FM-Graphics/FMgraph-examples/insets/legend.fm");
//ImportDoc (oTL, "insets/legend.fm");
//ImportDoc (oTL, "insets/legend.txt");
} // -- end main --------------------------------------------------------
function ImportDoc (oDoc, sFile) { // ===================================
var oTF, bFmImport, lastBSlash, lastDot,
j, oPgf, oTL, oImpParms={}, oRetParms={}, sFullPath;
oTL = oDoc.TextSelection.beg;
if (sFile.toLowerCase().lastIndexOf("fm") < 0 &&
sFile.toLowerCase().lastIndexOf("mif") < 0 &&
sFile.toLowerCase().lastIndexOf("txt") < 0) {
alert ("File to be inserted is not of type fm, mif or txt.");
return false;
}
if (sFile.indexOf (":") !== -1) { // already full path
sFullPath = sFile;
} else {
lastBSlash = $.fileName.lastIndexOf("/");
sFullPath = $.fileName.substring(0, lastBSlash) + "/" + sFile;
}
// ---------------------------------------------- importing what? -------
bFmImport = (sFullPath.toLowerCase().lastIndexOf("fm") > 0 ||
sFullPath.toLowerCase().lastIndexOf("mif") > 0 );
// ---------------------------------------------- handle import ---------
oImpParms = GetImportDefaultParams();
$.bp(true);
/*
if (bFmImport) { // fm and mif
j = GetPropIndex(oImpParms, Constants.FS_HowToImport);
oImpParms[j].propVal.ival = Constants.FV_DoByRef; // FO_TiFlow
j = GetPropIndex(oImpParms, Constants.FS_ImportAsType);
oImpParms[j].propVal.ival = Constants.FV_AUTORECOGNIZE; // FM, MIF
j = GetPropIndex(oImpParms, Constants.FS_FormatImportedText);
oImpParms[j].propVal.ival = Constants.FV_EnclosingDoc; // container
} else { // txt
j = GetPropIndex(oImpParms, Constants.FS_HowToImport);
oImpParms[j].propVal.ival = Constants.FV_DoByRef; // FO_TiText
j = GetPropIndex(oImpParms, Constants.FS_ImportAsType);
oImpParms[j].propVal.ival = Constants.FV_AUTORECOGNIZE; // TYPE_TEXT
j = GetPropIndex(oImpParms, Constants.FS_FileIsText);
oImpParms[j].propVal.ival = Constants.FV_TextFile_EOLisEOP; // EOL ►
}
*/
//oRetParms = null;
oDoc.Import (oTL, sFullPath, oImpParms, oRetParms); // ESTK wheels
alert ("FA_errno: " + FA_errno);
} //-- end ImportDoc --------------------------------------------------


