Hi guys,
I'd like the script to check whether the file from which all formats are imported is an appendix file (the 1st heading is of type "1 Heading Appendix"). So, I modified the script as follows:
...
var openRegFM = Open(regFileName, openParams, openReturnParams);
openRegFM.GetNamedPgfFmt = "1 Heading Appendix";
if ((openRegFM.ObjectValid () == 1) && (openRegFM.FirstPgfFmtInDoc == "1 Heading Appendix")) {
opendoc.SimpleImportFormats(openRegFM, Constants.FF_UFF_COND|Constants.FF_UFF_FONT|Constants.FF_UFF_PAGE |Constants.FF_UFF_PGF|Constants.FF_UFF_REFPAGE|Constants.FF_UFF_TABLE|Constants.FF_UFF_VAR|Constants.FF_UFF_XREF);
}
...
However, for some reason that is unclear to me, this doesn't work. There are no errors produced, but the script seems to ignore the "if" part.
Any suggestions?
Thank you!
Hi Roman,
You are checking whether a paragraph format exists, not whether the first paragraph in the document has that format applied. If you are using the same template for all files, all files will have the same paragraph formats, hence the "if" to check whether the paragraph format exists will always yield 'true'. And when you check whether that paragraph format is the first format in the file, it will likely produce 'false', as it would be a strange coincidence if that paragraph format would be the first one in the list.
What you need to do to check the format of the first paragraph in the file is the following (I have made it into a function that can be used with any first paragraph format you might be looking for).
function CheckFirstParagraphFormat( oDoc, sFormat )
{
var oFlow = oDoc.MainFlowInDoc;
var oFrame = oFlow.FirstTextFrameInFlow;
var oPgf = oFrame.FirstPgf;
if( oPgf.Name == sFormat )
return true;
else
return false;
}
The Name of the Pgf object is the name of the format that was applied to it.
Good luck
Jang