[JSX] problem setting fill color of selection (outlined text)

Adobe Community Professional ,
Apr 12, 2022 Apr 12, 2022

Copy link to clipboard


I always seem to have issues setting colors via script in Illustrator. This one is boggling me. I have outlined black text. Top selection is a group, with path items for each text underneath. I verified that the blush color is being created; I can see it in the swatch list of the document. But the colors are not changing. No errors, no alerts. Just nothing happens. To test, create a doc with lorem ipsum and create an outline, then select. Any thoughts? 


Edit: Disregard--found the error thanks to this thread: https://community.adobe.com/t5/illustrator-discussions/setting-fill-color-for-a-compound-path-via-sc...


I needed to check that the compound path item had sub pathitems to fill.  Updated the replaceColor script in case useful for anyone encountering the same issue. 



colors: {
    blush: {
        color: [1,8,7,0],
        name: "newSwatcheBLUSH",
        abbr: "bh",
        bgs: ["clear","white","black","jade","navy"],

//create named swatches for all the colors for easier recall during script later
var makeColors = function(doc) {
    for (var c in colors) {
        try {
            var s = doc.swatches.getByName(colors[c].name);
        } catch(e) {
            var col = new CMYKColor();
            col.cyan = colors[c].color[0];
            col.magenta = colors[c].color[1];
            col.yellow = colors[c].color[2];
            col.black = colors[c].color[3];
            var s = doc.swatches.add();
            s.color = col;
            s.colorType = ColorModel.PROCESS;
            s.name = colors[c].name;

var replaceColor = function(items, color) {
    for (var i = 0; i < items.length; i++) {
        try {
            items[i].filledOverprint = false;
            items[i].filled = true;
            items[i].fillColor = color;
        } catch(e) {
            $.writeln("Error filling");
        try {
            if (items[i].pageItems.length > 0) {
                replaceColor(items[i].pageItems, color);
        } catch(e) {
            $.writeln("Error recursing: " + items[i].typename + ": " + e);
        try {
            if (items[i].pathItems) {
                items[i].pathItems[0].fillColor = color;
        } catch(e) {
            $.writeln("Error with child compound");

var unitTest = function() {
    var col = app.activeDocument.swatches.getByName(colors.blush.name).color;
    replaceColor(app.activeDocument.selection, col);










Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
no replies

Have something to add?

Join the conversation