Script to save, close, reopen, and continue ("Error 8702: there is no document")
Hi all,
I'm trying to create a script which will allow me to save an Illustrator file, close it, reopen it, and continue working on it (in this case, add a layer). I've tried a number of different methods, but each one gives me an error ("8702: there is no document"). I'm guessing this is due to the document variable being reset once the document is reopened? I've tried a few different things, but can't seem to crack it:
Firstly I tried running it as a single function--
var doc = app.activeDocument
var docPath = app.activeDocument.fullName
app.executeMenuCommand("save");
app.executeMenuCommand("close");
app.open(new File(docPath));
var newLayer = doc.layers.add();
newLayer.name = "New";
Then I tried breaking it into seperate fucntions, with the variable redefined--
saveCloseReopen();
addLayer();
function saveCloseReopen(){
var doc = app.activeDocument
var docPath = app.activeDocument.fullName
app.executeMenuCommand("save");
app.executeMenuCommand("close");
app.open(new File(docPath));
}
function addLayer(){
var doc = app.activeDocument
var newLayer = doc.layers.add();
newLayer.name = "New";
}I tried using app.documents[0] instead of activeDocument to define the variable; I tried running app.activeDocument = doc after reopening, which I've had work in a similar Photoshop script. I've even tried writing each function as a seperate script, and calling them individually using $.evalFile -- I was really surprised this didn't work, but I'm still getting the error.
Any advice massively appreciated, I'm ready to pull my hair out at this point!!
Thanks in advance.
