Skip to main content
Participating Frequently
May 21, 2021
Question

Scripting for adding a stroke to the text active or to texts that converted to outline

  • May 21, 2021
  • 1 reply
  • 1134 views

Dear All,

 

I've tried some ways to create a script that able to add a stroke into text or text that converted. I need a help for that, thanks..

 

Below is my current script:

#target illustrator

var sel = app.activeDocument.selection;

var obj = sel; // selected the text that I converted or text active.

for (var i = 0; i <obj.length; i++){ // I've tried some, like change "length" to groupItems, compoundPathItems, pathItems, even added the "length" after its (pathItems.length) and its doesn't work.

var textConvertedToOutline = obj[i];

textConvertedToOutline.stroked = true;

textConvertedToOutline.strokeWidth = 5;

textConvertedToOutline.strokeColor = textConvertedToOutline.fillColor;

}

 

This script only work to rectangle and if for text that converted to outline, I have to released it into compound path..

 

Thank you,

Regards,

Riko

This topic has been closed for replies.

1 reply

femkeblanco
Legend
May 21, 2021

I presume you mean expanded text, which becomes paths within compound paths within groups.

var sel = app.activeDocument.selection;
for (var i = 0; i < sel.length; i++){
    var compPaths = sel[i].compoundPathItems;
    for (var j = 0; j < compPaths.length; j++) {
        var paths = compPaths[j].pathItems;
        for (var k = 0; k < paths.length; k++) {
            paths[k].stroked = true;
            paths[k].strokeWidth = 5;
            paths[k].strokeColor = paths[k].fillColor;
        }
    }
}

 

Participating Frequently
May 22, 2021

@femkeblanco 

Thanks for ur solution, its work perfectly. 🙂

 

Btw, may I have 1 more help?

 

After trying ur script, it turned out I needed something else.. So can we make rectangle, text and expanded text given strokes in at once?

 

Thanks 

femkeblanco
Legend
May 22, 2021
var items = app.activeDocument.pageItems;
for (var i = 0; i < items.length; i++){
    if (items[i].selected == true) {
        if (items[i].typename == "TextFrame") {
            items[i].textRange.strokeWeight = 5;
            items[i].textRange.strokeColor = items[i].textRange.fillColor;
        } else {
            items[i].stroked = true;
            items[i].strokeWidth = 5;
            items[i].strokeColor = items[i].fillColor;
        }
    }
}