Skip to main content
Flowgun
Inspiring
December 1, 2025
Answered

How to set gradient/pattern by name to the default Fill?

  • December 1, 2025
  • 1 reply
  • 86 views

Hello everyone,
I'm trying to write a script that changes the default fill content. It is pretty straightforward for RGBColor and CMYKColor (and NONE), but I'm finding difficulty finding a way to place a gradient or a fill by name (they exist in the swatches so a if there's a way to set a swatch to the fill can be a solution.

Correct answer Flowgun

this worked

    var doc = app.activeDocument;
    var tmp = doc.pathItems.add();
    tmp.setEntirePath([[0,0],[0,0]]);
    tmp.filled = true;
    var sw = doc.swatches.getByName(patternName);
    tmp.fillColor = sw.color;
    doc.defaultFilled = true;
    doc.defaultFillColor = tmp.fillColor;
    tmp.remove();

1 reply

Flowgun
FlowgunAuthorCorrect answer
Inspiring
December 1, 2025

this worked

    var doc = app.activeDocument;
    var tmp = doc.pathItems.add();
    tmp.setEntirePath([[0,0],[0,0]]);
    tmp.filled = true;
    var sw = doc.swatches.getByName(patternName);
    tmp.fillColor = sw.color;
    doc.defaultFilled = true;
    doc.defaultFillColor = tmp.fillColor;
    tmp.remove();