Copy link to clipboard
Copied
Hello everyone,
I'm trying to write a script that increases or decreases the width of strokes on shapes.
for now, what I came up with (found mostly on the internet a while ago), works fine for most shapes, and it can recurse into containers like groups, read their stroke width, and increase it by a certain percentage.
The problem remains with Live paint objects. I can't figure how to read their stroke width or how to change it. Any help would be appreciated!
Copy link to clipboard
Copied
Because Live Paint, like Compound Shape for scripts, is an "unknown" container of PluginItem. But from the outside, it's a PluginItem, and inside it's a GroupItem, which already has script access if you select one path with the Direct Selection Tool.
I tried this trick (check out video) on Live Paint but discovered another problem:
Copy link to clipboard
Copied
this seems to work well, all colors and stroke size are preserved
// scale Live Paint Stroke
function main() {
app.executeMenuCommand("Expand Planet X");
selection[0].resize (100, 100, true, true, true, true, 200, Transformation.CENTER); // scale strokes
app.executeMenuCommand("Make Planet X")
}
main();
Copy link to clipboard
Copied
Not bad Carlos!
Copy link to clipboard
Copied
I admit that the idea is creative 🙂 But the result in layers is not so pleasing
Copy link to clipboard
Copied
I admit that the idea is creative 🙂 But the result in layers is not so pleasing
By @Sergey Osokin
but that's the expected result when one expands a Livepaint group no? something has to give 😕
it's far from perfect like most things in illustrator scripting 😕
Copy link to clipboard
Copied
This is certainly the expected behavior after an expand. But I think users would like a magic pill so that Live Paint remains the original structure with only a modified stroke weight. This is something Adobe doesn't offer us in ExtendScript 😞
Copy link to clipboard
Copied
I've been waiting... hoping!... for someone to post an answer here, but I should tell you that as far as I know the scripting API doesn't expose much of the live paint object, if any. 😞
Edit: sorry didn't see Sergey's post.
Copy link to clipboard
Copied
I haven't tried it yet, but perhaps one may be able to script the following manual steps (possibly assisted by Mark's (m1b) LE_Functions suite):
- Select one or several Live Paint objects.
- Effect menu > Distort and Transform > Transform:
Copy link to clipboard
Copied
That seems like a good approach Kurt. I like that it doesn't interfere with the live paint object itself.
- Mark
Copy link to clipboard
Copied
Yes, the effect certainly allows us to increase the stroke width in Live Paint. But again, the downside is that once the effect is applied, we can't edit it again via script. It's a one-time automation, and then we have to manually edit the percentages in Appearance > Transform. In an ideal world, scripts should be able to dynamically change the width of strokes repeatedly 😞
(function (){
if (!app.selection.length || app.selection[0].typename !== 'PluginItem') return;
var scalePercent = 200;
var xml = '<LiveEffect name="Adobe Transform"><Dict data="R scaleH_Percent #1 R scaleV_Percent #2 R scaleH_Factor #3 R scaleV_Factor #4 R moveH_Pts 0 R moveV_Pts 0 R rotate_Degrees 0 R rotate_Radians 0 I numCopies 0 I pinPoint 4 B scaleLines 1 B transformPatterns 0 B transformObjects 0 B reflectX 0 B reflectY 0 B randomize 0 "/></LiveEffect>'
.replace(/#1/, scalePercent)
.replace(/#2/, scalePercent)
.replace(/#3/, scalePercent / 100)
.replace(/#4/, scalePercent / 100)
app.selection[0].applyEffect(xml);
})();
Copy link to clipboard
Copied
If you don't mind to use helper graphic styles, you may check this sample Illustrator file:
Using this snippet will scale the strokes of selected Live Paint objects by 200 %:
(function () {
var doc = app.activeDocument;
var sel = doc.selection;
var style = doc.graphicStyles.getByName("Scale_Live_Paint_Strokes_By_200_Percent");
for (var i = 0; i < sel.length; i++) style.applyTo(sel[i]);
})();
That would also work with an action or by just applying the graphic style manually (fastest method).
Find more inspiration, events, and resources on the new Adobe Community
Explore Now