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

Problems opening network file from script.

Contributor ,
May 30, 2023 May 30, 2023

Copy link to clipboard

Copied

I have a simple script to open a file from the network and import master pages using portions of Russ Ward and Klaus Daube's code:

 

function ImportMasterPages(doc)
{
var sFullPath = "\\\\Network Name\\Document_Template.fm"
    var Doc_Template = SimpleOpen(sFullPath, "");
    //If we successfully opened the file, let's report it.
    if(Doc_Template.ObjectValid() == true)
    {
 //       alert("Successfully opened the file:\n\n" + TCTO_Template.Name);
    }
    //Otherwise, report the failure.
    else
    {
        alert("Couldn't open the file! Check to see if it is an FM document " +
            "and if somebody is already using it. The selected path was:\n\n" + sFullPath);
    }
Doc_Template.ShowAll = true;
var formatFlags = Constants.FF_UFF_PAGE;
doc.SimpleImportFormats (Doc_Template, formatFlags);
Doc_Template.Close(Constants.FF_CLOSE_MODIFIED)
 return;
} // -- end ImportMasterPages

 

Usually it works. Sometimes it gives us the "Could not open file ..." error. There doesn't seem to be a locking handle when it fails.

I tried deleting and replacing the template on the network and that usually fixes it for a while.

I'm going to try changing "==" to "===" on the Objectvalide line, but does anybody see anything else that might cause this?

TOPICS
Scripting

Views

269

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 ,
May 30, 2023 May 30, 2023

Copy link to clipboard

Copied

Script ALWAYS errors with "===" on the objectvalid line - usually works otherwise.

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 ,
Jun 07, 2023 Jun 07, 2023

Copy link to clipboard

Copied

Just to clarify: The script was not failing b/c I had "====" and I changed it to "==" and it works now. It was/is working intermittently with "==" and I tried changing that to "===" and that never worked, so I changed it back.

The error is very random. I would suspect network latency or similar, but I've had it work for me over VPN (slow file transfer speeds) and fail for a co-worker over hard-wire Ethernet at about the same time.

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 ,
Jun 07, 2023 Jun 07, 2023

Copy link to clipboard

Copied

Also - when it does work, it works VERY quickly. i.e. I don't even see the file open and close in FM, but my target file is updated. (It's not like I even see a new tab added in FM when the file is opening). So I don't think it is an issue where two people happen to be running the script at the exact same time.

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 ,
Jul 15, 2023 Jul 15, 2023

Copy link to clipboard

Copied

The ObjectValid() method returns a 0 or 1. When you compare ObjectValid() with true or false using a double equals sign, ExtendScript will see 0 as false and 1 as true. However the triple equals sign is a "true equal" test and will require to test for either 0 or 1; true or false will always fail.

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 ,
Jul 15, 2023 Jul 15, 2023

Copy link to clipboard

Copied

I don't know if this will help, but I have a couple of scripts that open documents located on a network drive.  The code I use is bit different, and it works everytime.

var path = "\\\\MyNetwork_Name\\Documents\\";   
var doc_Title = "Table 22. Word Class.fm"     
     doc = SimpleOpen(path + doc_Title);        
     if(doc.ObjectValid() == false) {  // If unable to open the hitlist, report it
        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);
     }  

I only test for an invalid object.  If it's valid, I have a subsequent line that lists the document title to the console.  Network I work with has latency issues, but may not be as bad as yours.

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 ,
Jul 17, 2023 Jul 17, 2023

Copy link to clipboard

Copied

@Fightergator I'll give it a shot, although I don't see much difference in the code (but it might not take much).  As I read it, essentially you just split the doc title from the path and you are testing for object valid = false whereas I am testing for object valid = false, else - but those might be enough.

Two things:

- It's an intermittent failure, so I won't know immediately if it works or fails.

- I'm not sure it's latency related, as the script has worked for me remotely and failed for others on a hard-wire connection, but that might not mean anything either.

 

Thanks for the assistance, I'll report results.

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
Enthusiast ,
Jul 17, 2023 Jul 17, 2023

Copy link to clipboard

Copied

The problem is the FrameMaker file.

If you open it "manually", are there any error messages? if so, try to get rid of them.

- Missing graphics, missing "anything", older version.....

 

Then it should work.

So you should use simpleopen only, if you are SURE, that the file is OK. Otherwise use "open"

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 ,
Jul 17, 2023 Jul 17, 2023

Copy link to clipboard

Copied

@Klaus Göbel - Thanks! No issues opening the file normally - in fact, simpleOpen works maybe 3/4 of the time with ESTK.

I'll try the script with FighterGator's comments and just "open" and report results, though!

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 ,
Jul 17, 2023 Jul 17, 2023

Copy link to clipboard

Copied

A SimpleOpen can fail for various reasons, depending on the document. There may be missing graphics, missing fonts, unresolved cross-references, etc. in the document that will cause it to fail. You should use Open instead, because you can set parameters that will ignore missing graphics, etc. and still open the document. Here is a function you can use:

 

function openDocOrBook (filename, visible) {

    var i = 0, docOrBook = 0;

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

    // Set specific open property values to open the document.
    // Ignore open warnings.
    i = GetPropIndex (openProps, Constants.FS_AlertUserAboutFailure);
    openProps[i].propVal.ival = false;
    // Make the document visible, depending on the true/false value.
    i = GetPropIndex (openProps, Constants.FS_MakeVisible);
    openProps[i].propVal.ival = visible;
    // Open older version without warning.
    i = GetPropIndex (openProps, Constants.FS_FileIsOldVersion);
    openProps[i].propVal.ival = Constants.FV_DoOK;
    // Reset locked files.
    i = GetPropIndex (openProps, Constants.FS_FileIsInUse);
    openProps[i].propVal.ival = Constants.FV_ResetLockAndContinue;
    i = GetPropIndex (openProps, Constants.FS_OpenFileNotWritable);
    openProps[i].propVal.ival = Constants.FV_DoOK;
    // Ignore font problems.
    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;
    // Ignore missing graphics and unresolved cross-references.
    i = GetPropIndex (openProps, Constants.FS_RefFileNotFound);
    openProps[i].propVal.ival = Constants.FV_AllowAllRefFilesUnFindable;

    // 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 ,
Jul 17, 2023 Jul 17, 2023

Copy link to clipboard

Copied

LATEST

I updated the script using @frameexpert 's openDocOrBook function. It worked, but it worked sometimes previously. Too early to declare victory, but hopefully the issue is solved.

Thanks to all for the assistance.

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