Skip to main content
Participant
April 10, 2023
Question

Is the blend tool (specified steps) scriptable?

  • April 10, 2023
  • 6 replies
  • 1356 views

I'm creating a lot of rows of objects (sometimes the same number of items per row, sometimes different) and I just want to script creating two objects and then using the blend tool to create X elements in the row evenly spaced. Is this possible to do via ExtendScript? The documentation doesn't seem to have any info on whether this is possible or not. 

This topic has been closed for replies.

6 replies

femkeblanco
Legend
April 15, 2023

This snippet duplicates the topmost of two selected items and interpolates the duplicates inbetween.

if (app.selection.length == 2) {
    var x1 = app.selection[0].geometricBounds[0];
    var y1 = app.selection[0].geometricBounds[1];
    var x2 = app.selection[1].geometricBounds[0];
    var y2 = app.selection[1].geometricBounds[1];
    var dx = x2 - x1;
    var dy = y2 - y1;
    var a = Math.atan2(dy, dx)
    var n = +prompt("", "10", "Steps") + 1;
    var h = Math.sqrt(dx * dx + dy * dy) / n;
    dx = Math.cos(a) * h;
    dy = Math.sin(a) * h;
    for (var i = 0; i < n - 1; i++) {
        x1 += dx;
        y1 += dy;
        var dup = app.selection[0].duplicate();
        dup.selected = false;
        dup.position = [x1, y1];
    }
    app.selection[0].zOrder(ZOrderMethod.BRINGTOFRONT);
}

 

 

Legend
April 13, 2023

I have solved it with dynamic generation of actions as Kurt Gold says.

 

If you want to use AppleScript, you can achieve this by opening the blend option and then using System Events to simulate keystrokes. The script will be unstable and dependent on the situation, however.

tell application "Adobe Illustrator" to activate

tell application "System Events"
	tell application process "Adobe Illustrator"
		set sleep_seconds to 0.3
		delay sleep_seconds
		
		-- set smooth to step
		key code 49 -- space
		key code 125 -- arrow down
		keystroke return
		delay sleep_seconds
		
		-- set step
		keystroke "10"
		delay sleep_seconds
		
		-- ok
		keystroke return
	end tell
end tell
pixxxelschubser
Community Expert
Community Expert
April 12, 2023

Hi,

@CarlosCanto has experience with Applescript. But I fear that these options are not scriptable.

CarlosCanto
Community Expert
Community Expert
April 13, 2023

Hi @pixxxelschubser, no sorry, I'm not familiar with Applescript, I'm a Windows users, @sttk3 has provided an applescript below.

m1b
Community Expert
Community Expert
April 12, 2023

I have a script that does this, but with some limitations:

1. it doesn't actually create a blend object (the script does the interpolation itself).

2. it only works if the start and end path items have the same number of points.

3. it doesn't reorder the points, so it interpolates the first point of the start path with the first point of the end path, etc.

Would that work in your case?

- Mark

 

Edit: example usage.

Kurt Gold
Community Expert
Community Expert
April 11, 2023

You can create an action to do it and – if required – execute the action with a script.

app.doScript ("Action name", "Action Set name")

 

femkeblanco
Legend
April 10, 2023

You can't directly script blending.  But you can indirectly do so, through executeMenuCommand.  The first line brings up the options window; the second line makes the effect. 

 

app.executeMenuCommand("Path Blend Options");
app.executeMenuCommand("Path Blend Make");

 

If the options are set, you can do without the first line.  If you want to set the options, but don't want to interact with the window, and you're on Windows, you can use a temporary VBS script to interact with the window

Participant
April 10, 2023

I'm on a mac - is there any way to do it with applescript or javascript? 

femkeblanco
Legend
April 11, 2023

It's not possible with JavaScript.  I have no knowledge of AppleScript, but I've hardly seen anyone use it around here.