Copy link to clipboard
Copied
Hi
im not much familiar with illustrator scripting languages, but i thought maybe i could ask if this kind of procedure is even possible in scripting.
I have ai files for different garments of clothing for example.
in the file there are the following layers>
Info
outline XS
outline S-M
outline L-XL
design XS
design S-M
design L-XL
the layer names stay the same in all files
would it be possible for a script to print the layers in the following way:
1) Prompt the user which sizes he wants to print ( tick a box for example?) + ask to add a prefix for the file.
2) use print preset "x"
3) 1st pdf: only layers: info, outline xs, design xs, named prefix--xs
2nd pdf only layers: info, outline s-m, design s-m, named prefix--s-m
3rd pdf: only layers: info outline l-xl, design l-xl, named prefix--l-xl
pdf-s can be placed in the same folder as the source file
is this possible, if not, could this be done via a plugin?
Copy link to clipboard
Copied
selecting multiple sizes now works
I still need to get the pdf-s printed
when i try to use the new File command in print job options, it gives me the correct file name, but corrupts the pdf.
when i use this, it corrupts the pdf
var printJobOptions= new PrintJobOptions();
var options = new PrintOptions();
options.jobOptions = printJobOptions;
printJobOptions.file= new File(doc.path + "/" + doc.name.split(".")[0] + "_L-XL.pdf");
var PP="PDF print";
options.printPreset=PP;
doc.print(options);
when i remove the new File joboptions, i get the prompt to name the file myself, and then the pdf is not corrupted. So i guess the problem is in the new filename line?
Copy link to clipboard
Copied
As I mentioned...yes it will give you a corrupted PDF file. The file being created is just a file. Not an actual native PDF.
I typically use this function when writing things like a log file that ends up being a .TXT.
There should be a way we can save your PDF using the same details as what you are trying to accomplish with the print method.
Can you screen shot your preset settings?
Copy link to clipboard
Copied
Ok, so i looked around a bit, and the correct answer seems to be that you can't print a pdf with a name. Just use save as and pdfoptions. Thanks for the awesome script!
The negative side is that when saving to pdf you cant determine a lot of settings you can when printing:media size, printer resolution, emulsion, these are just a few of many. so essentialy the save as pdf option becomes pointless. Or am i missing the part in pdf settings, where you can edit these?
Copy link to clipboard
Copied
Maybe someone can help with why printJobOptions does not let me choose multiple variables for the file name?
printJobOptions.name=(doc.name.split(".")[0] + "_L-XL.pdf");
when i try something like that, it just gives me the default file name. It only works then i enter one name. like this
printJobOptions.name= "--L-XL" no way to add a user entered prefix to here?
Copy link to clipboard
Copied
remove the brackets
printJobOptions.name = doc.name.split(".")[0] + "_L-XL.pdf";
Copy link to clipboard
Copied
it works, thanks!
Any way to change this to a variable that the user can type in before doing the sizes?
Copy link to clipboard
Copied
sure
add:
var size_name = "";
and use UI to enter a user defined value
printJobOptions.name = doc.name.split(".")[0] + "_" + size_name + ".pdf";
Copy link to clipboard
Copied
thanks, how can i add a "add prefix" row to the select size window, which gives the value to var size_name?
Copy link to clipboard
Copied
Update your script for the UI to this...
// Panel for size selection
var selectSizeWindow = new Window('dialog', "Select the size...");
var checkBoxGroup = selectSizeWindow.add("group");
checkBoxGroup.orientation = "row";
var isXS = checkBoxGroup.add('checkbox', undefined, "\u00A0XS");
var isSM = checkBoxGroup.add('checkbox', undefined, "\u00A0S - M");
var isLXL = checkBoxGroup.add('checkbox', undefined, "\u00A0L - XL");
var textBoxHeader = selectSizeWindow.add("group");
textBoxHeader.orientation = "row";
var labelText = textBoxHeader.add('statictext', undefined, "Add Prefix: ");
var textBoxGroup = selectSizeWindow.add("group");
var namePrefix = textBoxGroup.add('edittext', undefined, "");
namePrefix.preferredSize = [200, 23];
var buttons = selectSizeWindow.add("group")
buttons.add("button", undefined, "OK", {name: "ok"});
buttons.add("button", undefined, "Cancel", {name: "cancel"});
selectSizeWindow.show();
Then when you want to pull the value for that new field it needs to be like this....
namePrefix.text
Copy link to clipboard
Copied
So the line q3player wrote would look like this to include the user input field from the window...
printJobOptions.name = doc.name.split(".")[0] + "_" + namePrefix.text + ".pdf";
Copy link to clipboard
Copied
So, everything else is working now for me, but i have run into a new weird problem with the new file name.
This is how the name is entered, using 2 variables from the UI
printJobOptions.name=namePrefix.text + "--150-160" + nameSuffix.text;
When the user enters a Prefix that also has a . (dot) ( for example V65.5) in the name, the script stops the file name at the dot and no size and suffix are added to the name of the pdf.
Why does this happen? can i tell javascript to ignore it ?
Copy link to clipboard
Copied
A period does have specific meaning. Look at the script we have written so far... lots of them
So my suggestion would be to pass the users input for the file name to a variable.
Then replace the period by using a replace statement that will put an escape in (which should force the period to retain).
var passFormat = namePrefix.text;
passFormat = passFormat.replace(".", "\.");
Then use the variable passFormat in your file name statement
Copy link to clipboard
Copied
tried it like this, and it does not work, still cuts the name at the dot.
debug stops at the marked line
var printJobOptions= new PrintJobOptions();
var options = new PrintOptions();
options.jobOptions = printJobOptions;
var passFormat = namePrefix;
passFormat = passFormat.replace(".", "\."); //Debug stops on this line
printJobOptions.copies=1;
printJobOptions.name=passFormat+ "--XS" + nameSuffix.text;
var PP="PDF print";
options.printPreset=PP;
doc.print(options);
}
}
Copy link to clipboard
Copied
HHhhhmmm... What about something like this....
var checkName = namePrefix.text;
if(checkName.indexOf('.') !== -1)
{
// Contains a period
var formatName = checkName.split(".");
printJobOptions.name = formatName[0] + "." + formatName[1] + "--150-160" + nameSuffix.text;
}
else {
// Doesn't contain a period
printJobOptions.name = namePrefix.text + "--150-160" + nameSuffix.text;
}
Copy link to clipboard
Copied
var printfolder = "_PRINT"; // Suffix used for the folder where all files for the printer are collected
var imagefolder = "images"; // sub-folder for images
var pdfOption = 'PDFX3-Setting'; // Name of your PDF setting for printable PDF
var pdfOption2 = 'lowResPDF-Setting'; // Name of your PDF settings für preview only PDF
var aiSuff = '_cs6.ai'; // Suffix attached to the open AI file determining the version
var doc = app.activeDocument;
var arr = doc.name.split(".");
var extension = "";
if (arr.length>1) extension = "." + arr.pop();
var filename = arr.join("."); // base file name for all further steps
var foldername = filename; // defining the first part of name of the folder where all files for the printer are collected
foldername = foldername.replace(/RZ_/,""); // delete RZ_ in filename
foldername = foldername.replace(/\s/g,"_"); // replace Blanks with _
foldername = foldername.replace("ß","ss"); // replace ß with ss
foldername = foldername.replace("%","Pr"); // replace % with Pr
foldername = foldername.replace(/[^-a-zA-Z0-9._]/g,""); // discard all remaining special characters
var export_folder = "~/Desktop/" + foldername + printfolder; // name and place to save the folder
var assets_folder = new Folder (export_folder + "/" + imagefolder); // name and place for the sub-folder
var name_ai = filename + aiSuff;
var name_aizw = filename + aiSuff2;
var name_pdfprint = filename + pdfSuff;
var name_pdfpreview = filename + pdfSuff2;
var name_infofile = "_info_" + filename + ".txt";
Here's a snippet of one of my more complex scripts. It generates a base file name (line 9 ff.) Maybe this could be of use.
Copy link to clipboard
Copied
the var formatname option does not work
the bigger script is too hard for me to understand, or implement it to my code.
Find more inspiration, events, and resources on the new Adobe Community
Explore Now