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

How to avoid wrap in find method ?

$
0
0

Dear friends,

 

Although i carefully followed the advice found at this post, I have no success. The find always wraps back to the first occurrence fo the items to be found.

Case 3 works fine for several months now - but why does case 4 not?

Jang obviously had the same problem in the mentioned post ...

function GetFindParameters (iType, sSearch) {
var propVal, findParams = new PropVals() ;   switch (iType) {
// ...    case 3: // ---------------------------------- find marker of type sSearch, don't wrap      propVal = new PropVal() ;       propVal.propIdent.num = Constants.FS_FindWrap ;       propVal.propVal.valType = Constants.FT_Integer;       propVal.propVal.ival = 0 ;      findParams.push(propVal);       propVal = new PropVal() ;       propVal.propIdent.num = Constants.FS_FindMarkerOfType;       propVal.propVal.valType = Constants.FT_String;       propVal.propVal.sval = sSearch;       findParams.push(propVal);       return findParams;      break;    case 4: // ---------------------------------- find character format sSearch, don't wrap      propVal = new PropVal() ;       propVal.propIdent.num = Constants.FS_FindWrap ;       propVal.propVal.valType = Constants.FT_Integer;       propVal.propVal.ival = 0 ;      findParams.push(propVal);       propVal.propIdent.num = Constants.FS_FindCharTag;       propVal.propVal.valType = Constants.FO_CharFmt;       propVal.propVal.sval = sSearch;       findParams.push(propVal);       return findParams;      break;    default:      alert ("GetFindParameters:\nPgm error: case " + iType + " in switch not defined.", "GetFindParameters", true);      return null;  }
} //---  end GetFindParameters

 

Because of this my searches are not terminated and loop forever - FA_errno is not set (as described in the FDK doc).

  findRange = goCurrentDoc.Find  (oTextLoc, findParams);// finds text range (object pgf), lenght 1  if (FA_errno === Constants.FE_NotFound) {    return null;                                  // no further items  }

 

What's wrong with my search parameters?


ExtendScript and WebDAV

$
0
0

Hi,

 

I am hoping some Adobe lurkers will be out here and be able to give me some help. I would like to use some FrameMaker WebDAV commands with ExtendScript. I tried following the examples for F_ApiCallClient in the FDK Programmer's Reference, but I can't get them to work. Does anyone have any example scripts that I can start with? Thank you very much.

 

-Rick

How to access the Publisher module

$
0
0

Does anybody know if the Publisher module is exposed to FM's Extendscript (or FDK)? I looked through all of the scripting info and the FDK info, .h and config files and couldn't find any references to it other than the TPUBforFMDoc (Book/DITA  esc ph shortcut) command. I need to kick off the Publish module after some manipulation and use a specified STS file depending upon the manipulation.

Custom Ruling & Shading via ExtendScript

$
0
0

Hi,

 

I've taken up learning ExtendScript to tackle some common problems in my workflow.

 

My current project is to write a scrip that applies white rules to the columns in table heading rows.

 

So far my script can select the top (heading) row of the appropriate tables. But I can't figure out what the commands are for applying ruling. I've searched through every piece of documentation I could get my hands on, but there doesn't seem to be extensive material written with the beginner in mind.

 

Here's the script so far (Note: the counter and the alerts are just there so I know everything is working as I go along):

 

//target the active document

var doc = app.ActiveDoc;

 

//target the "first" table

var table = doc.FirstTblInDoc;

 

//number of tables to edit

var numberOfTables = 0;

 

if(table.ObjectValid() == true)

{

    while(table.ObjectValid() == true)

    {

        if(table.TblTag == "WithHeading")

        {

            numberOfTables++;

            alert("The table '" + table.TblTag.toString() + "' will be edited.");

           

            //select the top row of the table

            table.MakeTblSelection(0, 0, 0, table.TblNumRows - 1);

            table = table.NextTblInDoc;

        }

 

        else

        {

            alert("The table '" + table.TblTag.toString() + "' will not be edited.");

            table = table.NextTblInDoc;

        }

    }

}

 

else

{

    alert("No more tables.");

}

 

alert(numberOfTables + " tables will be edited.");

Script favorites not persistent

$
0
0

In FM 13.0.5.547 the scripts in the script library (favorites list) disappear after some time.

  1. I define a favorite script, then close FM
  2. Start FM again: (withing a minute) the script is still in the catalogue.
  3. I closeFM
  4. After a while (about 5 min) I start FM again
  5. => Tthe script is no more in the catalogue!

Where the heck is the catalogue stored?
Who may delete the catalgoue?

 

Klaus Daube

Batch Processing or Script for FrameMaker 2015 - Save all book .fm files to .mif

$
0
0

I have received a client's FrameMaker 2015 document that I need to prepare for translation. The book is comprised of over 900 .fm FrameMaker files each of which will need to be saved as a .mif file for use with SDL Trados Studio. Where can I find a script or a plugin for FrameMaker 2015 to allow me to batch process these .fm files without needing to Open > Save As each individual file? !

Reducing Cyclomatic Complexity - in all cases?

$
0
0

Dear experts
Everything works in my script (hmm, you read about ghosts and twins...). However JsHint.com reports for some long function a Cyclomatic Complexity beyond the acceptable limit - up to 50.

In many cases I could cut this down to about 10 (replacing switch by if/else if and splitting off reasonable chunks into sub-functions).

But for a function like the following (complexity 22) I would need to split off the actions in the if (character ... clauses into separate function with many parameters. IMHO this would be just l'art pour l'art:

 

The function in question parses a string and acts at particular characters thus expanding it step by step to an evaluative statement:

#vat_amount = Round(((Sum(Left(3))) + #item + [CELL 5, 5]) * #VAT, 2) {F2};

To be evaluated it has to be expanded step by step:

#vat_amount = Round(((Sum(Left(3))) + #item + [CELL 5, 5]) * #VAT, 2)
#vat_amount = M_Round(((Sum(Left(3))) + #item + [CELL 5, 5]) * #VAT, 2);
#vat_amount = M_Round(((M_Sum(Left(3))) + #item + [CELL 5, 5]) * #VAT, 2)
#vat_amount = M_Round(((M_Sum(17.0, 23.7, 37.9)) + #item + [CELL 5, 5]) * #VAT, 2)
#vat_amount = M_Round(((M_Sum(17.0, 23.7, 37.9)) + 12.34 + [CELL 5, 5]) * #VAT, 2)
#vat_amount = M_Round(((M_Sum(17.0, 23.7, 37.9)) + 12.34 + 56.78) * #VAT, 2)
#vat_amount = M_Round(((M_Sum(17.0, 23.7, 37.9)) + 12.34 + 56.78) * 0.08, 2)

The interpretation of the final line is:
User variable #vat_amount will receive the result from the formula. M_Round and M_sum are functions.

 

The skeleton of my function looks like this:

function EvaluateStmntsC (text) {
//...   for(indexOfChar = 0; character = localText[indexOfChar]; indexOfChar++) {      if (character.match(/[ (),+\-*\/]/) !== null) {        continue;      } else      if (character == "#") {         // expand the user variable      } else      if (character == "@"){        // expand the constant      } else      if (character.match(/[ABCEFHLMPRST]/) !== null) {        // expand function name (e.g. Sin => Math.sin)        // and check for the number of arguments in the ()      } else      if (character.match(/[0-9]/) !== null) {        // numeric value, just advance behind it        // optional - sign has been skipped already      } else      if (character == "["){        // Expand to cell contentss      } else      if (character == "<") {             // if followed by =, this introduces a vector notation (list of values).      } else      if (character == "{") {        // put the output format aside for later use      //...         } else {           // indicate illegal character (e.g. unknown function)      }      EvaluateStmntsCfinalise (aStatement[j], jAssign, bHasVector, sVarName, fmtString)    } //--- end for indexOfChar, statement worked off  } //--- end for statements  return true;
} //--- end EvaluateStmntsC

 

This skeleton alone result in a complexity of 10. Of course there are some 'intra'-case structures with 1-2 nested if's => leading to a final complexity of 22.
Towards the end I have extracted what is there into a new function, which on it's own has a complexity of 6 and needs quite a number of parameters:

 

function
EvaluateStmntsCfinalise (sStatement, jAssign, bHasVector, sVarName, fmtString) {
var kText, bIsOK, sEval, rResult, sFormatted;  kText = StrTrim(localText.substring (jAssign+1));// a vector definition is kept intact within variable  bIsOK = ContainsVector (kText);               // may be the result of a table location  if (bHasVector || bIsOK) {                    //--- store whole list in variable - unformatted!    iLength = sVarName.length;    if (sVarName.indexOf ("<") > 0) {iLength = iLength - 1;} // "#TEST <"  => "#TEST"      sVarName = sVarName.substring (0, iLength);      sVarName = StrTrim(sVarName);               // there may be blanks      WriteFeedback (" Filling variable = "+ sVarName + " with \n >"+kText);      DefineUserVariable (glbl.oCurrentDoc, sVarName, kText); // Fill user var with vector  } else {                                      //--- scalar variable: evaluate, format, store    sEval = "rResult = " + kText;    WriteFeedback (" To evaluate:\n>"+sEval);    try {eval (sEval);}                         // JShint: eval can be harmful.    catch (e) {      MsgErrEvaluation (sStatement, sEval, e.name, e.message);      return false;    }    WriteFeedback (" rResult = "+rResult);    sFormatted = FormatValue (rResult, fmtString, true); // format result    if (glbl.bTempVar) {glbl.sTempVar = sVarName;}       // for direct insertion    DefineUserVariable (glbl.oCurrentDoc, sVarName, sFormatted); // Fill user var  }
}

 

So my question is this:
Is it worth to create a huge number of functions just to reduce the complexity of a somewhat linearly long function?

FA_Note_PostActiveDocChange - strange happening

$
0
0

Dear friends,

In my script I have a Notify function to react on certain events.
I have now discovered that FA_Note_PostActiveDocChange triggers although I have only one file open.
Notify is invoked after leaving a function (which works on the document) and just climbing up the return ladder:

Leaving HandleCalcMarkers
Leaving Command
FA_Note_PostActiveDocChange triggered

 

FA_Note_PostActiveDocChange is not explained in the FDK reference. Adobe FrameMaker Scripting Guide only mentions it: (Constants.FA_Note_PostActiveDocChange int Value: 105).

My understanding of this constant is that it triggers when I switch from one open document to another. I do not understand why it can trigger with only one document open.

Although this behaviour does not create (as far as I see) any negative effect in the script, I'm suspicious...


Need help using Socket

$
0
0

I need to connect to a webpage that contains a list of documents. Need to grab the next document ID available by reading the top most document.

Can somebody point in the right direction?

I tried the script that comes in the manual but something is not working right.

Thanks.

Is it possible to run an ExtendScript function from the FDK?

$
0
0

I have created an ExtendScript function that builds and populates a ScriptUI dialog. It then opens a template selected by the user. This works well and does everything I want it to do. Now the problem is that I need to run it from an FDK menu. This ExtendScript function takes a single argument.

 

I though that F_ApiCallClient() would be the way to go, but it's not documented for that usage. Has anyone tried to do this and succeeded? Or perhaps I'm overlooking a really obvious way to do it?

 

Thanks

Ian

Open a FM 10 document to a specific paragraph ID

$
0
0

I would like to be able to open a FM 10 document at a particular paragraph, so the paragraph is scrolled to. I want to pass the paragraph ID for a heading and have the heading at the top (or at least within the visible portion) of the document window. Is this possible?

Algorithm for navigating an element selection

$
0
0

Hi All,

 

Given a selected element anywhere in a document:

 

var doc = app.ActiveDoc;
var element = doc.ElementSelection.beg.child;

 

I can touch every element in the tree using a function like this:

 

var elements = getElements (element, /^xref$/, []);

function getElements (element, nameRegex, elements) {

    if (element.ElementDef.ObjectValid ()) {        if (nameRegex.test (element.ElementDef.Name)) {            elements.push (element);        }    }    var element2 = element.FirstChildElement;    while (element2.ObjectValid ()) {        elements = getElements (element2, nameRegex, elements);        element2 = element2.NextSiblingElement;    }    return elements;
}

 

This particular function traverses the selected element and its descendants and gets elements matching a particular regular expression. What is important is that it uses recursion to touch every element in the tree.

 

I have a different situation where there may be a series of sibling elements selected and I want to still touch every element in the selection. The selection might look something like this:

 

structureview.png

Notice that there is no top-level, containing element selected. But I still want to touch every element in the selection. I am looking for a general purpose algorithm for doing this. Thank you very much.

 

-Rick

SharePoint+ Framemaker

$
0
0

How do I trigger a 'save as PDF' of a FM file that is sitting in our SharePoint document library? I know I can probably register a script to "save as" but how do I run it from a button click on my SharePoint document library after selecting a bunch of framemaker files?

Framescript: Retrieving text from a broken xref

$
0
0

Hello fellows,

 

I'd like to write a script that will find broken external xrefs and attempt to restore them.  In my case, the xrefs get broken because the xref markers appearing in the source files are often updated by a system that generates these source files. I'd like to restore the xrefs by retrieving the xref string and attempting to find this string in the source files. But here is a problem: when an xref is broken, it no longer allows to retrieve XRefSrcText properly. The xref string no longer appears in XRefSrcText. I used the following code to test that:

 

Set vCurrentDoc = ActiveDoc;

Set vXRef = vCurrentDoc.FirstXRefInDoc;

 

Loop While(vXRef)

If vXRef.XRefIsUnresolved

Write Console  vXRef.XRefSrcText;

 

EndIf

Set vXRef = vXRef.NextXRefInDoc;

EndLoop

 

So, the XRefSrcText of an unresolved xref appears as follows:

25117: TableTitleTable Entry: ;2511718;2511719

 

While the XRefSrcText  of a live xref  appears as follows:

 

41369: TableTitle: Table 329: Item Numbering

 

What I would need to extract from here is the string "Item Numbering" and then find it in the xref source file to create a new link.

 

My question is how can one retrieve the text string from a broken xref? One way I could think of is converting the xrefs to text, copying the relevant part into a variable using regex. Any other ideas?

 

Thank you!

Trapping the ghost

$
0
0

Dear friends,
In my post Special effects - mostly unwanted I reported about some really persky things happening with my (now about 4500 lines) script. While the Twins and the Slave effect have disappeared by the time (not knowing which changes did it), the Ghost could not be trapped until now.
Hence, I have now stripped down the script to the bare bones, which also create this ghostly effect.

 

  • Have any FM document open (it may be empty) and run the script Ghostbuster.jsx
  • In the document type ESC, q, m, c
  • The panel is opened
  • You may type something in the edit field
  • Cancel
  • In the document type ESC, q, m, c

 

=> The ghost appears: a mysterious drop down list, which got text from the edit field and into which you can type (and if you do so),  the typed text will apear in the next invocation of th panel.

 

Where the heck does this come from?

Ghostbusters are higly welcome!

 

Klaus

// Ghostbuster.jsx --- Attempt to find out what creates the ghost (artfacts) in the C and S panels.

#target framemaker

// === global variables, arrays ===================================================================
var wPalC  = new Window("palette", undefined, undefined);  // title set in PaletteCalcMarkers
var glbl = {};  glbl.sCalcMarkerText = "Some initial text";
main ();                                          // follow the standard …

function main () { //=== ==========================================================================
  SetUpMenus(); // uncomment             comment
}
function SetUpMenus () { //=== Define the menu items for document and book ========================
var bkFMcalcMenu, docFMcalcMenu, menuLocation, oMenus = {}, oCmd = {};  oMenus.MenuMain           = "Calculations in FrameMaker…";  oMenus.HandleCalcMarker   = "Handle #calc Markers…";  oCmd.HandleCalcMarker   = DefineCommand(4,"docHcalcMarker",   oMenus.HandleCalcMarker,   "\\!qmc");  oCmd.HandleCalcMarker.KeyboardShortcutLabel   = "ESC q m c";   menuLocation = app.GetNamedMenu("FormatMenu");  docFMcalcMenu  = menuLocation.DefineAndAddMenu("!FMcalcMain", oMenus.MenuMain); // ! required  docFMcalcMenu.AddCommandToMenu (oCmd.HandleCalcMarker);  UpdateMenus();                                  // refresh and actually make the new menu appear
} //--- end SetUpMenus

function Command (cmd) { //=== Assign functions to menu commands ==================================     switch (cmd) {    case 4:      PaletteCalcMarkers();         break;  }
} //--- end Command

function PaletteCalcMarkers(){ //=== Palette for handling #calc markers ===========================
  wPalC.title = "FMcalc : Handle #calc Markers";    wPalC.st1 = wPalC.add('statictext',undefined,"Marker contents");    wPalC.st1.alignment = ['left',' '];    wPalC.st1.graphics.font = ScriptUI.newFont(wPalC.st1.graphics.font.family,"BOLD",wPalC.st1.graphics.font.size);    wPalC.sMarkerContent = wPalC.add('edittext',undefined, glbl.sCalcMarkerText, {multiline:true, scrollable:true});  wPalC.sMarkerContent.graphics.font = ScriptUI.newFont ("Consolas", "", 12);    wPalC.sMarkerContent.preferredSize.width = 580;    wPalC.sMarkerContent.preferredSize.height = 65;
//                                                //--- Button row Evaluate, Help, Cancel ---------  wPalC.g4 = wPalC.add('group',undefined);  wPalC.g4.alignment = ['fill',' '];  wPalC.g4.margins= [0,0,7,0];                    // add right margin      wPalC.g4.Cancel = wPalC.g4.add('button',undefined,"Cancel");      wPalC.g4.Cancel.helpTip = "Dismiss dialogue panel";      wPalC.g4.Cancel.preferredSize.width = 137;  wPalC.g4.Cancel.onClick = function () {    wPalC.close();  };  wPalC.show();
} //--- end of PaletteCalcMarkers -----------------------------------------------------------------

Is it possible to copy folder with Extendscript

$
0
0

Not sure if this is only available to files... Trying to create a folder locally (C: drive) and then copy the folder (and contents) to another folder on the network...

 

var foSource = new Folder(myPath);

foSource.copy(strTarget);

 

This throws an error... any ideas?

 

Thanks!

Events calls for insert Variable

$
0
0

Are there any events, which are called by FM only in case of insertion FM Variables?

 

Thanks!

How to Apply No AttrCondFmts

$
0
0

I am trying to Show All Attribute Expressions (Special > Filter by Attribute) using ExtendScript. I can do this:

 

#target framemaker

var doc = app.ActiveDoc;
var attrCondExpr = doc.FirstAttrCondExprInDoc;
while (attrCondExpr.ObjectValid () === 1) {
    attrCondExpr.AttrCondExprIsActive = 0;    attrCondExpr = attrCondExpr.NextAttrCondExprInDoc;
}

 

And it does switch the "Manage Attribute Expressions" Show All radio button to on. The problem is that it does "Apply" the change to the document. There is an ApplyAttributeExpression() method on the AttrCondExpr object, but there is nothing on the document. I don't want to apply a particular filter; I want to apply no filter to show everything. Any help would be appreciated. -Rick

Put focus on insertion point..

$
0
0

I'm trying to put the focus on the insertion point after inserting text from a palette without mouseclick.

I just want to continue writing at that point.

 

Things I've already tested:

- scrollToText

- oDoc.IsInFront = 1

- oDoc.TextSelection = tRange

 

Has anybody solved this problem?

 

var w = new Window ("palette","INSERT");    w.Button = w.add("button",undefined,"Go")    w.Button.onClick = Insert;    w.show()

function Insert()
{
var oDoc = app.ActiveDoc
var textLoc = oDoc.TextSelection.beg; 
oDoc.AddText (textLoc, "Test"); 
}

Check the complete Book

$
0
0

Hi Scripter,

 

we want to check all the text content within a book with a regular expression and JavaScript.

We have no idea how it works.

 

Can someone help us?

 

Thank you.

Viewing all 888 articles
Browse latest View live


Latest Images