Highlighted

Frame maker 13 scripting question

Community Beginner ,
Mar 07, 2019

Copy link to clipboard

Copied

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); 

}

Adobe Community Professional
Correct answer by frameexpert | Adobe Community Professional

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

TOPICS
Scripting

Views

2.4K

Likes

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

Frame maker 13 scripting question

Community Beginner ,
Mar 07, 2019

Copy link to clipboard

Copied

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); 

}

Adobe Community Professional
Correct answer by frameexpert | Adobe Community Professional

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

TOPICS
Scripting

Views

2.4K

Likes

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
Mar 07, 2019 0
Advocate ,
Mar 07, 2019

Copy link to clipboard

Copied

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

Likes

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
Reply
Loading...
Mar 07, 2019 0
Community Beginner ,
Mar 07, 2019

Copy link to clipboard

Copied

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);

Likes

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
Reply
Loading...
Mar 07, 2019 0
Advocate ,
Mar 07, 2019

Copy link to clipboard

Copied

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.

Likes

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
Reply
Loading...
Mar 07, 2019 0
Community Beginner ,
Mar 07, 2019

Copy link to clipboard

Copied

I did change the function to

function saveDocToPdf (doc, jobOption) {

    var params, returnParams, saveName, i, openName;

    openName = doc;

    // Get required parameters for the save function.

    params = GetSaveDefaultParams();

    returnParamsp = new PropVals();

    openparams = GetOpenDefaultParams();

    returnOpenParamsp = new PropVals();

    doc.Open(openName, openparams, returnOpenParamsp);

      .

      .

But it still fails upon calling Open , complaining that doc.Open is not a function.

Likes

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
Reply
Loading...
Mar 07, 2019 0
Advocate ,
Mar 07, 2019

Copy link to clipboard

Copied

Open is not a function of the Doc object. It is a global function. The reason is that before calling Open( ) there is no Doc object.

Also, Open( ) is not a function you call INSIDE the Save function. You first call the Open function, then check if you have a valid Doc object, then use the Save function for that Doc object.

Always insert code to check if you objects exist, if they are valid etc. Scripting is 10% design and 90% avoiding errors that might occur. After calling Open( ) check if the returned object is valid. If it is, proceed to the next step.

Likes

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
Reply
Loading...
Mar 07, 2019 0
Community Beginner ,
Mar 07, 2019

Copy link to clipboard

Copied

OK, Now I changed it to

doc = Open(fileName, openParams, openReturnParams);

But the doc

is shown as [objectInvalidObject], when I am executing the line above while debugging the script.

Likes

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
Reply
Loading...
Mar 07, 2019 0
Adobe Community Professional ,
Mar 07, 2019

Copy link to clipboard

Copied

Right, because you haven't provided any open or return parameters. I don't want to be unkind, but you are kind of taking a lazy approach to your task. First of all, your post title is very general. What you are trying to learn is how to open a FrameMaker document with ExtendScript. You found out that the global method is Open. Now you have to find out how the Open method works. I would suggest that you do a little research on that; there should be some code on this forum that you can use. Opening FrameMaker documents with ExtendScript is a pretty common task. If you still have trouble, post a new thread that specifically asks about opening FrameMaker documents.

Also, you posted code that does more than one thing. A better approach is to break your overall task into smaller tasks and solve those first. It's evident that you know how to grab a bunch of FrameMaker files and loop through them. However, you don't know how to open a single FrameMaker file, so start with that. Then figure out how to save a single FrameMaker document to PDF. Once you are successful with the small tasks on single files, then you can put everything together in a single script.

Likes

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
Reply
Loading...
Mar 07, 2019 0
Community Beginner ,
Mar 07, 2019

Copy link to clipboard

Copied

I was able to open and save the document as PDF. My issue is the path that was returned by "var fld = new Folder("c:/incoming");"

after execution of this line, fld gets the value "/c/incoming" that is not understood by Open function. I hard coded the path and file name and I was able to save the file as PDF. Thanks.

Now, I am trying to figure how to correct the file and path name from "/c/incoming/file.fm" to "c:/incoming/file.fm".

Likes

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
Reply
Loading...
Mar 07, 2019 0
Adobe Community Professional ,
Mar 07, 2019

Copy link to clipboard

Copied

It is in the ExtendScript Toolkit documentation. When you have a File object, you need to pass this to the Open method: file.fsName.

Likes

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
Reply
Loading...
Mar 07, 2019 0
Community Beginner ,
Mar 08, 2019

Copy link to clipboard

Copied

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?

Likes

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
Reply
Loading...
Mar 08, 2019 0
Adobe Community Professional ,
Mar 08, 2019

Copy link to clipboard

Copied

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

Likes

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
Reply
Loading...
Mar 08, 2019 1
Community Beginner ,
Mar 08, 2019

Copy link to clipboard

Copied

Thank you. Now my script is working and I can convert all .mif and .fm files in folder to PDF.

Likes

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
Reply
Loading...
Mar 08, 2019 0
Community Beginner ,
Mar 08, 2019

Copy link to clipboard

Copied

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?

Likes

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
Reply
Loading...
Mar 08, 2019 0
Advocate ,
Mar 08, 2019

Copy link to clipboard

Copied

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

Likes

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
Reply
Loading...
Mar 08, 2019 2