Skip to main content
Participant
April 3, 2014
Answered

Error while loading an XML document using a structured application

  • April 3, 2014
  • 3 replies
  • 1097 views

Hi,

I try to load an XML document using a structured application defined in the default structapps.fm

My code is shown down, extracted from the FDK API code sample.

Problem, I always have the same message :

"Cannot find the file named e:\xml\AdobeFrameMaker10\file. Make sure that the file exists. "

Where "e:\xml\AdobeFrameMaker10\" is my install directory.

So I assume that frame try to find the structapps.fm file but does not find it.

What else can it be ?

Does anyone knowns how to achieve this simple task using extendScript ?

Thanks for any comments, Pierre

function openXMLFile(myLastFile) {

    var filename = myLastFile.openDlg("Choose XML file ...", "*.xml", false);

    if (filename != null) {

       

 

        /* Get default open properties. Return if it can’t be allocated. */

        var params = GetOpenDefaultParams();

       

       

        /* Set properties to open an XML document*/

       

        /*Specify XML as file type to open*/

        var i = GetPropIndex(params, Constants.FS_OpenAsType)

        params.propVal.ival = Constants.FV_TYPE_XML;

       

       

        /* Specify the XML application to be used when opening the document.*/

        i = GetPropIndex(params, Constants.FS_StructuredOpenApplication)

        params.propVal.sval = "myApp";

       

       

        i = GetPropIndex(params, Constants.FS_FileIsOldVersion)

       

        params.propVal.ival = Constants.FV_DoOK

       

        i = GetPropIndex(params, Constants.FS_FontNotFoundInDoc)

       

        params.propVal.ival = Constants.FV_DoOK

       

        i = GetPropIndex(params, Constants.FS_FileIsInUse)

       

        params.propVal.ival = Constants.FV_DoCancel

       

        i = GetPropIndex(params, Constants.FS_AlertUserAboutFailure)

       

        params.propVal.ival = Constants.FV_DoCancel

       

        /*The structapps.fm file containing the specified application must have

        already been read. The default structapps.fm file is read when FrameMaker is

        opened so this shouldn't be a problem if the application to be used is

        listed in the structapps.fm file.*/

       

        var retParm = new PropVals()

        var fileObj = Open(filename, params, retParm);

        return fileObj

    } else {

        return null;

    }

}

This topic has been closed for replies.
Correct answer 4everJang

Pierre,

Depending on the object "myLastFile", the method openDlg might not even exist (if the myLastFile object is not a File object, for instance). And I do not see any need for the myLastFile anyhow, as you are presenting a dialog to select a file to open. I recommend using the global ChooseFile( ) method instead. This will give you a filename as string in full path notation, or null when no file was selected in the dialog. I am not sure what your ExtendScript documentation states about the return value for ChooseFile, but if that differs from what I am telling you here, the documentation is wrong. So, if you replace the first lines of your code with the following it should work:

function openXMLFile ( ) {

    var filename = ChooseFile ( "Choose XML file ...", "", "*.xml", Constants.FV_ChooseSelect );

While writing this, I see that Russ has already given you the same advice. Use the symbolic constant value I indicated to use the ChooseFile dialog to select a single file (it can also be used to select a directory or open a file - but you want to control the opening process yourself). Note that this method allows you to set a start directory for the dialog (second parameter). The ESTK autocompletion also gives you a fifth parameter "helplink" which is undocumented and can safely be ignored.

Good luck

Jang

3 replies

4everJang
4everJangCorrect answer
Legend
April 4, 2014

Pierre,

Depending on the object "myLastFile", the method openDlg might not even exist (if the myLastFile object is not a File object, for instance). And I do not see any need for the myLastFile anyhow, as you are presenting a dialog to select a file to open. I recommend using the global ChooseFile( ) method instead. This will give you a filename as string in full path notation, or null when no file was selected in the dialog. I am not sure what your ExtendScript documentation states about the return value for ChooseFile, but if that differs from what I am telling you here, the documentation is wrong. So, if you replace the first lines of your code with the following it should work:

function openXMLFile ( ) {

    var filename = ChooseFile ( "Choose XML file ...", "", "*.xml", Constants.FV_ChooseSelect );

While writing this, I see that Russ has already given you the same advice. Use the symbolic constant value I indicated to use the ChooseFile dialog to select a single file (it can also be used to select a directory or open a file - but you want to control the opening process yourself). Note that this method allows you to set a start directory for the dialog (second parameter). The ESTK autocompletion also gives you a fifth parameter "helplink" which is undocumented and can safely be ignored.

Good luck

Jang

frameexpert
Community Expert
Community Expert
April 4, 2014

Hi Pierre, The openDlg method returns an ExtendScript File object, not a string. When you do this:

var fileObj = Open(filename, params, retParm);

filename is a File object instead of a string. You need this instead to get the full path as a string:

var fileObj = Open(filename.fsName, params, retParm);

Or, Russ's method should work as well.

-Rick

www.frameexpert.com
pierattAuthor
Participant
April 4, 2014

Hi Russ, Hi Rick, Hi Jang,

Thanks for taking time on my problem.

You were right : filename was a File object, not a string ... that was the sole problem.

Thanks for your answer, it now works.

Legend
April 4, 2014

Hi,

My guess is that the script can't find the file you want to open, not that it can't find structapps.fm. One question... what is this?

var filename = myLastFile.openDlg("Choose XML file ...", "*.xml", false);

Did you define this yourself? Have you tested 'filename' after the call?  Try something like this afterwards to see what FrameMaker is actually trying to open:

alert(filename);

Russ

Legend
April 4, 2014

Postscript... I realize now that openDlg() might be some core javascript method that I'm not familiar with, although I can't find much about it. In any case, see what filename equals afterwards. If it equals nothing, that is your problem. Consider using the FM ExtendScript method instead:

ChooseFile(title, directory, stuffVal, mode)

Russ