Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
Refer this url
Copy link to clipboard
Copied
Hi John,
What is the error that you get on the line you mentioned.
-Manan
Copy link to clipboard
Copied
Hi Manan,
the error reason is:
undefined is not an object
John
Copy link to clipboard
Copied
Hi,
I think jobFolder is not valid object ie., folder object. Please check the function "searchsubFolder" in your code.
Copy link to clipboard
Copied
yes,
may be undefined
rootFolder
but how can fix it?
John
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
yes, thank you Manan,
I even have not define
rootFolder
may be
rootFolder= rootFolder.match(/\d{5}/)
thanks
John
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
ok, thank you Sudha
thank so much.
John
Copy link to clipboard
Copied
Is is really your code?
Best Regards
Sunil
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
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.