So blends have some annoying, unconfigurable behavior: if you have open paths in your blend then Illustrator won't automatically create a blend spine, and it insists on checking "knockout group" on the blend, which I almost never want. I have a script that attempts to work around this. It saves the open/closed state of every selected path, makes them all closed, calls object>blend>make, unchecks knockout group, and attempts to restore the original open/closed state (but this doesn't seem to take any more). Then it calls object>blend options. Because I almost inevitably do that after creating a blend. And this is where things get weird: the instant I start poking at the options in that window, everything my script did is *undone*. What the heck is going on here? (And why does my loop that is supposed to restore the open/closed state of each path not seem to do anything half the time, either?) // blend properly
#target Illustrator
#targetengine main
function Main(curDoc, sel, amountofselectedobjects) {
// we just fail silently if <2 paths are selected,
// just like the normal blend operation
if (amountofselectedobjects >= 2) {
firstPath = sel[0];
pathClosed = new Array();
// record closed/open state of all paths, close them all
for (var i = 0; i < amountofselectedobjects; i++) {
pathClosed [i] = sel[i].closed;
sel[i].closed = true;
// alert (pathClosed[i]);
}
app.executeMenuCommand('Path Blend Make');
// Illustrator thinks blends should default to having 'knockout group' turned on and I never want this.
firstPath.parent.parent.artworkKnockout = KnockoutState.DISABLED;
// attempt to restore closed/open status
// why does everything stay closed
// even though my diagnostic alert returns a few 'false'es
for (var i = 0; i < amountofselectedobjects; i++) {
sel[i].closed = pathClosed [i] ;
alert (pathClosed[i]);
}
// I would like to immediately pop up the blend options but for some reason
// this undoes the blend creation when I start cursoring around
// in the blend options window, wtf.
app.executeMenuCommand('Path Blend Options');
}
}
// initial setup: check for open document, fail quietly or invoke main function
if ( app.documents.length > 0 ) {
var curDoc = app.activeDocument;
var sel = curDoc.selection; // get selection Pageitems
var amountofselectedobjects = sel.length;
Main(curDoc, sel, amountofselectedobjects);
}
(also happy slightly belated seventh birthday to my uservoice request regarding this behavior) Thanks for any wisdom y'all have to bring to this problem. 🙂
... View more