Copy link to clipboard
Copied
Hello,
I have a simple script that creates a new document and a couple of Layers. How would I add in code to be able to give the new document a name other than "Untitled-1"?
Thank you!
var myDocument = app.documents.add();
// PROD Layer
var prodLayer = myDocument.layers.add();
prodLayer.name = "PROD";
// SPEC Layer
var proofLayer = myDocument.layers.add();
proofLayer.name = "PROOF";
try this,
var doc = app.activeDocument;
var presets = app.startupPresetsList;
var preset = presets[0];
var enterName=prompt("Please Type document Name");
var docPreset = new DocumentPreset();
//add doc Name
docPreset.title = enterName;
var doc = app.documents.addDocument(preset, docPreset, false);
Copy link to clipboard
Copied
I am admittedly not strong in Illustrator Scripting but I would have assumed this to be necessary, alas apparently you need to define the name when saving the file.
The Documents-method »add« does not seem to include a »name«-parameter.
Copy link to clipboard
Copied
@c.pfaffenbichler is right. A document's "name" property is read-only. But if you save the document, you give it a file name.
Copy link to clipboard
Copied
Hello,
You can use the saveAs giving the file a path and name to save to.
var myDocument = app.documents.add();
// PROD Layer
var prodLayer = myDocument.layers.add();
prodLayer.name = "PROD";
// SPEC Layer
var proofLayer = myDocument.layers.add();
proofLayer.name = "PROOF";
myDocument.saveAs(File('~/Desktop/myDocument.ai'));
Regards,
Mike
Copy link to clipboard
Copied
hey @BryanPagenkopf
add new document with name, check out those lines maybe can help you!
var doc = app.activeDocument;
var presets = app.startupPresetsList;
var preset = presets[0];
var docPreset = new DocumentPreset();
//add doc Name
docPreset.title = "Nombre de documento";
var doc = app.documents.addDocument(preset, docPreset, false);
best Regards
Gersson Delgado
Copy link to clipboard
Copied
Gersson,
That worked, however, the name is hardcoded and I would need to enter a job number.
Copy link to clipboard
Copied
try this,
var doc = app.activeDocument;
var presets = app.startupPresetsList;
var preset = presets[0];
var enterName=prompt("Please Type document Name");
var docPreset = new DocumentPreset();
//add doc Name
docPreset.title = enterName;
var doc = app.documents.addDocument(preset, docPreset, false);
Copy link to clipboard
Copied
@GerssonDelgado would you know how to also code it so the Units are set to Inches? and the art board size would be 90" x 90"?
Copy link to clipboard
Copied
Check out this!
var doc = app.activeDocument;
var PTS_IN = 72;
var width = 90 * PTS_IN;
var height = 90* PTS_IN;
var presets = app.startupPresetsList;
var preset = presets[0];
var enterName=prompt("Please Type document Name");
var docPreset = new DocumentPreset();
//add doc Name
docPreset.title = enterName;
docPreset.units = RulerUnits.Inches;
docPreset.width = width;
docPreset.height = height;
var doc = app.documents.addDocument(preset, docPreset, false);
let me know any question 🙂
Copy link to clipboard
Copied
Love it!!! Thank you!
Copy link to clipboard
Copied
Hi Bryan,
I have added a prompt box for you to enter a job number.
var myJobID = prompt("Enter Job#","");
if(myJobID == null)
{
exit();
}
if(myJobID == "")
{
alert ("Error!\nNo Job# Entered.");
exit();
}
var myDocument = app.documents.add();
// PROD Layer
var prodLayer = myDocument.layers.add();
prodLayer.name = "PROD";
// SPEC Layer
var proofLayer = myDocument.layers.add();
proofLayer.name = "PROOF";
myDocument.saveAs(File('~/Desktop/'+ myJobID + '.ai'));
Regards,
Mike