• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

How do I Automatically apply Filter with a script?

Participant ,
Sep 17, 2024 Sep 17, 2024

Copy link to clipboard

Copied

I have a process in which I apply a filter to the specific active layer, I do it many times and I find that making a script would save me a lot of time. I think I could do it with an action but I'm doing other process together so finding out how to do it with a script would be much better for me.

How would I write a code that applies a filter to the selected active layer? Any filter? And how could I auto add the level of the filter on the script if it has any?

For example: If I wanna add a mosaic filter to the active layer and I want it to always have a cell size of 100, how could I incorporate that into a script?

TOPICS
Actions and scripting , Windows

Views

135

Translate

Translate

Report

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

correct answers 1 Correct answer

Community Expert , Sep 17, 2024 Sep 17, 2024

@HeyoThere 

 

Using legacy ExtendScript code, you can use DOM code for supported filters. Such as:

 

https://theiviaxx.github.io/photoshop-docs/Photoshop/ArtLayer.html

 

https://theiviaxx.github.io/photoshop-docs/Photoshop/ArtLayer/applyAddNoise.html#artlayer-applyaddnoise

 

app.activeDocument.activeLayer.applyAddNoise(10, NoiseDistribution.GAUSSIAN, true);

 

Or using legacy AM code recorded via the ScriptingListener plugin:

 

var idaddNoise = stringIDToTypeID( "addNoise" );
    var desc187 = ne
...

Votes

Translate

Translate
Adobe
Community Expert ,
Sep 17, 2024 Sep 17, 2024

Copy link to clipboard

Copied

@HeyoThere 

 

Using legacy ExtendScript code, you can use DOM code for supported filters. Such as:

 

https://theiviaxx.github.io/photoshop-docs/Photoshop/ArtLayer.html

 

https://theiviaxx.github.io/photoshop-docs/Photoshop/ArtLayer/applyAddNoise.html#artlayer-applyaddno...

 

app.activeDocument.activeLayer.applyAddNoise(10, NoiseDistribution.GAUSSIAN, true);

 

Or using legacy AM code recorded via the ScriptingListener plugin:

 

var idaddNoise = stringIDToTypeID( "addNoise" );
    var desc187 = new ActionDescriptor();
    var iddistort = stringIDToTypeID( "distort" );
    var iddistort = stringIDToTypeID( "distort" );
    var iduniformDistribution = stringIDToTypeID( "uniformDistribution" );
    desc187.putEnumerated( iddistort, iddistort, iduniformDistribution );
    var idnoise = stringIDToTypeID( "noise" );
    var idpercentUnit = stringIDToTypeID( "percentUnit" );
    desc187.putUnitDouble( idnoise, idpercentUnit, 10.000000 );
    var idmonochromatic = stringIDToTypeID( "monochromatic" );
    desc187.putBoolean( idmonochromatic, true );
    var idFlRs = charIDToTypeID( "FlRs" );
    desc187.putInteger( idFlRs, 204982 );
executeAction( idaddNoise, desc187, DialogModes.NO );

 

 Some filters are not available in the DOM and can only be run via AM code:

 

var idmosaic = stringIDToTypeID( "mosaic" );
    var desc207 = new ActionDescriptor();
    var idcellSize = stringIDToTypeID( "cellSize" );
    var idpixelsUnit = stringIDToTypeID( "pixelsUnit" );
    desc207.putUnitDouble( idcellSize, idpixelsUnit, 100.000000 );
executeAction( idmosaic, desc207, DialogModes.NO );

 

Or refactored into a function call and function:

 

mosaic(100);

function mosaic(cellSize) {
	var s2t = function (s) {
		return app.stringIDToTypeID(s);
	};
	var descriptor = new ActionDescriptor();
	descriptor.putUnitDouble( s2t( "cellSize" ), s2t( "pixelsUnit" ), cellSize );
	executeAction( s2t( "mosaic" ), descriptor, DialogModes.NO );
}

 

For the new UXP, you would either use UXP DOM code or BatchPlay recorded code:

 

https://developer.adobe.com/photoshop/uxp/2022/

 

async function actionCommands() {
    let commands = [
        // Mosaic
        {
            "_obj": "mosaic",
            "cellSize": {
                "_unit": "pixelsUnit",
                "_value": 100.0
            }
        }
    ];
    return await require("photoshop").action.batchPlay(commands, {});
}

console.log(
    await require("photoshop").core.executeAsModal(actionCommands, {"commandName": "Action Commands"})
);

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Sep 17, 2024 Sep 17, 2024

Copy link to clipboard

Copied

Thank you!! This is going to help me a lot!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Sep 17, 2024 Sep 17, 2024

Copy link to clipboard

Copied

LATEST

@HeyoThere -- You're welcome.

Votes

Translate

Translate

Report

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