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

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

  • August 1, 2025
  • 2 replies
  • 919 views

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

Correct answer 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 replies

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

CarlosCanto
Community Expert
Community Expert
August 2, 2025

weird, perhaps it's a Mac only issue? I haven't seen other people report on it. Also, your UserVoice post didn't get much traction.

 

Does it happen if you blend open paths manually? 

CarlosCanto
Community Expert
CarlosCantoCommunity ExpertCorrect answer
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! ❤️