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 name | Containing |
---|---|
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.jsx | Ancillary 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!