Quantcast
Channel: Adobe Community : All Content - FrameMaker Scripting
Viewing all 888 articles
Browse latest View live

Script to save FM files as older version

$
0
0

I'm working on some scripts to save FrameMaker books to older Frame and MIF versions. I'm using a framework kindly supplied by Rick Quatro to run through all the documents in a book. When I run the script from FrameMaker 12, I can save to FM 9, 10 and 11, and to MIF 7, so the script works correctly.

 

But when I try to save to MIF 9, 10 or 11 or FM 7, the script fails silently, and my files are not updated.

 

I'm using this code to specify the file format:

saveParams[i].propVal.ival =Constants.FV_SaveFmtBinary70;

    doc.Save(name, saveParams, returnParams);

 

 

According to the Object Model Viewer, the following constants are available for FV_SaveFmt:

FV_SaveFmtInterchange110;

FV_SaveFmtInterchange100;

FV_SaveFmtInterchange90;

 

So it looks like these constants are read-only: I can check if a file currently has this format but I cannot write a file in this format. The Object Model Viewer doesn't say anything about this, though.

 

Am I correct? Is it impossible to save to MIF 9, 10 or 11 or FM 7 from FrameMaker 12? Or am I overlooking something?

 

Harro de Jong


Archive utility does not work in FrameMaker 2015

$
0
0

The Archive utility (a script Adobe created that packages all of a book's files, including images regardless of their source location) does not work in FrameMaker 2015. Is there a new version available? FrameMaker's built-in Package function only pulls in images if they're in the same folder as the book.

Set conditional tag to all table cells including the content

$
0
0

Hi,

I am using FM12, unstructured. I would like to set the entire content of a chapter to a certain conditional text (by selecting all content and setting the condition).

My problem is with tables. This action only sets the table as a frame, but does not set the table cell contents as conditional. Is there a simple way to do this without scripting?

Thanks in advance,

Hani

XML to FrameMaker - FDK API

$
0
0

Do we have any FDK API to convert XML to FrameMaker ? Do we have any alternative solutions?

Calling an ExtendScript script from the command line

$
0
0

Hi! I can call an ExtendScript script from a command line just by using its path, but is there a way to pass parameters to the script? Thanks. -Rick

Has anyone used scripts in FrameMaker 2015?

$
0
0

Hi everyone,

 

We have some relatively complex scripts we use to update books in FrameMaker 10. Now that we are running them on FrameMaker 2015, the results are mixed. We are parsing out each function and doing some testing, but I wanted to check here if anyone has any experience running scripts in FM2015.

 

If we get the issue narrowed down, I will try to share our results here.

 

Thanks for your feedback!!

 

Heather Ayer

Convert an ExtendScript to FDK

$
0
0

Hi All.

 

I have never used FrameMaker until today so this is my first post here. :-)

 

I have combined a file-reading script and Ian Proudfoot's Search and Replace script into a script that reads comma separated values from a file, and then searches the FrameMaker file for the first string in the array and if found replaces that string with the second string in the array. Making it possible to e.g. loop through a list of old product numbers and replacing them with new ones.

 

It does actually work, but the thing is that the people who are going to use this script are still using FrameMaker 9.So I need to convert this script to a FDK script. And i need to inform them how to run this script in FrameMaker 9.

 

So does anyone know if there are any easy ways of converting this ExtendScript to a FDK script to be used in FM9. And could anyone please help me understand how such a script would be run in FrameMaker 9?

 

Here's "my" script:

 

//initializing variables

var activeDoc = app.ActiveDoc;

var flow = activeDoc.MainFlowInDoc;

var findString = '';

var replaceString = '';

var considerCase = 0;

 

 

// telling FrameMaker which file to open

var csvFile = File.openDialog('Select a CSV File','comma-separated-values(*.csv):*.csv;'); 

 

 

if (csvFile != null)

{

    sarArray = readInCSV(csvFile);  //read the file into the Search And Replace (sar) array using the readInCSV function

}

 

 

for (var i=0, len=sarArray.length; i < len; i++) { //loop through the array and do a search and replace for each collection of elements in the array

    findString = sarArray[i][0];  //the find string is the first element in the current collection

    replaceString = sarArray[i][1] //the replace string is the second element in the current collection

    FindAndReplaceString(activeDoc, flow, findString, replaceString, considerCase)  //the actual search and replace routine

}

 

 

 

 

function readInCSV(fileObj)

{

     var sarArray = new Array(); //creating the array

     fileObj.open('r');  //open the file for reading

     fileObj.seek(0, 0);  //go to the beginning of the file

     while(!fileObj.eof)  //as long as end of file has not been reached

     {

          var thisLine = fileObj.readln(); //read each line

          var csvArray = thisLine.split(';'); //split the line in two at the ; character

          sarArray.push(csvArray); //insert each value into the array

     }

     fileObj.close();  //close the file

     return sarArray; //and return an array full of search and replace strings

}

 

 

function FindAndReplaceString(activeDoc, flow, findString, replaceString, considerCase) {

    var tr = new TextRange();

    var restoreTR, frame = 0;

    var loopCounter = 0, replacementCounter = 0;

    var findParams = new PropVals();

 

 

    //if the flow object is not valid, assume the main flow

    if(activeDoc.ObjectValid() && !flow.ObjectValid()){

        flow = activeDoc.MainFlowInDoc;

    }

 

 

    //get the first text frame in the flow, a starting point to

    //find the first paragraph

    if(flow.ObjectValid()){

        frame = flow.FirstTextFrameInFlow;

    }

 

 

    //At this point, if we don't have a frame object, might as well abort.

    if(!frame.ObjectValid()){

        Alert("Could not find a starting point for the search. Cannot continue." , Constants.FF_ALERT_CONTINUE_WARN);

    return replacementCounter;

    }

 

 

    //store the original text selection as an amenity to restore after the action.

    restoreTR = activeDoc.TextSelection;

 

 

    //now, set up the starting text range as the very beginning

    //of the flow. We'll move straight from beginning to end.

    tr.beg.obj = tr.end.obj = frame.FirstPgf;

    tr.beg.offset = tr.end.offset = 0;

 

 

    //set up our find parameters. We want to configure it to look

    //for a string and perhaps be case sensitive. We don't need

    //the find to wrap because we are controlling the flow from

    //beginning to end.

    findParams = AllocatePropVals(2);

 

 

    findParams[0].propIdent.num = Constants.FS_FindText;

    findParams[0].propVal.valType = Constants.FT_String;

    findParams[0].propVal.sval = findString;

 

 

    findParams[1].propIdent.num = Constants.FS_FindCustomizationFlags;

    findParams[1].propVal.valType = Constants.FT_Integer;

    if(considerCase){

        findParams[1].propVal.ival = Constants.FF_FIND_CONSIDER_CASE;

    }

    else{

        findParams[1].propVal.ival = 0;

    }

 

 

    //initialize the errno global, which will be used to

    //track the progress of the find and replace

    FA_errno = Constants.FE_Success;

 

 

    //and do an initial find to get started.

    tr = activeDoc.Find(tr.beg, findParams);

 

 

    //now, run the find and replace loop as long as we keep finding things.

    //The loop counter is just an emergency back door in case something

    //goes critically wrong and causes an endless loop.

    while(FA_errno === Constants.FE_Success && loopCounter++ < 1500){

    //set up the text range to clear the original text

        activeDoc.TextSelection = tr;

        //clear it

        activeDoc.Clear(0);

 

 

        //insert the new text. We should be able to use the

        //original beginning of the text range where the old text was

        //found.

        activeDoc.AddText(tr.beg, replaceString);

 

 

        //now, lets jimmy the text range in memory to place it directly

        //after the string we just inserted, so the find picks back up after that.

        tr.beg.offset += replaceString.length;

 

 

        //increment our return counter

        if(FA_errno === Constants.FE_Success){

            replacementCounter++;

        }

 

 

        //...and find the next instance. We'll reset FA_errno again just in case

        //something screwy happened while we were replacing text.

        FA_errno = Constants.FE_Success;

        tr = activeDoc.Find(tr.beg, findParams);

    }

    //we're done. Restore the document to it's original area of display

    activeDoc.TextSelection = restoreTR;

    activeDoc.ScrollToText(restoreTR);

    return replacementCounter;

}

Strip structure from document

$
0
0

Hi and all the best in new year!

 

If I like to open a structured document in unstructured framemaker-app, I can use Constants.FV_StripStructureAndOpen in open-parameters.

Is there any way to delete the structure information in a document to get the same document with all formats and text without structure, when the document is open in structured framemaker-app?

 

Thank you for all your ideas

Ute


Can anyone please guide me how to write a plugin from scratch for framemaker using extendscript?

$
0
0

My goal is to modify the index marker and cross references by using the extendscript plugin.

But I am not able to find any good source from where I can understand the basics of writing the plugin using extendscript.

How to trigger a refresh of a dropdown list when the selection is changed

$
0
0

Hi,

 

This is a general ExtendScript question, but since I'm working with FM, I'll ask here first. I have a bit of a paradox here and I'm not sure of the best way to handle it.

 

I have a dialog box with a dropdown list, where I want to refresh certain controls when the user changes the selection in the list (dropdownList.onChange). This includes refreshing the contents of the list itself. However, the problem is, as soon as I try to refresh the list contents, it triggers onChange again. So, if I put the call to refresh the box within the onChange handler, it results in an endless loop, because my refresher function triggers onChange when it refreshes the list.

 

Does anyone know a better methodology, where I can safely trigger a refresh of a dropdown list within the list's own onChange event handler? I really wish that onChange was reserved for a user action only, or there was at least some property to that effect.

 

Russ

Moving menu commands

$
0
0

Has anyone had success adding custom commands to FrameMaker menus and then moving them to different locations on the menu? I can do this with the FDK and FrameScript but I haven't had success with ExtendScript. I am defining a custom command and adding it to the File menu. I want to move it up under the Save As XML command. Here is what I am using:

 

#target framemaker

var menu, cmd, saveCmd;

// Get the File menu.
menu = app.GetNamedMenu ("FileMenu");

// Create the command and add it to the File menu.
cmd = menu.DefineAndAddCommand (10, "SaveAsPdfQuickCmd", "Save As PDF Quick","");
cmd.EnabledWhen = Constants.FV_ENABLE_NEEDS_DOCP_ONLY;

// Move the command up in the menu.
saveCmd = app.GetNamedCommand ("SaveAsXml");
cmd.PrevMenuItemInMenu = saveCmd;

// must call if script has been run through ESTK, redundant otherwise.
UpdateMenus ();

 

The custom command gets added to the File menu, but it stays at the bottom of the menu. Any help would be appreciated. Thanks.

-Rick

TextRange problem

$
0
0

I had reported a strange problem with TextRange in my post "Working off paragraphs in two successive While loops" - which could be bypassed with Russ Wards help.

In a recent discussion in the German Frame users group the root of this problem may have been addressed by Johannes Graubner - albeit related to FameScript (translated by me):

«

The command Find FromTextLoc does not work in FrameScript 6 / FrameMaker 2015 - at least not as documented and working in FrameScript 5.2 and FrameMaker 11.

Find FromTextLoc(lvRange) String(xFM1) NoWrap ReturnRange(lvRangeNew)
ReturnStatus(bStat);

The search does not start at the locaction defined by lvRange, but at the current cursor location.

A workaround is

Find TextRange(lvRange) ScrollTo;
Find FromTextLoc(lvRange) String(xFM1) NoWrap ReturnRange(lvRangeNew)
ReturnStatus(bStat);

Since many script commands are 1:1 transformations of the respctive API commens I assume that this is a FrameMaker problem and hence also exists in ExtendScript. I have reported the bug to Frank Elmore (FrameScript).

»

Replace string with formatted text

$
0
0

Dear all - I'm back to my beloved project...

I want to replace a found string by a TextSelction (formatted text) and started with Jang’s famous function  FindAndReplaceString.
Since my replacement comes from a different document (sourceDoc)  I edited activeDoc to targetDoc and introduced a second document (sourceDoc).
Actually the replacePara comes from an arry where it had been placed to avoid switching back and forth between the documents of a book (where to find and replace) and the source documents. I have learnt in another function that the information on the array requires that the sourceDoc must stay open.

  • Of course everything works fine until I want to insert the replacelement:
    line 26 clears the found string
  • Since I do not insert a string, I skip lines 28 and 29 and try try line 30
  • At line 30 sourceDoc is object Document and replacePare is object TextSelection. However, sourceDoc.replacePara is undefined and
  • (as a consequence ?) line 31 pasts the current clipboard contents.

Obviously there is some fog around me ... and I need some sunshine.

 

function FindAndReplacePara (targetDoc, findString, sourceDoc, replacePara, loopMax) {  var tr = new TextRange();  var restoreTR, frame = 0, loopCounter = 0, replacementCounter = 0;  var findParams = new PropVals();  var firstPgf = targetDoc.MainFlowInDoc.FirstTextFrameInFlow.FirstPgf;   tr.beg.obj = tr.end.obj = firstPgf;             //  set up the starting text range as the very beginning  tr.beg.offset = tr.end.offset = 0;              // of the flow. We'll move straight from beginning to end.  trSaved = tr                                    // to come back after work  findParams = AllocatePropVals(2);   findParams[0].propIdent.num = Constants.FS_FindText;  findParams[0].propVal.valType = Constants.FT_String;  findParams[0].propVal.sval = findString;   findParams[1].propIdent.num = Constants.FS_FindCustomizationFlags;  findParams[1].propVal.valType = Constants.FT_Integer;  findParams[1].propVal.ival = Constants.FF_FIND_CONSIDER_CASE;  FA_errno = Constants.FE_Success;                // errno global, to be used to track the progress of the find and replace  tr = targetDoc.Find(tr.beg, findParams);        // and do an initial find to get started.   while(FA_errno === Constants.FE_Success && loopCounter++ < 2*loopMax) { //find and replace loop as long as we keep finding    targetDoc.TextSelection = tr;                 // set up the text range to clear the original text    targetDoc.Clear(0);                           // clear it   
//    targetDoc.AddText(tr.beg, replacePara);       // insert the new text at the original beginning of the text range
//    tr.beg.offset += replacePara.length;          //  lets jimmy the text range in memory to place it directly after    targetDoc.TextSelection = sourceDoc.replacePara;        // paste the whole replacement paragraph    targetDoc.Paste (0);                          // <-- Current contents of clipboard is pasted !!!!    if(FA_errno === Constants.FE_Success) {       // increment our return counter      replacementCounter++;    }    FA_errno = Constants.FE_Success;              // ...  find the next instance. We'll reset FA_errno again just in case    tr = targetDoc.Find(tr.beg, findParams);      // something screwy happened while we were replacing text.  }  targetDoc.ScrollToText(trSaved);                // we're done. Restore the document to it's original area of display  return replacementCounter;
} // --- end FindAndReplacePara

Find text and apply paragraph format tag in Framemaker 11

$
0
0

Help!!!

 

I'm trying to automate finding text in a FM11 file and tagging it with a specific para tag. Once it's tagged, I want to be able to search for the same string again and delete it. The search will include wildcards. I'm moving Word files over and bringing them in with manual numbering of paragraphs. So, when they come in, they have "2.3.4.5" in front of the paragraphs for instance. I want to search for all numbers at beginning of paragraphs, tag all those with the appropriate para format (from a catalog) and then delete the manual numbering.

 

Right now we do this manually, by using Find/Replace and using wildcard search strings to find (such as "\P[1-9]*.*.*.*[0-9]", which will find all para numbering with 4 digits at the beginning of a para), and then using the Change By Pasting option to paste in a para tag from the catalog. Then we rerun the same search and delete the text, leaving only the para tag formatted numbering. It works great, but errors can arise if the search string in put incorrectly or if the numbers are not deleted (in this case, it is found on the next search and retagged improperly). For example

 

I work for the Air Force gathering inputs from the field and creating publications out of them, so there's no profit motive here, just trying to be efficient. Any help is greatly appreciated!!

 

thanks in advance

b

Re-apply format to paragraph

$
0
0

Dear all,

Once again it seams that I "put the cart before the horse" to do the following:

- In the current document i have a text selection and want to re-apply the pgf format from the catalogue to the current pgf.

- Taking the properties from the catalogue and applying to the current pgf does nothing.

 

function ReApplyPgfFormat (oDoc, tRange) {
// oDoc        current document
// tRange      current text range  var currPgf = tRange.beg.obj;  var pgfFormat = currPgf.Name;                   // most likely Footnote, but not guaranteed  var pgfFmt = oDoc.GetNamedPgfFmt(pgfFormat);     var pgfProps = pgfFmt.GetProps();               // from catalogue  currPgf.SetProps(pgfProps);                     // re-apply
alert ("Reformatting done?");                     // re-apply did not happen
}

I was searching in the documentation (fdk reference, object reference) back and forth - but did not get a clue.


Entering carriage returns in extendscript

$
0
0

So, I've been able to fight my way up to a point to where I can search for a string, apply a para format, then replace the found string. Works great!  Thanks, Russ, for the assist...

 

Now, does anyone know how to enter a carriage return as part of a find/replace? I've tried to just use "\r" and several combinations of that but can't figure it out. I need to find a specific text string, go to the end and enter a carriage return.

 

Also, along similar lines, when using the find function in the UI, you can put \P (for beginning of the para) and other criteria (like \t for tab stop). Does anyone know how to use those features in script?

 

Below is what I'm using for the search and apply formatting, just for sharing purposes, it works fine, just looking to extend features. It could probably be done a bit more elegantly, but if it works...

 

//This is the chsubpara5 search and tag
    var doc=app.ActiveDoc
    var docStart = doc.MainFlowInDoc.FirstTextFrameInFlow.FirstPgf ; 
    var tloc = new TextLoc (docStart, 0); 
    var findParams = new PropVals();
   // setup find parameters 
    var searchString = "[1-9]*.*.*.*.*.*.*[0-9]";
   
    findParams = AllocatePropVals(2);
  
    findParams[0].propIdent.num = Constants.FS_FindCustomizationFlags;
    findParams[0].propVal.valType = Constants.FT_Integer;   
    findParams[0].propVal.ival = 4;
   
    findParams[1].propIdent.num = Constants.FS_FindText;
    findParams[1].propVal.valType = Constants.FT_String;
    findParams[1].propVal.sval = searchString;
     
   pgfFmt = doc.GetNamedPgfFmt ("chsubpara5");
   var props = pgfFmt.GetProps();
   var foundText = doc.Find(tloc, findParams);        
   var counter = 0
  while (foundText.beg.obj.ObjectValid()&& counter < 100) { 
          
    tloc = new TextLoc(foundText.end.obj, foundText.end.offset);

//alert (foundText.beg.offset, 2);
   if (foundText.beg.offset=="0")
   {
   var pgf = tloc.obj;
   pgf.SetProps (props);
   //doc.AddText (tloc, replaceString);
   doc.DeleteText (foundText);
      }    
      
    foundText = doc.Find(tloc, findParams);
    counter ++;
    }
//End of chsubpara5 search and tag

FM Script to find the pagenumber of a paragraph

$
0
0

I am working on a frame maker script and flowing from first Pgf to the last Pgf in search of selected PgfFmt. When I found the required PgfFmt I need to list the page number in which page the Pgf is present. Using Scripting I can able to find the PgfFmt but I cant able to find the actual page in which it exist.

Thanks & Regards,

Lohithkumar

Logic to insert a CrossReference in an Active Doc

$
0
0

Hi,

I am facing problem in inserting Xref in the document that Xref is linked to the Figure in different document. I am not getting the logic how this can be established using Extend Script. Please guide me how this can be done. If possible, please share the example Script.

Thanks & Regards,

Lohithkumar

aFile.remove() not working as expected

$
0
0

Trying to find out why the code below is not deleting all files from the target folder.

 

After some test it appears that only graphic files (jpg, png, gif) are being removed, skipping pdf, txt, eps, doc, docx, etc.

 

Have you seen this happening before? Thanks,

 

#target framemaker

var aGraphicFiles = [];

//Check for target folder existance, if not, create.
var myTargetFolder = new File("C:\\Basket2\\XML Tests\\BookFolder\\Resources\\DeleteMe");
if (!checkFolderExists(myTargetFolder)){ //target folder does not exist
    myTargetFolder = new Folder("C:\\Basket2\\XML Tests\\BookFolder\\Resources\\DeleteMe");    myTargetFolder.create();
}

//Check if folder DeleteMe is empty
myTargetFolder = new Folder("C:\\Basket2\\XML Tests\\BookFolder\\Resources\\DeleteMe");
aGraphicFiles = myTargetFolder.getFiles();
if (aGraphicFiles.length != 0){
    for (i=0; i<aGraphicFiles.length; i++){ //scan array        var sourceChild = aGraphicFiles[i];        if (sourceChild instanceof File){            sourceChild.remove();            }        if (sourceChild instanceof Folder){            alert("I found a folder");        }    }
}

function checkFolderExists(myObj){
    var flagEx = false;    if (myObj.exists){        flagEx = true; //alert("myTargetFolder exists");     } else {        flagEx = false; //alert("myTargetFolder does NOT exist");     }     return flagEx;
}

Type mismatch ?

$
0
0

Dear experts,

I have an ini-file and want to read the value of a distinct entry. Within the script the item is found and its value also. Outside the script the value is undefined.

What happens? Any ideas are welcome.

 

var value;
GetIniValue ("FM-biblio.ini", "04_DoingBook", value);
alert ("value read is " + value);

function GetIniValue (sIniFile, sValueName, sValue) {
// ----------------------------------------------- Read an ini item into a variable
// iniFile must end with a line containing some blanks.
// sValueName is that used in the ini-file (with the prepending #_ (e.g. "04_DoingBook")
  var thisLine, match, notFound = true;  var regex = {    section: /^\s*\[\s*([^\]]*)\s*\]\s*$/,    param: /^\s*([\w\.\-\_]+)\s*=\s*(.*?)\s*$/,    comment: /^\s*;.*$/ } ;  settingsFile = new File($.fileName.replace (/[^\\\/]+$/i , sIniFile)); // method Ric Quatro  settingsFile.open("r");  while(true) {    thisLine = settingsFile.readln();                     if (settingsFile.eof) {                       // at end of the file we are done      break;    }    if (thisLine === null || thisLine === "") {   // skip blank lines      continue;    }    if (regex.comment.test(thisLine))  {          // skip comment lines      continue;    }    if (regex.section.test(thisLine))  {          // ignore section lines      continue;    }    match = thisLine.match(regex.param);          // ignore undefined contents    if (match[1] == sValueName) {      sValue = match[2];
alert ("GetIniValue: sValueName  " + sValueName + ", sValue read = " + sValue);      notFound = false;      break;                                      // no need to continue while loop    }  }  if (notFound) {    alert ("GetIniValue program error - sValueName " + sValueName + " not found in sIniFile " + sIniFile);    stop;  }  settingsFile.close();
} // --- end GetIniValue

 

The alert on line 34 reports "GetIniValue: sValueName  04_DoingBook, sValue read = no", but outside the value is undefined.

The ini file contains these lines:

 

...
03_ListItems      = yes
04_DoingBook      = no
05_Template       = FM-biblio-tpl.fm
...
Viewing all 888 articles
Browse latest View live


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>