Copy link to clipboard
Copied
I am trying to stop the script from running if No Documents are open.
I have a variable at the beginning of the script which reads... var docRef = app.activeDocument but it's throwing an error in ESTK if no document is open so I am trying to figure out a way to prevent the script from running if no document is open when the script is started.
I tried the following thinking that if the document length was greater then 0 then it would set the variable otherwise it would exit but this is wrong somewhere.
if(app.documents.length > 0){
var docRef = app.activeDocument
}else{
return;
}
try{
var docRef = app.activeDocument;
}
catch(e){
var noDocs = false;
}
if (noDocs== false){
alert ("You do not have a document open.")
}
else {
// run script
}
Copy link to clipboard
Copied
try{
var docRef = app.activeDocument;
}
catch(e){
var noDocs = false;
}
if (noDocs== false){
alert ("You do not have a document open.")
}
else {
// run script
}
Copy link to clipboard
Copied
Thank you, that has help me
Copy link to clipboard
Copied
Hi ian-barber,
'return' only works in a function.
Your own code should be:
areThereDocuments ();
function areThereDocuments () {
if (app.documents.length > 0) {
var docRef = app.activeDocument;
// your code
// alert (docRef.name);
} else {
alert ("no open document");
return;
}
}
Have fun