添加链接
link管理
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接
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

When adding a Document in Adobe Illustrator's Extendscript is there a way to set it's name?

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");
                I think you're right, especially when thinking how you would do it via the UI. Except that when you create a new document in Illustrator, it'll ask you the document name (as well as dimensions) but I feel that Adobe hasn't given us that functionality through Extendscript yet. I think your answer is probably the next best thing.
– Chad
                Apr 3, 2020 at 22:53
                I was under the impression that you just wanted to create a document automatically with a predefined name. So you actually need the ExtendScript command to prompt you with the new Document window?
– mdomino
                Apr 3, 2020 at 23:08
                I do want to create a document automatically with a predefined name. I was just pointing out that the UI has a way to specify all that info when you create a document, but Extendscript doesn't (that I'm aware of).
– Chad
                Apr 5, 2020 at 4:26
        

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.