Skip to main content
Participating Frequently
March 7, 2019
Answered

Frame maker 13 scripting question

  • March 7, 2019
  • 2 replies
  • 3780 views

Hello,

I am using the following script to convert fm/mif files in a folder to PDF. The script fails in 2 places. I am using FM 13.

saveMultFilesTpPDF();

function saveMultFilesTpPDF() {

    var stop = false; 

    while( stop==false ) { 

        // Wait for 20.000 ms 

        //$.sleep(20000); 

        var fld = new Folder("c:/incoming"); 

        var filesInFld = fld.getFiles("*.fm"); 

        for(var f=0; f < filesInFld.length; f++) { 

            // process the individual file 

            $.writeln(filesInFld);

            saveDocToPdf (filesInFld, "High Quality Print"); 

        } 

        // Exit the  loop after 19:00 

        var time = new Date(); 

        if( time.getHours() > 19 ) stop = true; 

    }  

}

function saveDocToPdf (doc, jobOption) {    

    

    var params, returnParams, saveName, i; 

    // Set the PDF Job Option for the document.

        doc.PDFJobOption = jobOption; 

    // Replace the .fm extension with .pdf. 

  // Exceution fails on line below with "undefined is not an object"

    saveName = doc.Name.replace (/\.[^\.\\]+$/,".pdf"); 

    // Get the save parameters and set the file type to PDF> 

    params = GetSaveDefaultParams(); 

    returnParams = new PropVals(); 

    i = GetPropIndex (params, Constants.FS_FileType); 

    params.propVal.ival =Constants.FV_SaveFmtPdf; 

 

    // Call the document's Save method.   The script fails with

     // Exceution fails on line below with "is not a function"

    doc.Save(saveName, params, returnParams); 

}

This topic has been closed for replies.
Correct answer frameexpert

Now, my problem is not converting the document. With your help I was able to convert fm to PDF. I have a bunch of fm/mif documents in a folder. When I am using var fld = new Folder("c:/incoming");, it reads the folder as "/c/incoming", do you know of any script command to manipulate an string?


I am not sure what you mean, but if you want the system version of the folder's path, you use fld.fsName.

2 replies

kamranbAuthor
Participating Frequently
March 8, 2019

Just one quick question, whenever I am trying to convert files with fm extention, the files should be opened in Framemaker,

otherwise,

doc = Open(fileName, openParams, openReturnParams);

returns invalid object to doc.

However for files with mif extension, there no need for the files to be opened in Framemaker.

How can I convert fm files without having them opened in Framemaker?

4everJang
Legend
March 8, 2019

You cannot. .fm files are stored in a binary format that is optimized for FrameMaker.

4everJang
Legend
March 7, 2019

You are not opening the files at all. Your saveDocToPdf function is called with a File object, not an opened FrameMaker document.

kamranbAuthor
Participating Frequently
March 7, 2019

Thanks. Do you what function with what parameter should I use? OpenDoc?

Please note that the script fails at

saveName = doc.Name.replace (/\.[^\.\\]+$/,".pdf");

Before even reaching

doc.Save(saveName, params, returnParams);

4everJang
Legend
March 7, 2019

Your save action fails because you do not have the required Doc object.

A File object is not a Doc object. A file is just something on your disk. After FrameMaker has opened the file succesfully, it is a document object - with all its properties and methods. The Name property is one of those - that is the one that is marked as 'undefined' by your script.

Sesrch for GetOpenDefaultParams in the Scripting Guide. Similar to GetSaveDefaultParams.