You should spend some time on reading what you write:
var doc = app.documents.add(null,width,height);
reads:
- from application
- take the documents container
- add a new document
- that we shall call doc from now on
But that's not actually what you want to do you want to:
var f = new File("E:/project/AH_Portrait.ai");
var doc = app.open(f);
reads:
- Find file
- that we shall call f
- open this file in application as document
- let use call this document doc from now on
Ok, then the rest of the code works fine. However, there is a few caveats. The handle app is not universally defined to mean Illustrator! So usually you would put the line
#target illustrator
on the first line of your script. Second illustrator height coordinates are positive upwards. So [20,height-50]
is actually above your image on most illustrator versions (yeah the 0, 0 used to be in lower left corner back in the day). You should probably do [20,-height+50]
instead, but I'm not sure (possibly [20, -50]
).
Now then your script becomes:
#target illustrator
var height = 100;
var f = new File("E:/project/AH_Portrait.ai");
var doc = app.open (f)
var text1 = doc.textFrames.pointText( [20,-height+50] );
text1.contents = "Handgloves";
Off course this does not save your result.