Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

help for fix script

Contributor ,
Jan 28, 2019 Jan 28, 2019

Hi experts,

my script like this:

var userChoice = mDialog (),
//||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
mRoot = "/C/Job/",
normalScript = File("C:/Job/script/Normal-AD.jsxbin"),
cleanSaveScript = File("C:/Job/script/Normal-Cir.jsxbin"),
cleanNoSaveScript = File("C:/Job/script/Normal-IR.jsxbin");
//||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
openFiles (userChoice);
//
if (userChoice.book) {
myBooks = app.books.everyItem().getElements(); 
  for (var k = 0; k < myBooks.length; k ++)  
  myBooks.updateAllNumbers(); 
}
//
switch(userChoice.option)
{
case 0: app.doScript( normalScript, ScriptLanguage.JAVASCRIPT , [] ); break;
case 1: app.doScript( cleanSaveScript, ScriptLanguage.JAVASCRIPT , [] ); break;
case 2: app.doScript( cleanNoSaveScript, ScriptLanguage.JAVASCRIPT , [] ); break;
};
//
function mDialog ()
{
  var
  resObj = {
   job: "",
   type: 0,
   option: 0,
   book: false},
  mAlert = "This job number can't be found",
  w1 = new Window("dialog","Open Jobs and Gen PDF", undefined, {closeButton: false}),  
   mPanel = w1.add("panel", undefined, "Job number?"),
   mSpace = mPanel.add("group",[0,0,20,2]),
   mEdit = mPanel.add("edittext", undefined,""),
   mRadio1 = mPanel.add("group"),
    mE = mRadio1.add("radiobutton", undefined, "Eng"),
    mC = mRadio1.add("radiobutton", undefined, "Chi"),
    mEC = mRadio1.add("radiobutton", undefined, "E && C"),
   mLine = mPanel.add("panel",[0,0,250,2]),
   mCheck = mPanel.add("checkbox", undefined, "Book Update All Numbers"),
   mRadio2 = mPanel.add("group"),
    mS0 = mRadio2.add("radiobutton", undefined, "Ignore"),
    mS1 = mRadio2.add("radiobutton", undefined, "Clean Save"),
    mS2 = mRadio2.add("radiobutton", undefined, "Clean No Save"),
   mButtons = mPanel.add("group"),
   mCan = mButtons.add ('button', undefined, "取り消す", {name:"Cancel"}),
   mOK = mButtons.add ('button', undefined, "OK", {name:"OK"});
// dialog formats
   w1.location = [150,150];
   mEdit.minimumSize = [170,20];
   mPanel.alignment = "left";
   mRadio1.alignment = mRadio2.alignment = mCheck.alignment = "left";
   mButtons.alignment = "center";
   mLine.aligment = "fill";
   mEdit.characters = 5;
   mRadio1.spacing = 50;
// init
mE.value = mS0.value = true;
mEdit.active = true;
//
if (w1.show() == 1) {
  if (mC.value) resObj.type = 1;
  if (mEC.value) resObj.type = 2;
  if (mS1.value) resObj.option = 1;
  if (mS2.value) resObj.option = 2;
  if (mCheck.value) resObj.book = true;
  resObj.job = mEdit.text;
  return resObj;
  }
else exit();
}
function openFiles (userChoice)
{
started = false;
mFound = false;
mFolds = [];
var
  mDest = null,
  jobFolder = searchsubFolder (Folder(mRoot), userChoice.job),
  eFolder,cFolder,ecFolder, engDoc, chiDoc, biDoc,
  docArr = bookArr = [],
  mFiles = jobFolder.getFiles("*.indd"),
  cFile;

  if (userChoice.type == 2) {
   while(cFile = mFiles.pop())
    if(cFile.name.match(/^*[eE]&[cC]\.indd/) )
     biDoc = app.open(cFile);
    if (!engDoc) {
     started = false;
     mFound = false;
     mFolds = [];
     ecFolder = searchsubFolder (jobFolder, "E&C");
     mFiles = ecFolder.getFiles("*.indb");
     while(cFile = mFiles.pop())
      biDoc = app.open(cFile);
     if (!biDoc) {
      mFiles = ecFolder.getFiles("*.indd");
      while(cFile = mFiles.pop())
       biDoc = app.open(cFile);
      }
     }
   }
  if (userChoice.type == 0 || ( userChoice.type == 2 && !biDoc ) ) {
   while(cFile = mFiles.pop())
    if(cFile.name.match(/^*[eE]\.indd/) )
     engDoc = app.open(cFile);
   if (!engDoc) {
    started = false;
    mFound = false;
    mFolds = [];
    eFolder = searchsubFolder (jobFolder, "Eng"),
    mFiles = eFolder.getFiles("*.indb");
    while(cFile = mFiles.pop())
     engDoc = app.open(cFile);
    if (!engDoc) {
     mFiles = eFolder.getFiles("*.indd");
     while(cFile = mFiles.pop())
      engDoc = app.open(cFile);
     }
    }
   }
  if (userChoice.type == 1 || ( userChoice.type == 2 && !biDoc ) ) {
   while(cFile = mFiles.pop())
    if(cFile.name.match(/^*[cC]\.indd/))
     chiDoc = app.open(cFile);
   if (!chiDoc) {
    started = false;
    mFound = false;
    mFolds = [];
    cFolder = searchsubFolder (jobFolder, "Chi"),
    mFiles = cFolder.getFiles("*.indb");
    while(cFile = mFiles.pop())
     chiDoc = app.open(cFile);
    if (!chiDoc) {
     mFiles = cFolder.getFiles("*.indd");
     while(cFile = mFiles.pop())
      chiDoc = app.open(cFile);
     }
    }
   }
}
function searchsubFolder(rootFolder, searchName)
{
    var
   mFiles = rootFolder.getFiles(),
   cFile;
  if( !mFound ) {
   if (started){
     mFolds.splice(0,1) ;
     }

   while ( cFile = mFiles.pop() )
     if (cFile instanceof Folder){
      if (cFile.displayName.match(searchName)) {
       mFound = true;
       mDest = cFile;
       break;
       }
       mFolds.push(cFile) ;
       }
     
   started = true ;
   if (mFolds.length >> 0)
    searchsubFolder(mFolds[0],searchName);
   }
  }

the function: find and open docs then do script by job number.

but it error on line: 83

  mFiles = jobFolder.getFiles("*.indd"),

how can I fix.

thanks

regard

John

TOPICS
Scripting
899
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Jan 28, 2019 Jan 28, 2019
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 28, 2019 Jan 28, 2019

Hi John,

What is the error that you get on the line you mentioned.

-Manan

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Jan 28, 2019 Jan 28, 2019

Hi Manan,

the error reason is:

undefined is not an object

John

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Jan 29, 2019 Jan 29, 2019

Hi,

     I think jobFolder is not valid object ie., folder object.  Please check the function "searchsubFolder" in your code.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Jan 29, 2019 Jan 29, 2019

yes,

may be undefined

rootFolder

but how can fix it?

John

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 29, 2019 Jan 29, 2019

John its difficult to help unless we get to know what you are trying to do. I see you are searching for a folder in /c/Job folder what is the logic for the search? You need to debug your code in the method as mentioned, to pinpoint the area where your logic fails and maybe share that information with us to give you some suggestions.

One thing i can see is that you are using mFound in your searchSubFolder within an if, but its never defined inside this method neither is it a global variable. Is it what you intended or did you intend to pass it as an argument to the method.

-Manan

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Jan 29, 2019 Jan 29, 2019

yes, thank you Manan,

I even have not define

rootFolder

may be

rootFolder= rootFolder.match(/\d{5}/)

thanks

John

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Jan 30, 2019 Jan 30, 2019

Check your "searchsubFolder" function because its recursive function but you used to assign the return value of this function to jobFolder. Something is wrong there. Hence its throwing the undefined error.

I think that you have to use global variable for jobFolder and proceed get files when it is not null or undefined.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Jan 30, 2019 Jan 30, 2019

ok, thank you Sudha

thank so much.

John

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
Feb 01, 2019 Feb 01, 2019

Is is really your code?

Best Regards

Sunil

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Feb 03, 2019 Feb 03, 2019

Hi Manan,

Could you please leave a mail address to me.

I will show you the details and my goal.

my email:

[personal information, removed by moderator]

thanks

regard

John

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 03, 2019 Feb 03, 2019

Hi John,

You can PM me on the forum, hover over my name and you would find a message button that you can use to send me a message. I have removed your email id from the post, as it can be a potential for being exploited by spammers.

-Manan

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Feb 04, 2019 Feb 04, 2019
LATEST

Line 3 doesn't look right.

mRoot = "/C/Job/", 

Shouldn't that be... ???

mRoot = "C:/Job/",

/C/Job/ is likely an invalid path, which causes the var 'jobFolder' result to be invalid (undefined) on line 80.

William Campbell
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines