Copy link to clipboard
Copied
Dear all,
My script for document navigation works fine as long as I do not use it via menu. Via menu the main function is not found:
Error Message : KLD_E.DocNav is not a function
Script, Line# : C:\Users\klaus\AppData\Roaming\Adobe\FrameMaker\15\startup\ETBdocNav.jsx, 85
I can not find, why the function is not defined. I have changed the location of it withing the script (before the menu set-up, after it) - to no positive effect.
Any ideas?
KLD_E.DocNavMenu = function (){ // === Create menu entry ================
var menuLocation, oCmd = {};
// ---------------- Menu and Command definition for documents -------
menuLocation = app.GetNamedMenu("ViewMenu");
oCmd.MenuDnav = menuLocation.DefineAndAddCommand (1,"ETBdocNav", localize (KLD_E.sDnav_title), "\\!qdn");
oCmd.MenuDnav.KeyboardShortcutLabel = "ESC q d n";
UpdateMenus();
} // --- end KLD_E.DocNavMenu
function Command(cmd) { // ==============================================
switch(cmd) { // Respond to menu command.
case 1:
KLD_E.DocNav();
break;
}
} // --- end Command
KLD_E.DocNav = function (location, bTag) { // === Main function =======
// Arguments location Current screen location of palette. used for resize
// Called by -
// Calling KLD_E.BuildPalette, KLD_E.GetParagraphs
// Comment To be implemented in ETBdocNav
var aPgfs = [], oDoc, wDocNav;
if (bTag === undefined) {bTag = false};
oDoc = app.ActiveDoc;
if (!oDoc.ObjectValid()) {
Alert (localize (KLD_E.sDnav_docRequ), localize (KLD_E.sDnav_title), true);
return;
}
if (!KLD_E.GetLevelSettings(KLD_E.oLevelSettings)) {return;};
KLD_E.GetParagraphs (oDoc, aPgfs, KLD_E.oLevelSettings);
wDocNav = KLD_E.BuildPalette (oDoc, aPgfs, KLD_E.oLevelSettings, bTag);
if (location) {
wDocNav.bounds = location; // Restore the palette's previous size and location on the screen.
}
} // end of KLD_E.DocNav
Solved - see end of post
Script behaves differently in Startup and in the …\Adobe Scripts folder
I have added a log instruction just before the execution in the Command function - and there is aleady one just befor calling the main function (see above).
function Command(cmd) { // ==========================================
switch(cmd) { // Respond to menu command.
case 1:
Console ("Command - KLD_E.DocNav is " + typeof KLD_E.DocNav);
KLD_E.DocNav ();
brea
...
Copy link to clipboard
Copied
Strange things happen withem.
At the very end of the script file I have these statements:
Console ("KLD_E.DocNav is " + typeof KLD_E.DocNav);
Console ("KLD_E.DocNavMenu is " + typeof KLD_E.DocNavMenu);
KLD_E.DocNavMenu (); // comment for debug without menu
//KLD_E.DocNav (); // uncomment for debug without menu
Before this all functions are defined. During start the first Console statement is executed and delivers
KLD_E.DocNav is function
KLD_E.DocNavMenu is function
There is a menu item established - hence I can issue the function.
When issuing the shortcut ESC q d n or select the menu I get in the console
Error Message : KLD_E.DocNav is not a function
Script, Line# : C:\Users\klaus\AppData\Roaming\Adobe\FrameMaker\15\startup\ETBdocNav.jsx, 514
So at some time the type of the function is ruined - but how?
Copy link to clipboard
Copied
Solved - see end of post
Script behaves differently in Startup and in the …\Adobe Scripts folder
I have added a log instruction just before the execution in the Command function - and there is aleady one just befor calling the main function (see above).
function Command(cmd) { // ==========================================
switch(cmd) { // Respond to menu command.
case 1:
Console ("Command - KLD_E.DocNav is " + typeof KLD_E.DocNav);
KLD_E.DocNav ();
break;
}
} // --- end Command
…\Adobe Scriptsfolder - other scripts (Startup) using the global object KLD_E
Running the script: the menu is established and the log confirms that KLD_E.DocNav is function.
Execute the script via menu: It runs and the log in the Command function also confirms that KLD_E.DocNav is function.
→ In this environement (started from the …\Adobe Scripts folder) the scripts works correctly.
Startup folder - no other scripts using the global object KLD_E
The script established the menu and the log confirms that KLD_E.DocNav is function.
Execute the script via menu: It runs and the log in the Command function also confirms that KLD_E.DocNav is function.
→ The script runs correctly also from the Startup folder, if there are no other scripts using the global object KLD_E.
Startup folder - with other scripts (Startup) using the global object KLD_E
→ This logs on execution from the menu: Command - KLD_E.DocNav is undefined
Conclusion
Error in using global object KLD_E. Replace
KLD_E = {};
by
if (typeof KLD_E == "undefined") {
KLD_E = {}; // Global object may already be defined by others
}
... and everything works as expected!