Collectives™ on Stack Overflow
Find centralized, trusted content and collaborate around the technologies you use most.
Learn more about Collectives
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
Learn more about Teams
Ask Question
Everytime I run my script and add a document the default filename is "Untitled-x*". I would like to be able to provide a default name for the document. Is there a way to do this using Extendscript?
Here is how I'm adding a Document currently:
var doc = app.documents.add(DocumentColorSpace.RGB, width, height, 1);
I was hoping for a parameter to provide a name, but the Javascript Illustrator Extendscript PDF reference doesn't show anything under "Document".
There is the object DocumentPreset
it has the property title
. Here's how it works:
var docPreset = new DocumentPreset;
docPreset.colorMode = DocumentColorSpace.RGB;
docPreset.title = "Your Title Is Here";
docPreset.width = width;
docPreset.height = height;
// Startup Preset Options:
// 0 - Print
// 1 - Film & Video
// 2 - Web
// 3 - Art & Illustration
// 4 - Mobile
// 5 - Film and Video
var presetArt = app.startupPresetsList[3];
var doc = app.documents.addDocument(presetArt, docPreset);
The reference you linked shows a name
property for the Document
object, but as you can see, it is readonly. In cases like this, it often helps to think about how the same thing is achieved in the UI.
The only way to name an Illustrator document in Illustrator's UI is to save it somewhere under a certain name. And that's exactly what you will have to do in your script as well:
var doc = app.documents.add(DocumentColorSpace.RGB, width, height, 1);
doc.saveAs(File("~/Desktop/myIllustratorDoc.ai");
–
–
–
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.