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

Create masked area using javascript

Engaged ,
May 24, 2022 May 24, 2022

Copy link to clipboard

Copied

How its possible, using javascript, to create masked area that is positioned on the right side and that makes up 30% of canvas width? It is ideal if it is possible for the mask to have a blurred edge on the left side 🙂

 

Screen Shot 2022-05-24 at 09.40.25.png

TOPICS
Actions and scripting , macOS

Views

293

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 , May 24, 2022 May 24, 2022

Offhand I'd do it the same way as I would manually/recording an action, using the Scripting Listener plug-in + the Clean SL script:

 

// Updated 10th August 2022
activeDocument.selection.selectAll();
activeDocument.quickMaskMode ^= 1;
transformSelection(0, 0, 30);
app.activeDocument.quickMaskMode ^= 1;
addLayerMask();
motionBlur(0, 25);

// Functions

function transformSelection(horizontal, vertical, width) {
	var s2t = function (s) {
		return app.stringIDToTypeID(s);
	};
	var descriptor = new A
...

Votes

Translate

Translate
Adobe
Community Expert ,
May 24, 2022 May 24, 2022

Copy link to clipboard

Copied

 

// 2022, use it at your own risk;
if (app.documents.length > 0) {
// set to pixels;
var originalRulerUnits = app.preferences.rulerUnits;
app.preferences.rulerUnits = Units.POINTS;
rectangularSelection ([activeDocument.width*0.666666, 0, activeDocument.width, activeDocument.height], false, 100);
// reset;
app.preferences.rulerUnits = originalRulerUnits;
};
////// rectangular selection //////
function rectangularSelection (theBounds, add, theFeather) {
// =======================================================
if (add == false ||  add == undefined) {var idsetd = charIDToTypeID( "setd" )}
else {var idsetd = charIDToTypeID( "AddT" )};
    var desc55 = new ActionDescriptor();
    var idnull = charIDToTypeID( "null" );
        var ref11 = new ActionReference();
        var idChnl = charIDToTypeID( "Chnl" );
        var idfsel = charIDToTypeID( "fsel" );
        ref11.putProperty( idChnl, idfsel );
    desc55.putReference( idnull, ref11 );
    var idT = charIDToTypeID( "T   " );
        var desc56 = new ActionDescriptor();
        var idTop = charIDToTypeID( "Top " );
        var idRlt = charIDToTypeID( "#Rlt" );
        desc56.putUnitDouble(idTop, idRlt, theBounds[1]-theFeather);
        var idLeft = charIDToTypeID( "Left" );
        desc56.putUnitDouble(idLeft, idRlt, theBounds[0]);
        var idBtom = charIDToTypeID( "Btom" );
        desc56.putUnitDouble(idBtom, idRlt, theBounds[2]+theFeather);
        var idRght = charIDToTypeID( "Rght" );
        desc56.putUnitDouble(idRght, idRlt, theBounds[3]+theFeather);
    var idRctn = charIDToTypeID( "Rctn" );
    desc55.putObject(idT, idRctn, desc56 );
    desc55.putUnitDouble( stringIDToTypeID("feather"), stringIDToTypeID("pointsUnit"), theFeather);
executeAction( idsetd, desc55, DialogModes.NO );
};

edited

 

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 ,
May 24, 2022 May 24, 2022

Copy link to clipboard

Copied

Offhand I'd do it the same way as I would manually/recording an action, using the Scripting Listener plug-in + the Clean SL script:

 

// Updated 10th August 2022
activeDocument.selection.selectAll();
activeDocument.quickMaskMode ^= 1;
transformSelection(0, 0, 30);
app.activeDocument.quickMaskMode ^= 1;
addLayerMask();
motionBlur(0, 25);

// Functions

function transformSelection(horizontal, vertical, width) {
	var s2t = function (s) {
		return app.stringIDToTypeID(s);
	};
	var descriptor = new ActionDescriptor();
	var descriptor2 = new ActionDescriptor();
	var reference = new ActionReference();
	reference.putProperty( s2t( "channel" ), s2t( "selection" ));
	descriptor.putReference( s2t( "null" ), reference );
	descriptor.putEnumerated( s2t( "freeTransformCenterState" ), s2t( "quadCenterState" ), s2t( "QCSSide1" ));
	descriptor2.putUnitDouble( s2t( "horizontal" ), s2t( "percentUnit" ), horizontal );
	descriptor2.putUnitDouble( s2t( "vertical" ), s2t( "percentUnit" ), vertical );
	descriptor.putObject( s2t( "offset" ), s2t( "offset" ), descriptor2 );
	descriptor.putUnitDouble( s2t( "width" ), s2t( "percentUnit" ), width );
	descriptor.putEnumerated( s2t( "interfaceIconFrameDimmed" ), s2t( "interpolationType" ), s2t( "nearestNeighbor" ));
	executeAction( s2t( "transform" ), descriptor, DialogModes.NO );
}

function addLayerMask() {
	var s2t = function (s) {
		return app.stringIDToTypeID(s);
	};
	var descriptor = new ActionDescriptor();
	var reference = new ActionReference();
	descriptor.putClass( s2t( "new" ), s2t( "channel" ));
	reference.putEnumerated( s2t( "channel" ), s2t( "channel" ), s2t( "mask" ));
	descriptor.putReference( s2t( "at" ), reference );
	descriptor.putEnumerated( s2t( "using" ), s2t( "userMaskEnabled" ), s2t( "revealSelection" ));
	executeAction( s2t( "make" ), descriptor, DialogModes.NO );
}

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

 

 

Thanks to @c.pfaffenbichler for finding the error with the transform selection code. I have added a QuickMask toggle to overcome the issue (thanks to @Kukurykus for the toggle code).

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
Engaged ,
Aug 10, 2022 Aug 10, 2022

Copy link to clipboard

Copied

Dear @Stephen_A_Marsh i have the problem when i use this script on a group of layers i got message as on image below. Is it possible to imporve this? Thanks in avance

Screen Shot 2022-08-10 at 13.00.55.png

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 ,
Aug 10, 2022 Aug 10, 2022

Copy link to clipboard

Copied

Could you please post screenshots with the pertinent Panels (Toolbar, Layers, Options Bar, History, …) visible? 

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
Engaged ,
Aug 10, 2022 Aug 10, 2022

Copy link to clipboard

Copied

First image is orginal file before runing a script, and another one is after.

Screen Shot 2022-08-10 at 13.20.15.png

Screen Shot 2022-08-10 at 13.19.36.png

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 ,
Aug 10, 2022 Aug 10, 2022

Copy link to clipboard

Copied

Don’t select a Group. 

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
Engaged ,
Aug 10, 2022 Aug 10, 2022

Copy link to clipboard

Copied

But that is the problem, often i need to create mask on a group of layers. 

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 ,
Aug 10, 2022 Aug 10, 2022

Copy link to clipboard

Copied

Have you ever tested the Script I posted in post 1? 

That creates a Selection, so you could edit that and add the addLayerMask-function. 

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 ,
Aug 10, 2022 Aug 10, 2022

Copy link to clipboard

Copied

The function 

transformSelection

appears to, if a Group is selected, transform the Group. 

So I guess you can either insert some additional checks or restructure the operation, for example by switching to QuickMask Mode for the transformation. 

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 ,
Aug 10, 2022 Aug 10, 2022

Copy link to clipboard

Copied

LATEST

@milevic – I didn't receive an automated forum email for some reason and just stumbled over this in the updated topics... Anyway, I have updated the original code as suggested by @c.pfaffenbichler as your original request was only for a layer and not a layer group so this deficiency was not originally tested/spotted.

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