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
That's a good question, I can't find it!
Copy link to clipboard
Copied
Save as PDF with Bleed...then re Save as Ai
[edit: please ignore, I should have tested it before posting]
Copy link to clipboard
Copied
Yes, problem is even setting it up for pdf export does absolutely nothing.
var dest = "~/Desktop/testme1.pdf";
var doc = app.activeDocument;
var myFile = new File(dest);
var saveOpts;
setSaveOptions();
saveFileToPDF(myFile);
function saveFileToPDF(myFile){
var originalInteractionLevel = userInteractionLevel;
userInteractionLevel = UserInteractionLevel.DONTDISPLAYALERTS;
doc.saveAs(myFile,saveOpts);
userInteractionLevel = originalInteractionLevel;
}
function setSaveOptions(){
saveOpts = new PDFSaveOptions();
saveOpts.compatibility = PDFCompatibility.ACROBAT5;
saveOpts.generateThumbnails = true;
saveOpts.optimization = true;
saveOpts.preserveEditability = true;
saveOpts.bleedOffsetRect = [2,2,2,2];
saveOpts.trimMarks = true;
}
After this media box is the size of trim marks but the art is cropped to the Artboard size, (not +2).
Copy link to clipboard
Copied
Bump,
Is there really no way to do this?
Copy link to clipboard
Copied
We must not give up the search
Copy link to clipboard
Copied
Matts, do you have Windows system? I can try to make a Win plugin which can be used by your script.
Well, to be honest, I made the one for testing purpose.The plugin sets bleeds from txt file.
You write some number to txt file with script, run action, bleeds change - voila.
But if you don't have win system, there's no point uploading this plugin.
Copy link to clipboard
Copied
What is a difference which would make your plugin Windows-only? To make it for Macs, would the entire code need to be re-written, or only certain parts?
Copy link to clipboard
Copied
The difference is I can compile for Windows only
But the C++ code for Mac should be the same.
The meaningful part of code is below.
int bleedOffset; //let the bleed be integer, why not
ifstream infile ("C:\\Tom_Subscriber\\data.txt"); //read the number from txt file. It's presumed that JS script has already written the number into it;
infile >> bleedOffset;
AIRealRect myRect;
//lets make bleeds symmetrical
myRect.right = bleedOffset;
myRect.left = bleedOffset;
myRect.top = bleedOffset;
myRect.bottom = bleedOffset;
error = sAIDocument->SetDocumentBleeds (myRect); // command to set bleeds.
As you can see, there's no dialog, input from txt file.
The plugin adds a command to the Objects menu.
Copy link to clipboard
Copied
Okay thank you for showing this. So, can you also say one more thing, which is: in order to make this in Mac, what would you need to do to be able to compile? You'd have to buy a mac computer?
Copy link to clipboard
Copied
The other option is to install Xcode in virtual machine or Hackintosh.
Copy link to clipboard
Copied
Hi, instead of read data from file, is it possible to sendScriptMassage to your plugin in script, so the plugin can use received data to do the job automatically?
Copy link to clipboard
Copied
Never used sendScriptMessage, need to take a look.
Copy link to clipboard
Copied
"Make Javascript great again!"
That was hard, but once made, always can be made.
Copy link to clipboard
Copied
This is magic Tom, how do I use it?
Copy link to clipboard
Copied
Good news is that it's possible to implement for scripting any feature, offered by SDK(pixel calculation, dividing bezier curves, finding duplicates etc).
For example, you can write pixel calculation in plugin, make it available for scriptmessage. Then you just run, say, such a string:
colorTextString = app.sendScriptMessage ("PluginName", "Calculate_average", "");
and get average color for gradient object or rasterimage (in text string, but it's no problem to parse it).
Keep in mind, that sendscriptmessage can not only send information to plugin, but also receive.
Bad news: plugins are platform-dependent and currently I can compile for Win only.
Copy link to clipboard
Copied
I like the good news . So is it possible to implement these missing features, that Adobe do not provide, all in one plugin(say, call it ScriptingHelper), for the rest of us?
If true, maybe it's time for us to vote which features should be added prior to others.
Copy link to clipboard
Copied
2moluaple:
Seems it's possible (with native limitations of SDK).
The code in C++ is simple:
if (strcmp(selector, "Selector1") == 0){
//do one function
}
else if (strcmp(selector, "Selector2") ==0)
{
//do 2nd
}
etc.
So one can just send different selectors to plugin to run different functions.
Copy link to clipboard
Copied
agree with others, this is fantastic and promising. Thanks for sharing tom.
Copy link to clipboard
Copied
Keep in mind, that sendscriptmessage can not only send information to plugin, but also receive.
Cool, this means that a script can know whether a plugin action was successful and other data, in order to proceed with the script logic. Something that is not inherently available for use in app.executeMenuCommand() and Actions.
Copy link to clipboard
Copied
Tom, so could you send a link to compiled plugin version where I could send bleed size via app.sendScriptMessage?
Copy link to clipboard
Copied
Win64, CC-CC2015.
Usage:
app.sendScriptMessage ("My_plugin_name", "mySelector", 15); // where 15 is bleedoffset in points.
Copy link to clipboard
Copied
Copy link to clipboard
Copied
HOw much would it cost for you guys to do all the hard work and make me a plugin for both Windows and Mac that we can send our requests for and you add those commands to the plugin?
We need bleeds, we need other impossible stuff like seeing in some art has an opacity mask on it or not (without undoing the mask via actions, etc etc).
I mean, I think I can maybe learn how to finally set up my xcode, and hopefully I soon will to try these babies out!
Copy link to clipboard
Copied