2

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".

Chad
  • 1,708
  • 1
  • 25
  • 44

3 Answers3

3

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);
Chad
  • 1,708
  • 1
  • 25
  • 44
Yuri Khristich
  • 13,448
  • 2
  • 8
  • 23
1

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");
mdomino
  • 1,195
  • 1
  • 8
  • 22
  • 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 03 '20 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 03 '20 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 05 '20 at 04:26
1

Document can have name only after saving it once. And you can save the document as saveAs command as mentioned by @mdomino

Charu Rajput
  • 653
  • 3
  • 15