Scripting creation of a layer with fx attached?

How can I script creation of a layer with fx attached?

I’d like to

  1. create a layer above the current one
  2. add checkerboard generator fx
  3. set options of checkerboard (size 1, perhaps x value too)

I don’t see any examples that do this, they all seem to do permanent image changes rather than setting fx that will remain modifyable.

Here’s how you can do it with a script plugin:

function main(image, doc, layer) {
    
    var newLayer = doc.baseGroup().addBitmapLayer();
    
    doc.selectLayer(newLayer); // Private API, but needed to make the below work correctly. Will fix in 7.1.
    
    var params = {
        inputWidth: 12,
        inputColor0: CIColor.blackColor(),
        inputColor1: CIColor.whiteColor(),
    };
    
    newLayer.appendFilterWithName_parameters("CICheckerboardGenerator", params);
}
1 Like

Thanks Gus! I’ll try it out, looks great

Works a treat. Thanks again.

Where should I be looking for the docs that explain these mechanisms?

eg. appendFilterWithName_parameters

Where to look if I want to apply “Source Atop” blend mode?
edit: found that one at Acorn: Example AppleScript and JavaScript Scripts

I haven’t documented this one yet unfortunately. There’s a couple of new things I decided to open up but haven’t yet. I’ve added it to the todo list for 7.1

1 Like