Copy link to clipboard
Copied
Hello everyone and thank you in advance for your time.
I have been trying to figure this out on my own with very little javascript experience. I'll try to explain this as best as i can. A friend created a CSV file to use, created variables and created a batch from the action menu. The issue is, illustrator only gives us 'File + Number', 'File + Data Set Name' and 'Data Set Name' which isn't anything i want shown as the file name when i go to save. I would like certain layers saved as the file name. The variables create a number of different layers but i would like to use the layers 'invoice_#' and 'customer' as my file name so it would look something like this "123_customer.pdf". Is this possible with a script?
1 Correct answer
Try this:
var part1 = app.activeDocument.layers["Invoice_#"].textFrames[0].contents;
var part2 = app.activeDocument.layers["Customer"].textFrames[0].contents;
var address = "<u+202a>/C/Users/asparaccio/Desktop/" + part1 + "_" + part2;
var file1 = new File(address);
var PDF = new PDFSaveOptions;
app.activeDocument.saveAs(file1, PDF);
nbsp;rt
The last one only saved as "_.pdf" because the textFrames are not named (but showing their contents).ment.la nbsp;st
Explore related tutorials & articles
Copy link to clipboard
Copied
For clarification, please show us a screenshot of the Layers panel with the layer names. Or upload a sample file (without confidential data) to a host of your choice (e.g. Dropbox ...) and link to here.
Copy link to clipboard
Copied
Hello,
I attached a photo of the layers
Copy link to clipboard
Copied
The file name is the last part of the path. So you can use a layer's name as the last part of the path. For example, you can use the name of the layer which is active: (you will need to fill in "..." in your path)
var layer1 = app.activeDocument.activeLayer;
var address = "<u+202a>/C/Users/.../Desktop/" + layer1.name;
var file1 = new File(address);
var PDF = new PDFSaveOptions;
app.activeDocument.saveAs(file1, PDF);
nbsp;ye
Or you can use a joining of the names of the first and second layers:
var layer1 = app.activeDocument.layers[0];
var layer2 = app.activeDocument.layers[1];
var address = "<u+202a>/C/Users/.../Desktop/" + layer1.name + layer2.name;
var file1 = new File(address);
var PDF = new PDFSaveOptions;
app.activeDocument.saveAs(file1, PDF);
nbsp;ye
Et cetera. = app. nbsp;er (Of course, you can also enter the layers' names directly into the path if you want.)var add
Copy link to clipboard
Copied
Thank You for that. I didn't expand the layers and it's actually the sub layer information i need. Very sorry i didn't mention that before. I hope it doesn't make it harder.
Copy link to clipboard
Copied
var sublayer1 = app.activeDocument.layers[1].layers[0];
var sublayer2 = app.activeDocument.layers[2].layers[0];
var address = "<u+202a>/C/Users/.../Desktop/" + sublayer1.name + "_" + sublayer2.name;
var file1 = new File(address);
var PDF = new PDFSaveOptions;
app.activeDocument.saveAs(file1, PDF);
nbsp;bl
nbsp;bl
Copy link to clipboard
Copied
I copied the script (and entered my address) but i'm getting a Line 1 error:
Copy link to clipboard
Copied
So "1600" and "Peter" are not sublayers then, but items (of some type). So try this:
var item1 = app.activeDocument.layers[1].pageItems[0];
var item2 = app.activeDocument.layers[2].pageItems[0];
var address = "<u+202a>/C/Users/.../Desktop/" + item1.name + "_" + item2.name;
var file1 = new File(address);
var PDF = new PDFSaveOptions;
app.activeDocument.saveAs(file1, PDF);
nbsp;em
Edit:00m1 = nbsp;0m nbsp;0mFollowing what .activepixxxel_schubseractiveD said below, presuming these are textFrames, try this instead:m2 = ap nbsp;be (this won't work if contents is textFra>gt;is w1 line)won't w
nbsp;)w
var part1 = app.activeDocument.layers["Invoice_#"].textFrames[0].contents;
var part2 = app.activeDocument.layers["Customer"].textFrames[0].contents;
var address = "<u+202a>/C/Users/.../Desktop/" + part1 + "_" + part2;
var file1 = new File(address);
var PDF = new PDFSaveOptions;
app.activeDocument.saveAs(file1, PDF);
nbsp;rt
Copy link to clipboard
Copied
Hi @asparaccio,
thank you for the image.
@asparaccio wrote: "… but i would like to use the layers 'invoice_#' and 'customer' as my file name so it would look something like this "123_customer.pdf". Is this possible with a script?"
One question: Where the part "123_" comes from?
edited by pixxxel_schubser
Strange. My browser didn't show the last answers. Now I can see - the number is written in (the only) text frame in layer "Invoice_#"
Copy link to clipboard
Copied
Yes sorry, it's text. I tried the script but it only saves as "_.pdf". so i must be missing something.
var item1 = app.activeDocument.layers[1].pageItems[0];
var item2 = app.activeDocument.layers[2].pageItems[0];
var address = "<u+202a>/C/Users/asparaccio/Desktop/" + item1.name + "_" + item2.name;
var file1 = new File(address);
var PDF = new PDFSaveOptions;
activeDocument.saveAs(file1, PDF);
nbsp;em
Copy link to clipboard
Copied
You can get the required name in this way:
var aDoc = app.activeDocument;
var part1 = aDoc.layers.getByName("Invoice_#").textFrames[0].contents;
var part2 = aDoc.layers.getByName("Customer").textFrames[0].contents;
alert(part1+"_"+part2+".pdf")
Have fun
😉
Copy link to clipboard
Copied
I actually got this to work but it only shows in a dialogue box but doesn't actually save the PDF which is what i need.
Copy link to clipboard
Copied
Try this:
var part1 = app.activeDocument.layers["Invoice_#"].textFrames[0].contents;
var part2 = app.activeDocument.layers["Customer"].textFrames[0].contents;
var address = "<u+202a>/C/Users/asparaccio/Desktop/" + part1 + "_" + part2;
var file1 = new File(address);
var PDF = new PDFSaveOptions;
app.activeDocument.saveAs(file1, PDF);
nbsp;rt
The last one only saved as "_.pdf" because the textFrames are not named (but showing their contents).ment.la nbsp;st
Copy link to clipboard
Copied
Yes! that worked.. thank you so much!
Copy link to clipboard
Copied
Yes. That is how is works.
😉
My snippet gives you only the name you want, but nothing more so far.
There are still too many open questions:
Was your file already been saved under a different name? - As AI or as PDF?
What save options?
Should the complete file be saved under the name "part1_part2.pdf"? - Or just the layers as a new file?
Where? On the same file path as your other file?
Copy link to clipboard
Copied
The file is a template theat i'm working off of called invoice.pdf
It's a Save As:
Saved under the name "part1_part2.pdf" but also a new PDF file
Same file path
I am going to use the script in an action
Copy link to clipboard
Copied
😄
The problem was not to save the file. You can find dozens of methods here in the forum.
Glad that my snippet was helpful to find the wished name and helpful to complete the saving routine.
Copy link to clipboard
Copied
I was searching for 3 hours last night about something else and couldn't find a solution, so instead of figuring it out on my own (at work) i thought it would be easier to ask the experts and save some time. Thanks again!
Copy link to clipboard
Copied
Here is a small modification for saving in your wished path with the wished name. (Hope you are under Windows - like I said before: to little informations)
var aDoc = app.activeDocument;
var part1 = aDoc.layers["Invoice_#"].textFrames[0].contents;
var part2 = aDoc.layers["Customer"].textFrames[0].contents;
var address = aDoc.path + "/" + part1 + "_" + part2 + ".pdf";
var File2save = new File(address);
var PDFopts = new PDFSaveOptions;
app.activeDocument.saveAs(File2save, PDFopts);
If that works for you
have fun
😉

