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

Script Filepath Error in FM 22

Contributor ,
Feb 22, 2024 Feb 22, 2024

Copy link to clipboard

Copied

I have a script written originally in FM 2017 that opens an FM file and loads a list of words from a table.  The script has worked fine in all versions until FM 2022.  When I run the scipt I get an error that says: "Couldn’t open Words Not Spelled Out.fm!  Check to see if it is an FM document and if somebody is already using it.  The selected path was:

\\C:\Editing Tools\FM Hitlists (ver 2.0)\Words Not Spelled Out.fm

 

The code I'm using to open the file is:

var path = “\\\\C:\\Editing Tools\\FM Hitlists (ver 2.0)\\Words Not Spelled Out.fm”

doc = SimpleOpen(path);

 

Title of document I'm trying to open is "Words Not Spelled Out.fm"

 

I tried searching on the topic, but no relavant posts.  Wondering if anyone else has run into this.

Views

263

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 2 Correct answers

Community Expert , Feb 22, 2024 Feb 22, 2024

What happens if you choose File > Open and attempt to open the document manually? Do you get any errors, like missing fonts, graphics, unresolved cross-references, etc.?

Votes

Translate

Translate
Community Expert , Feb 24, 2024 Feb 24, 2024

I would use the Open () method instead of SimpleOpen (). Open allows you to ignore all kinds of things when opening a document or book. If you look through the code, you can see the kinds of issues that it will ignore while still opening the document or book.

 

function openDocOrBook (filename, structuredApplication, visible) {
    
    var openProps, retParm, i, docOrBook;

    // Get default property list for opening documents.
    openProps = GetOpenDefaultParams ();
    // Get a property lis
...

Votes

Translate

Translate
Community Expert ,
Feb 22, 2024 Feb 22, 2024

Copy link to clipboard

Copied

Any chance that spaces in the filepath and/or filename are causing problems?

(something parsing on the spaces)

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
Contributor ,
Feb 23, 2024 Feb 23, 2024

Copy link to clipboard

Copied

I use the same script in FM 2020 on same computer and it works everytime.  The path is exactly the same; spaces and all.  Try to run it in FM 2022 and I get the same error everytime.  

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 ,
Feb 22, 2024 Feb 22, 2024

Copy link to clipboard

Copied

What happens if you choose File > Open and attempt to open the document manually? Do you get any errors, like missing fonts, graphics, unresolved cross-references, etc.?

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
Contributor ,
Feb 23, 2024 Feb 23, 2024

Copy link to clipboard

Copied

Hi Rick...when I open the file manually in FM 2022, it opens just fine.  I even saved the file as a new file from within FM 2022 to see if it might be a file version problem, but get the same error when I try to open it from the script.

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
Contributor ,
Feb 24, 2024 Feb 24, 2024

Copy link to clipboard

Copied

Issue solved.  Files that I try to open from a script in FM22 result in an invalid doc.Object.  I thought I'd converted the file successfully during an earlier test, but most not have.  I'm suspecting the alert I get when I try to manually open a 2020 or older version file, asking if I want to convert the file to the newer format, is causing the error.  Not a problem now that I know why it's happening.  I'll just convert all the documents I load with the script to FM22.  Thanks for tips on things to check.

Here's code snippet:

#target framemaker
// SET UP VARIABLES
var path = "C:\\Users\\fight\\Desktop\\FM Hitlists\\"; 
var HLTitle = "Table 25. Words Not Spelled Out.fm";
//var HLTitle = "Table 25. Words Not Spelled Out(FM22).fm"

loadHitlist();

function loadHitlist() {
    $.writeln("Loading Table 25. Words Not Spelled Out.fm...");
    
    var doc = SimpleOpen(path + HLTitle);
        
        if(doc.ObjectValid() == false) {
            alert("Couldn't open the file! Check to see if it is an FM document " +
            "or if somebody is already using it. The selected path was:\n\n" + path);
        }
}

 

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 ,
Feb 24, 2024 Feb 24, 2024

Copy link to clipboard

Copied

I would use the Open () method instead of SimpleOpen (). Open allows you to ignore all kinds of things when opening a document or book. If you look through the code, you can see the kinds of issues that it will ignore while still opening the document or book.

 

function openDocOrBook (filename, structuredApplication, visible) {
    
    var openProps, retParm, i, docOrBook;

    // Get default property list for opening documents.
    openProps = GetOpenDefaultParams ();
    // Get a property list to return any error messages.
    retParm = new PropVals ();

    // Set specific open property values to open the document.
    i = GetPropIndex (openProps, Constants.FS_AlertUserAboutFailure);
    openProps[i].propVal.ival = false;
    i = GetPropIndex (openProps, Constants.FS_MakeVisible);
    openProps[i].propVal.ival = visible;
    i = GetPropIndex (openProps, Constants.FS_FileIsOldVersion);
    openProps[i].propVal.ival = Constants.FV_DoOK;
    i = GetPropIndex (openProps, Constants.FS_FileIsInUse);
    openProps[i].propVal.ival = Constants.FV_ResetLockAndContinue;
    i = GetPropIndex (openProps, Constants.FS_FontChangedMetric);
    openProps[i].propVal.ival = Constants.FV_DoOK;
    i = GetPropIndex (openProps, Constants.FS_FontNotFoundInCatalog);
    openProps[i].propVal.ival = Constants.FV_DoOK;
    i = GetPropIndex (openProps, Constants.FS_FontNotFoundInDoc);
    openProps[i].propVal.ival  =Constants.FV_DoOK;
    i = GetPropIndex (openProps, Constants.FS_RefFileNotFound);
    openProps[i].propVal.ival = Constants.FV_AllowAllRefFilesUnFindable;
    if (structuredApplication !== undefined) {
        i = GetPropIndex (openProps, Constants.FS_StructuredOpenApplication);
        openProps[i].propVal.sval = structuredApplication;
    }

    // Attempt to open the document.
    docOrBook = Open (filename, openProps, retParm);

    if (docOrBook.ObjectValid () === 1) {
        // Add a property to the document or book, indicating that the script opened it.
        docOrBook.openedByScript = true;
    }
    else {
        // If the document can't be open, print the errors to the Console.
        PrintOpenStatus (retParm);
    }

    return docOrBook; // Return the document  or book object.
}

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
Contributor ,
Feb 26, 2024 Feb 26, 2024

Copy link to clipboard

Copied

LATEST

Thanks Rick...I'll do that.  I remember you sharing this code in the past, but was working on some bigger problems at the time.  I'll incorporate it now. 

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