Copy link to clipboard
Copied
Hi All,
I'm writing a function to change the artboard size and add bleed depending on certain conditions.
I can't actually believe this is causing me trouble but here it is, I'm trying to set the bleed dimensions in AI document with Javascript. All I've found so far is setting up PDF export options or print options, but not the actual artboard Document Setup. I just want to be able to set bleed to a newly created document like in this window:
So similar to Indesign:
with(myDocument.documentPreferences){
documentBleedUniformSize = true;
documentBleedTopOffset = 7;
}
(CC2017)
Summarizing best solution by far: we can change bleed size using preinstalled plugin.
Windows
https://goo.gl/YE1Vah by tomr11694738
Drop plugin in ProgramFiles\Adobe\Adobe Illustrator\Plug-ins\Extensions. Use following code to run it:
app.sendScriptMessage ("My_plugin_name", "mySelector", bleeds);
where bleeds is bleedoffset in points.
Mac
GitHub - ten-A/Bleed by Ten A
All hail to these two dudes.
Copy link to clipboard
Copied
The problem is sendscriptmessage cant directly pass arthandle to plugin. So the only workaround is to pass selection, then plugin catches selection and checks for needed conditions.
Copy link to clipboard
Copied
Tom, is there a way to compile Win32 or even bit-independent version of your plug-in?
Copy link to clipboard
Copied
WIn32:
app.sendScriptMessage ("My_plugin_name", "Bleed", 15);
//some test selectors
app.sendScriptMessage ("My_plugin_name", "ifMasked", 0); // checks selected object for opacity mask; returns string "is masked" or "is NOT masked"
app.sendScriptMessage ("My_plugin_name", "countSelection", 0); // returns num of all selected objects
Copy link to clipboard
Copied
No Tom, unfortunately it's running on a Mac, and has to be cross-platform.
Copy link to clipboard
Copied
Another possible way with script:
- Save document uncompressed so that we can parse the bleed data, and close it.
- Open and read the saved file, use this regex to replace the bleed value: ([\d.]*)(?= /Real \(Bleed(Left|Right|Top|Bottom)Value\))
, then save it. Note that the bleed value are in point unit.
- Now the bleed changed, open it in Illustrator again, and save it compressed if needed.
Copy link to clipboard
Copied
I changed your regexp to this because it was putting my bleed single-digit value in 2x:
/((\d{1,2}))(?= \/Real \(Bleed(Left|Right|Top|Bottom)Value\))/g
Here is the function:
function setBleed(doc, bleed, newName){
/*
Thanks to moluapple.
bleed in points
*/
var opts = new IllustratorSaveOptions();
opts.compressed = false;
opts.pdfCompatible = false;
doc.saveAs(File(newName), opts);
var f = app.activeDocument.fullName;
var contents;
f.open('r');
contents = f.read();
f.close();
contents = contents.replace(/((\d{1,2}))(?= \/Real \(Bleed(Left|Right|Top|Bottom)Value\))/g, bleed);
f.open('w');
f.write(contents);
f.close();
app.activeDocument.close();
app.open(f);
var opts2 = new IllustratorSaveOptions();
opts2.compressed = true;
opts2.pdfCompatible = true;
app.activeDocument.saveAs(app.activeDocument.fullName, opts2);
}
Copy link to clipboard
Copied
I'm having trouble getting this function mentioned above to work (I marked where it fails) :
function setBleed(doc, bleed, newName){
/*
Thanks to moluapple.
bleed in points
*/
var opts = new IllustratorSaveOptions();
opts.compressed = false;
opts.pdfCompatible = false;
doc.saveAs(File(newName), opts);
var f = app.activeDocument.fullName;
var contents;
f.open('r');
contents = f.read();
f.close();
contents = contents.replace(/((\d{1,2}))(?= \/Real \(Bleed(Left|Right|Top|Bottom)Value\))/g, bleed);
f.open('w');
f.write(contents);
f.close();
app.activeDocument.close();
//THIS IS WHERE IT FAILS
app.open(f);
var opts2 = new IllustratorSaveOptions();
opts2.compressed = true;
opts2.pdfCompatible = true;
app.activeDocument.saveAs(app.activeDocument.fullName, opts2);
}
Did this work for you? I couldn't get this to work, and I can't use a plug-in for my script since the script will eventually be run on someone else's computer. If this solution ended up working for anyone then I might keep toying around with it to see if I can get it to work. When I run it Illustrator says that the new file is in an unknown format and so won't load. I get this problem essentially anytime I try to write to an illustrator file.
Copy link to clipboard
Copied
Let's see if the variable 'newName' that you are using contains some characters which cannot be used as a name of a file?
Copy link to clipboard
Copied
I don't think so. Here's how I call it:
setBleed(app.activeDocument,18,"~/Downloads/newdoc.ai");
This gives the error I was talking about before. My main question is whether it worked for you when you posted this function (this is just copied and pasted from your post). I just want to know if this is something I should keep trying to get to work, or if it's a lost cause.
Copy link to clipboard
Copied
It did work for me, but not quite so well because I'd get random file-read errors when trying to open the uncompressed file back up again. Possibly this was due to client's use of a plugin made by a company, which I did not have installed and which may not have made a difference if I had it installed either. Or, maybe it just happens with uncompressed files regularly when edited via my regexp.
However, try to use an absolute path to the file instead of a relative one and see if it works.
One quick way to get an absolute path from a relative one is to go File(File("~/Desktop/MyFile.ai).fsName);
Copy link to clipboard
Copied
Thanks. Changing the file name to the absolute path did not fix the problem, but it was helpful to understand what errors you were getting. I think I'll look into the other options on this thread.
Copy link to clipboard
Copied
Well, I tried it just now, (Mac) and it appears to work just fine with either an absolute or relative path.
I'm curious about any other variables which would make my system differ from yours which may yield the cause of this error.
Copy link to clipboard
Copied
Me too. Maybe I'll try it on a mac to see if that makes a difference, since you said that you got it to work on a mac. Are there any other system differences that you think might make a difference?
Copy link to clipboard
Copied
So what's your Ai version, is it the latest (cc2018 as of this moment) ?
Copy link to clipboard
Copied
Yes. It's Illustrator CC 2018.
Copy link to clipboard
Copied
I tried this script with Illustrator 2019 on Mac.
I was able to change the red bleeding box values to any single-digit value (0-9). Too bad that this value is in points - i.e. biggest red bleed I was able to create with this was 9 points = 3.175mm.
All my tried floating point values and 2 digit integers (e.g. 10) caused the file load to fail with error message
"The operation cannot complete because there isn't enough memory (RAM) available."
Note: When changing red bleed box values via Illustrator's UI, additionally the PDF Box values change. Changes on my tests were as follows:
Artbox stays the same
BleedBox -> 0.0, 0.0, original+2*bleed, original+2*bleed
CropBox -> 0.0, 0.0, original+2*bleed, original+2*bleed
MediaBox -> 0.0, 0.0, original+2*bleed, original+2*bleed
TrimBox -> bleed, bleed, original+bleed, original+bleed
Since Illustrator-originated changes work just fine, I am concluding that there is still some parameter in the .ai file which controls how the bleeding box variables are being treated.
Copy link to clipboard
Copied
Summarizing best solution by far: we can change bleed size using preinstalled plugin.
Windows
https://goo.gl/YE1Vah by tomr11694738
Drop plugin in ProgramFiles\Adobe\Adobe Illustrator\Plug-ins\Extensions. Use following code to run it:
app.sendScriptMessage ("My_plugin_name", "mySelector", bleeds);
where bleeds is bleedoffset in points.
Mac
GitHub - ten-A/Bleed by Ten A
All hail to these two dudes.
Copy link to clipboard
Copied
Here is a sample build for AI(Macintosh) ver.21 and later. You can download from the アプリケーション自動化総合コミュニティフォーラム (Japan) .
Commentary also available in [AI]Javascriptの機能を拡張する方法 (Sorry, its a Japanese article. However, you can translate via google...)
Copy link to clipboard
Copied
Just writing a note about this one. This plugin worked on Illustrator CC 2019 on Mac OS X 10.14.4.
Instructions:
1. Download and unzip Bleed.aip.zip mentioned here (or clone from github and compile. fun.)
2. Place the resulting Bleed.aip plugin to folder /Applications/Adobe Illustrator CC 2019/Plug-ins.localized/Extensions
3. Write a driver Javascript as follows:
$ cat script.js
alert (setBleed ( 51.0236 )); // unit: pt; range: 0-72.0
function setBleed (n) {
var result = app.sendScriptMessage ( 'Bleed', 'Bleed' , n);
return result;
}
4. Start Illustrator
5. Select menu File -> Scripts -> Other Script ...
6. Select the script you wrote on step #3
All this information has been available on this thread or linked threads. However, the exact needed steps seemed to be a bit scattered, so I thought writing this down will save my effort next time I'm having this problem.
Great thanks to the guys who took the effort to produce this plugin!
Copy link to clipboard
Copied
Hello,
Does anyone here have the Bleed.aip plugin for Mac OSX?
Regards,
Mike
Copy link to clipboard
Copied
Sorry but all these links are broken, is it still available somewhere?
Copy link to clipboard
Copied
I found the GitHub - ten-A/Bleed by Ten A
but I have no idea how to use this in Adobe Illustrator? Do I place it in a .jx scrpt?
I was using this .jx to create a new document:
var docPreset = new DocumentPreset;
docPreset.width = 8.5;
docPreset.height = 11;
docPreset.units = RulerUnits.Inches;
docPreset.artboardLayout = DocumentArtboardLayout.GridByCol;
docPreset.numArtboards = 1
var newDocument = app.documents.addDocument(DocumentColorSpace.CMYK, docPreset);
Not sure how to add a bleed
Copy link to clipboard
Copied
Tried to make 1.5 mm bleeds offset and got 1.411 mm... As well I can't make 1.5 pts offset, its always rounds it to 1. So plugin rounds the values by points, needs to be fixed.
Copy link to clipboard
Copied
This one did the job for 1.5 mm offset: app.sendScriptMessage ("My_plugin_name", "mySelector", "4,252");
Thank you, tomr11694738.