Skip to main content
egypturnash
Community Expert
Community Expert
August 1, 2025
Resuelto

Why is my script undoing half its work before it's done?

  • August 1, 2025
  • 2 respuestas
  • 919 visualizaciones

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. 🙂

Mejor respuesta de CarlosCanto

redraw the canvas to commit your changes right before you show the options

app.redraw();

 

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]);
	}
	
    app.redraw();
    
	// 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);
}

2 respuestas

CarlosCanto
Community Expert
Community Expert
August 2, 2025

by the way, I don't see the no-spine problem while blending open paths. I'm on Windows 11, Illustrator 29.6. So you might streamline your script if you don't have the problem either.

egypturnash
Community Expert
Community Expert
August 2, 2025

Mac 14.7, Illustrator 29.3, and I've been having the no-spline problem for years. Still have it. Maybe it finally got fixed somewhere in the last few point releases. That'd be a nice surprise! That's the whole reason this script exists.

 

(Or maybe it isn't fixed, I just checked the 29.7 prerelease sitting on my machine and it's still doing this. Oh joy, do I feel like doing the nuke-my-prefs dance to see if that fixes it. I do not. Maybe the next time this script breaks. 🙂 )

Monika Gause
Community Expert
Community Expert
August 4, 2025

Once upon a time, I seem to recall that I always got a spline, no matter what. Then it changed. I can't tell you when it changed as this was long before any versions that will still run on a modern Mac; the oldest one I can run right now is 2019 and it does this. If I was going to make a guess as to when it stopped working it'd probably be CS6, when the UI rewrite broke some other stuff like the wonderful Export panel we used to have.

 

I could be wrong, I could very well get a Classic Mac emulator up and running and fire up Illustrator 8 (my first version) and discover that it, too, does this, and that I was sighing and manually adding a blend spline to open-path blends for the entire time I've been using this thing until I finally wrote the first version of this script a couple years ago. 🙂


In 2004 I participated in a quiz, run by an Adobe staff person on their personal blog. So I assume they have checked all their questions with the devs. 

 

The 4 cases of no spine were one of the questions:

 

A) If there are at least three paths selected, and at least one of them is an open, unstroked, unfilled path, and at least two of them are not, then the open unpainted path is used as an initial spine and the other objects are moved onto it.

B) If the bounding box of the anchor points of each object encloses the bounding box of the anchor points of all the objects above it in the stacking order, then no spine path is created. (This is the ‘nested objects’ case.)

C) all centers are enclosed in the intersection that is built by of all objects

D) If all of the objects are open paths.

CarlosCanto
Community Expert
CarlosCantoCommunity ExpertRespuesta
Community Expert
August 2, 2025

redraw the canvas to commit your changes right before you show the options

app.redraw();

 

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]);
	}
	
    app.redraw();
    
	// 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);
}
egypturnash
Community Expert
Community Expert
August 2, 2025

Thanks, that did the trick! ❤️