• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Give New File a name with Script

Engaged ,
Jun 23, 2021 Jun 23, 2021

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

 

TOPICS
Scripting

Views

722

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Participant , Jun 23, 2021 Jun 23, 2021

@BryanPagenkopf 

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);

Votes

Translate

Translate
Adobe
Community Expert ,
Jun 23, 2021 Jun 23, 2021

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. 

Screenshot 2021-06-23 at 13.07.36.png

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Jun 23, 2021 Jun 23, 2021

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.  

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advisor ,
Jun 23, 2021 Jun 23, 2021

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Jun 23, 2021 Jun 23, 2021

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Jun 23, 2021 Jun 23, 2021

Copy link to clipboard

Copied

Gersson,

 

That worked, however, the name is hardcoded and I would need to enter a job number.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Jun 23, 2021 Jun 23, 2021

Copy link to clipboard

Copied

@BryanPagenkopf 

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);

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Jun 23, 2021 Jun 23, 2021

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Jun 23, 2021 Jun 23, 2021

Copy link to clipboard

Copied

@BryanPagenkopf 

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  🙂

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Jun 23, 2021 Jun 23, 2021

Copy link to clipboard

Copied

LATEST

Love it!!!   Thank you!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advisor ,
Jun 23, 2021 Jun 23, 2021

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines