How to Apply Conversion Table to FM file.
I have a conversion table generated for a group of files I am trying to structure. I want to be able to apply the conversion table with Extendscript. The script I have doesn't save any converted file. I am not sure why is it not saving the file. I was under the impression that the "Structure Generator" should create the new file. If this incorrect.
Here is the code I am trying to use.
var myFile = File.openDialog ("Select File to Convert");
var myCT = File.openDialog ("Select ConversionTable");
var CT = openFile (myCT.fsName, 0);
applyConversionTable (myFile.fsName, CT)
closeFile (CT);
function applyConversionTable(fileName, CT){
var doc= openFile (fileName, 0);
var name = fileName.replace(/[\w\.]+$/,"test.fm")
CallClient("Structure Generator", "InputDocId " + doc.id);
CallClient("Structure Generator", "RuleDocId " + CT.id);
CallClient("Structure Generator", "OutputDocName " + name);
CallClient("Structure Generator", "GenerateDoc");
closeFile (doc);
}
function openFile( fileName, visible){
var i = 0;
var doc = 0;
var openParams = GetOpenDefaultParams();
var retParams = new PropVals();
i = GetPropIndex(openParams, Constants.FS_AlertUserAboutFailure);
openParams.propVal.ival = false;
i = GetPropIndex(openParams, Constants.FS_MakeVisible);
openParams.propVal.ival = visible;
i = GetPropIndex(openParams, Constants.FS_FileIsOldVersion);
openParams.propVal.ival = Constants.FV_DoOK;
i = GetPropIndex(openParams, Constants.FS_FileIsInUse);
openParams.propVal.ival = Constants.FV_ResetLockAndContinue;
i = GetPropIndex(openParams, Constants.FS_FontChangedMetric);
openParams.propVal.ival = Constants.FV_DoOK;
i = GetPropIndex(openParams, Constants.FS_FontNotFoundInCatalog);
openParams.propVal.ival = Constants.FV_DoOK;
i = GetPropIndex(openParams, Constants.FS_FontNotFoundInDoc);
openParams.propVal.ival = Constants.FV_DoOK;
i = GetPropIndex(openParams, Constants.FS_RefFileNotFound);
openParams.propVal.ival = Constants.FV_AllowAllRefFilesUnFindable;
doc = Open(fileName, openParams, retParams);
if (doc.ObjectValid() ===1){
doc.openedByScript = true;
}
else{
PrintOpenStatus(retParams);
}
return doc
}
function closeFile(doc){
Constants.FF_CLOSE_MODIFIED = 1;
var res = doc.Close(Constants.FF_CLOSE_MODIFIED);
}
