Copy link to clipboard
Copied
hi guys,
Im currently trying to write a script for an assignment at Uni and I keep getting
"no such element"
var doc1=app.document[0];
I'm losing my mind!! Im new to scripting and to photoshop and I cant figure it out
please reply!!
Copy link to clipboard
Copied
For that line to work in Photoshop there has to be an open document. And from the error message I would bet there isn't.
Copy link to clipboard
Copied
You have missed the "s" in documents.
var doc1=app.documents[0];
Copy link to clipboard
Copied
I assumed the missing s was a typo in the post not the script itself. Otherwise the error message would have been 'undefined is not an object'. To get the 'no such element' message you need to try to access a document in the collection that doesn't exists. And if the first element doesn't exists that means there are no documents open.
Copy link to clipboard
Copied
app.preferences.rulerUnits = Units.PIXELS;
var doc1=app.documents[0];
var doc2=app.documents[1];
var doc3=app.documents[2];
var doc4=app.documents[3];
var newDoc = app.documents.add(2480, 3508, 300.0,
hi there- I just copied this from my script- the "s"missing was just a typo- sorry im just really stuck and running out of time to get this done!
Copy link to clipboard
Copied
Seems you are still having problems posting code, your last line is incomplete.
Try
alert(app.documents.length);
if( app.documents.length > 3 ){
app.preferences.rulerUnits = Units.PIXELS;
var doc1=app.documents[0];
var doc2=app.documents[1];
var doc3=app.documents[2];
var doc4=app.documents[3];
}else{
alert("you don't have enough documents open!");
}