最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

javascript - Adobe InDesign CS6 "undefined is not an object" - Stack Overflow

matteradmin5PV0评论

I am new to InDesign scripting though I do have experience with Javascript. I created a new menu item as you will see in the script below, which I planned to use it to call another script onclick. However I am facing some issues, so I decided to delete the menu item and start over. But at line 10, I get the message "undefined is not an object", which I can't figure out why it's causing a problem.

Any help will be appreciated.

//#targetengine "ImportFolder"

//var myMainMenu = app.menus.item("Main");
//var myCustomMenu = myMainMenu.submenus.item("Import Folder");
//var myCustomMenu = myMainMenu.submenus.add("Import Folder");
//var mySampleScriptAction = app.scriptMenuActions.add("onInvoke", function() {
//app.doScript(new File ("/C/Program Files (x86)/Adobe/Adobe InDesign CS6/Scripts/Scripts Panel/importFiles.jsx" ));});

//delete the menu
var myMainMenu = app.menus.item("Main");
try{
var myCustomMenu = myMainMenu.submenus.item("Import Folder");
myCustomMenu.remove();
}catch(myError){}

I am new to InDesign scripting though I do have experience with Javascript. I created a new menu item as you will see in the script below, which I planned to use it to call another script onclick. However I am facing some issues, so I decided to delete the menu item and start over. But at line 10, I get the message "undefined is not an object", which I can't figure out why it's causing a problem.

Any help will be appreciated.

//#targetengine "ImportFolder"

//var myMainMenu = app.menus.item("Main");
//var myCustomMenu = myMainMenu.submenus.item("Import Folder");
//var myCustomMenu = myMainMenu.submenus.add("Import Folder");
//var mySampleScriptAction = app.scriptMenuActions.add("onInvoke", function() {
//app.doScript(new File ("/C/Program Files (x86)/Adobe/Adobe InDesign CS6/Scripts/Scripts Panel/importFiles.jsx" ));});

//delete the menu
var myMainMenu = app.menus.item("Main");
try{
var myCustomMenu = myMainMenu.submenus.item("Import Folder");
myCustomMenu.remove();
}catch(myError){}
Share Improve this question edited Apr 3, 2014 at 15:02 Ria S. asked Apr 3, 2014 at 14:34 Ria S.Ria S. 632 silver badges11 bronze badges 3
  • Which line is line 10? var myMainMenu = app.menus.item("Main");? – Kevin B Commented Apr 3, 2014 at 15:04
  • @KevinB: it should be, because the rest of this mini-script is protected against run-time errors with the try..catch construction. However ... purely theoretically, that line should not have failed; alert (myMainMenu.submenus.everyItem().name); works for me. – Jongware Commented Apr 3, 2014 at 15:13
  • This is not the only script that this is happening. On a second script I get the exact same message (undefined is not an object), on the very 1st line (var myDocument = app.documents.add();). – Ria S. Commented Apr 3, 2014 at 16:31
Add a ment  | 

1 Answer 1

Reset to default 7

Try re-installing Indesign. If the scripting library dll lost its registration, it could cause all of the scripts to fail.

...wait a minute - are you trying to use this script from the Extendscript Toolkit? If you are, you have to change engines.

Also, if you have more than one version of CS on your system, you need to make sure you use the Extendscript Toolkit that matches the version of your InDesign - in other words, EXTK CS6 for IND CS6.

Another thing to try is to remove the new from your doscript mand. I like to wrap mine in a function like this:

//run a script from the CS6 Script Panel Directory (be sure to add the file extension
function RunMyScript(whatscriptname){
    app.doScript(File("/C/Program Files (x86)/Adobe/Adobe InDesign CS6/Scripts/Scripts Panel/" + whatscriptname));
}
Post a comment

comment list (0)

  1. No comments so far