Link in Zwischenablage kopieren
Kopiert
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.
Link in Zwischenablage kopieren
Kopiert
That's a good question, I can't find it!
Link in Zwischenablage kopieren
Kopiert
Save as PDF with Bleed...then re Save as Ai
[edit: please ignore, I should have tested it before posting]
Link in Zwischenablage kopieren
Kopiert
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).
Link in Zwischenablage kopieren
Kopiert
Bump,
Is there really no way to do this?
Link in Zwischenablage kopieren
Kopiert
We must not give up the search
Link in Zwischenablage kopieren
Kopiert
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.
Link in Zwischenablage kopieren
Kopiert
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?
Link in Zwischenablage kopieren
Kopiert
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.
Link in Zwischenablage kopieren
Kopiert
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?
Link in Zwischenablage kopieren
Kopiert
The other option is to install Xcode in virtual machine or Hackintosh.
Link in Zwischenablage kopieren
Kopiert
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?
Link in Zwischenablage kopieren
Kopiert
Never used sendScriptMessage, need to take a look.
Link in Zwischenablage kopieren
Kopiert
"Make Javascript great again!"
That was hard, but once made, always can be made.
Link in Zwischenablage kopieren
Kopiert
This is magic Tom, how do I use it?
Link in Zwischenablage kopieren
Kopiert
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.
Link in Zwischenablage kopieren
Kopiert
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.
Link in Zwischenablage kopieren
Kopiert
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.
Link in Zwischenablage kopieren
Kopiert
agree with others, this is fantastic and promising. Thanks for sharing tom.
Link in Zwischenablage kopieren
Kopiert
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.
Link in Zwischenablage kopieren
Kopiert
Tom, so could you send a link to compiled plugin version where I could send bleed size via app.sendScriptMessage?
Link in Zwischenablage kopieren
Kopiert
Win64, CC-CC2015.
Usage:
app.sendScriptMessage ("My_plugin_name", "mySelector", 15); // where 15 is bleedoffset in points.
Link in Zwischenablage kopieren
Kopiert
Link in Zwischenablage kopieren
Kopiert
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!
Link in Zwischenablage kopieren
Kopiert