Highlighted

jsx versus jsxbin

Advocate ,
Mar 08, 2018

Copy link to clipboard

Copied

Dear all,

I observe a difference in script behaviour when using jsx sources compared to jsxbin:

My large script FMcalc consists of 10 modules with a total of 208 functions:

Module nameContaining
FMcalc.jsx#includes to all other modules (except the language modules); main(), Command(cmd), SetUpMenues(), SetupFMcalc() etc.
FMcalc_Globals.jsx#includes to the language modules; global declarations
FMcalc_Ancillary.jsxAncillary functions such as OpenPdfAtDestination (pdfFile, location), PadWith0(number, nPlaces), CloneObject (oTarget, oSource), CopyToClipboard (theString), etc.
FMcalc_dialogC.jsx 
FMcalc_dialogS.jsx 
FMcalc_dialogDS.jsx
FMcalc_dialogV.jsx

All but the last define palettes. dialogDS allows to set building blocks and settings for the process.

These modules contain the Window definition and the corrspoinding action functions (e.g. ButtonEvalC () to evaluate contents of calc markers).

DialogV is an input-check for DialogDS and not a palette.

FMcalc_Evaluation.jsx
FMcalc_Markers.jsx   
FMcalc_Math.jsx     
Evaluation contains functions for analysing statements and evaluating formulas etc. Markers contains functions to handle markers and Math contains special math functions such as M_Asinh(xx) (arcus sinus hyprbolicus)
FMcalc_Texts_en.jsx
FMcalc_Texts_de.jsx
FMcalc_Texts_fr.jsx

These modules contain UI texts wich are cloned into a general text object depending on the current FM language.

In the dilaogues and messages only this general text object is referenced.

  • The jsxbin is built by opening FMcalc.jsx and exporting as jsxbin.
  • When installing this FMcalc.jsxbin into the FM startup folder (together with an fm-template file and a pdf help file) provides a corrclty working script.
  • When trying to use the jsx sources things don't work any more: The script loads without error, but the dialogue texts are not in the dialogues and settings are only known in the main module (FMcalc.jsx), not in the other modules, e.g. FMcalc_Evaluation.jsx in the function EvaluateStmntsC (text) { //Evaluate contents of #calc marker statement}. Outside of the main module only the intitial values as defined in FMcalc_Globals are known. There they are either set to distinct values or to undefined.
  • I have observed that the jsxbin is a flattened out item - as if I would concatenate all the source modules to a single file. Hence 'script-directory' is the same in all functions. Evaluting the script directory in one of the included source modules provides a different level than in the main module which includes the others.

After reading about some ExtendScript include quirks (e.g. by williamadowling) I'm completely puzzled. It's about Indesign, but this may also be true for FM: #include requires absolte paths !?! This would be OK on my own machine - but nobody else could use my script. The main script currently start with these lines:

#target framemaker
#include FMcalc\FMcalc_Globals.jsx            // all declarations
#include FMcalc\FMcalc_Ancillary.jsx          // ancillary functions
#include FMcalc\FMcalc_dialogC.jsx            // incl. button functions etc.
#include FMcalc\FMcalc_dialogS.jsx            // incl. button functions etc.
#include FMcalc\FMcalc_dialogDS.jsx           // incl. button functions etc.
#include FMcalc\FMcalc_dialogV.jsx            // ancillary dialogue
#include FMcalc\FMcalc_Evaluation.jsx         // for the evaluation process
#include FMcalc\FMcalc_Markers.jsx            // functions related to markers
#include FMcalc\FMcalc_Math.jsx               // math functions for evaluation
#include FMcalc\FMcalc_Texts_en.jsx           // From the relevant one the object will be cloned
#include FMcalc\FMcalc_Texts_de.jsx           // see FMcalc\FMcalc_Ancillary.jsx, SwitchUIlanguage
#include FMcalc\FMcalc_Texts_fr.jsx

main ();

function main () {
// Calling   SetupFMcalc, SetupNotifications, ReportInfo, SetUpMenus
}

function SetUpMenus () {
//=== Define the menu items for document and book
}

function Command (cmd) {
  ...
    case 2:
      CalculateInDoc();                        
      break;
  ...
}

function CalculateInDoc() {
// Evaluate Calc/Series markers in document
// Called by Command, CalculateInBook
// Calling   SaveCurrentLocation, SetDisplay, GetDSPanelItems, CollectMarkers, CollectVariables,
//           EvaluateC, PaletteCalcMarkers, RestoreLocation, FindAndDeleteVariable, InsertVariable,
//           DeleteUnusedVariables, GetRefPageCategory, oTxtScheme, GetAllSchemes, EvaluateS,
//           PaletteSeriesMarkers
}
...

So what is the secret of breaking up a long script into modules to avoid clutter in the Startup folder and nevertheless provide source code rather than jsxbin?

Klaus

Edit 2018-03-08 10:59

Mimicing the include process of the jsxbin building I have put everything together and get a complely unmanageable jsx file of nearly 8000 lines. But also here the settings are not gotten as defined in an early executed routine, not even the default from the initial global setting, but undefined!

TOPICS
Scripting

Views

682

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

jsx versus jsxbin

Advocate ,
Mar 08, 2018

Copy link to clipboard

Copied

Dear all,

I observe a difference in script behaviour when using jsx sources compared to jsxbin:

My large script FMcalc consists of 10 modules with a total of 208 functions:

Module nameContaining
FMcalc.jsx#includes to all other modules (except the language modules); main(), Command(cmd), SetUpMenues(), SetupFMcalc() etc.
FMcalc_Globals.jsx#includes to the language modules; global declarations
FMcalc_Ancillary.jsxAncillary functions such as OpenPdfAtDestination (pdfFile, location), PadWith0(number, nPlaces), CloneObject (oTarget, oSource), CopyToClipboard (theString), etc.
FMcalc_dialogC.jsx 
FMcalc_dialogS.jsx 
FMcalc_dialogDS.jsx
FMcalc_dialogV.jsx

All but the last define palettes. dialogDS allows to set building blocks and settings for the process.

These modules contain the Window definition and the corrspoinding action functions (e.g. ButtonEvalC () to evaluate contents of calc markers).

DialogV is an input-check for DialogDS and not a palette.

FMcalc_Evaluation.jsx
FMcalc_Markers.jsx   
FMcalc_Math.jsx     
Evaluation contains functions for analysing statements and evaluating formulas etc. Markers contains functions to handle markers and Math contains special math functions such as M_Asinh(xx) (arcus sinus hyprbolicus)
FMcalc_Texts_en.jsx
FMcalc_Texts_de.jsx
FMcalc_Texts_fr.jsx

These modules contain UI texts wich are cloned into a general text object depending on the current FM language.

In the dilaogues and messages only this general text object is referenced.

  • The jsxbin is built by opening FMcalc.jsx and exporting as jsxbin.
  • When installing this FMcalc.jsxbin into the FM startup folder (together with an fm-template file and a pdf help file) provides a corrclty working script.
  • When trying to use the jsx sources things don't work any more: The script loads without error, but the dialogue texts are not in the dialogues and settings are only known in the main module (FMcalc.jsx), not in the other modules, e.g. FMcalc_Evaluation.jsx in the function EvaluateStmntsC (text) { //Evaluate contents of #calc marker statement}. Outside of the main module only the intitial values as defined in FMcalc_Globals are known. There they are either set to distinct values or to undefined.
  • I have observed that the jsxbin is a flattened out item - as if I would concatenate all the source modules to a single file. Hence 'script-directory' is the same in all functions. Evaluting the script directory in one of the included source modules provides a different level than in the main module which includes the others.

After reading about some ExtendScript include quirks (e.g. by williamadowling) I'm completely puzzled. It's about Indesign, but this may also be true for FM: #include requires absolte paths !?! This would be OK on my own machine - but nobody else could use my script. The main script currently start with these lines:

#target framemaker
#include FMcalc\FMcalc_Globals.jsx            // all declarations
#include FMcalc\FMcalc_Ancillary.jsx          // ancillary functions
#include FMcalc\FMcalc_dialogC.jsx            // incl. button functions etc.
#include FMcalc\FMcalc_dialogS.jsx            // incl. button functions etc.
#include FMcalc\FMcalc_dialogDS.jsx           // incl. button functions etc.
#include FMcalc\FMcalc_dialogV.jsx            // ancillary dialogue
#include FMcalc\FMcalc_Evaluation.jsx         // for the evaluation process
#include FMcalc\FMcalc_Markers.jsx            // functions related to markers
#include FMcalc\FMcalc_Math.jsx               // math functions for evaluation
#include FMcalc\FMcalc_Texts_en.jsx           // From the relevant one the object will be cloned
#include FMcalc\FMcalc_Texts_de.jsx           // see FMcalc\FMcalc_Ancillary.jsx, SwitchUIlanguage
#include FMcalc\FMcalc_Texts_fr.jsx

main ();

function main () {
// Calling   SetupFMcalc, SetupNotifications, ReportInfo, SetUpMenus
}

function SetUpMenus () {
//=== Define the menu items for document and book
}

function Command (cmd) {
  ...
    case 2:
      CalculateInDoc();                        
      break;
  ...
}

function CalculateInDoc() {
// Evaluate Calc/Series markers in document
// Called by Command, CalculateInBook
// Calling   SaveCurrentLocation, SetDisplay, GetDSPanelItems, CollectMarkers, CollectVariables,
//           EvaluateC, PaletteCalcMarkers, RestoreLocation, FindAndDeleteVariable, InsertVariable,
//           DeleteUnusedVariables, GetRefPageCategory, oTxtScheme, GetAllSchemes, EvaluateS,
//           PaletteSeriesMarkers
}
...

So what is the secret of breaking up a long script into modules to avoid clutter in the Startup folder and nevertheless provide source code rather than jsxbin?

Klaus

Edit 2018-03-08 10:59

Mimicing the include process of the jsxbin building I have put everything together and get a complely unmanageable jsx file of nearly 8000 lines. But also here the settings are not gotten as defined in an early executed routine, not even the default from the initial global setting, but undefined!

TOPICS
Scripting

Views

683

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 08, 2018 0
K.Daube LATEST
Advocate ,
Mar 08, 2018

Copy link to clipboard

Copied

Well, I have not found the reason for this behaviour, but have found a detour/circumvention:

Insert the following statement at the very beginning of the dialogue in which function fails:

GetDocSettings (goFMc.oCurrentDoc);

This re-reads the settings found  in the current document and fills it into the global object. This was already regularly done when a document is opened. It is not clear to me why this solves my problem in the modularized source code.

Thanks for listening - and keep an eye on including modules.

Klaus

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, 2018 0