Copy link to clipboard
Copied
I'm trying to script several reptitive tasks as follows
I've worked out how to select the layer and select a specified point, but not all pixels & replace colour
var doc = app.documents[0];
app.activeDocument = doc;
var layers = app.activeDocument.layers;
// Text BG
var layerName = "Text BG";
var myLayer = layers[layerName];
app.activeDocument.activeLayer = myLayer;
makeSelection(224,439,102,7);
// Border Colour
// Selection Function
// x, y, width, height
// x & y position from top left corner of document
// width & height of selection
function makeSelection(x,y,sw,sh){
app.activeDocument.selection.select([ [x,y], [x,y+sh], [x+sw,y+sh], [x+sw,y] ]);
}
You could use the scriptlistener plugin (if you don't know it... google it, it's really useful)
Get the output in the log files to get the content-aware code.
I'm not sure entirely sure the opacity makes a difference for content-aware fill, if you experiment with it and find out, do let us know! 😉
Because it's monday...
Here's a working -monday morning, not the cleanest code- implementation of content-aware fill only.
/**Content Aware Fill from scriptlistener code
* @Param
...
Copy link to clipboard
Copied
If you're just selecting pixels on a named transparent layer, can't you simply record an action for that?
Copy link to clipboard
Copied
I've tried that but for 1&2 but when i run the action nothing happens
Copy link to clipboard
Copied
You could use the scriptlistener plugin (if you don't know it... google it, it's really useful)
Get the output in the log files to get the content-aware code.
I'm not sure entirely sure the opacity makes a difference for content-aware fill, if you experiment with it and find out, do let us know! 😉
Because it's monday...
Here's a working -monday morning, not the cleanest code- implementation of content-aware fill only.
/**Content Aware Fill from scriptlistener code
* @Param {boolean} color Adapt colors to local environment?
* @Param {boolean} rotate Orient image gradients?
* @Param {boolean} scale Match pattern size?
* @Param {boolean} mirror Flip pattern?
* @Param {number} opacity Opacity
* @Param {typeID} blendmode Layer blend mode as typeID... use scriptlistener to illicit more blend modes (look for "Nrml", "Dslv", "Drkn", Lghn, ...)
*/
function cntAwrFill (color,rotate,scale,mirror,opacity,blendmode){
var idFl = charIDToTypeID( "Fl " );
var idUsng = charIDToTypeID( "Usng" );
var idFlCn = charIDToTypeID( "FlCn" );
var idcontentAware = stringIDToTypeID( "contentAware" );
var idOpct = charIDToTypeID( "Opct" );
var idPrc = charIDToTypeID( "#Prc" );
var idMd = charIDToTypeID( "Md " );
var idBlnM = charIDToTypeID( "BlnM" );
var desc238 = new ActionDescriptor();
desc238.putEnumerated( idUsng, idFlCn, idcontentAware );
desc238.putBoolean( stringIDToTypeID( "contentAwareColorAdaptationFill" ), color ); //set
desc238.putBoolean( stringIDToTypeID( "contentAwareRotateFill" ), rotate );
desc238.putBoolean( stringIDToTypeID( "contentAwareScaleFill" ), scale );
desc238.putBoolean( stringIDToTypeID( "contentAwareMirrorFill" ), mirror );
desc238.putUnitDouble( idOpct, idPrc, opacity ); //Opacity value, can be anything between 0 & 100
desc238.putEnumerated( idMd, idBlnM, blendmode );
executeAction( idFl, desc238, DialogModes.NO );
}
cntAwrFill(true,true,true,false,100, charIDToTypeID( "Nrml" ));
Best of luck to ya!
Copy link to clipboard
Copied
Thanks, while i didn't use this directly the script listener info did help me.
I ended up with
var layerName = "Text BG";
var myLayer = layers[layerName];
app.activeDocument.activeLayer = myLayer;
app.activeDocument.selection.deselect();
fillWithForegroundColour();
// Border Colour
layerName = "Border Colour";
myLayer = layers[layerName];
app.activeDocument.activeLayer = myLayer;
app.activeDocument.selection.deselect();
fillWithForegroundColour();
// Replace Text
// var idfindReplace = stringIDToTypeID( "findReplace" );
executeAction(stringIDToTypeID('findReplace'), undefined)
// Functions
function fillWithForegroundColour() {
var idfill = stringIDToTypeID( "fill" );
var desc235 = new ActionDescriptor();
var idusing = stringIDToTypeID( "using" );
var idfillContents = stringIDToTypeID( "fillContents" );
var idforegroundColor = stringIDToTypeID( "foregroundColor" );
desc235.putEnumerated( idusing, idfillContents, idforegroundColor );
var idopacity = stringIDToTypeID( "opacity" );
var idpercentUnit = stringIDToTypeID( "percentUnit" );
desc235.putUnitDouble( idopacity, idpercentUnit, 100.000000 );
var idmode = stringIDToTypeID( "mode" );
var idblendMode = stringIDToTypeID( "blendMode" );
var idnormal = stringIDToTypeID( "normal" );
desc235.putEnumerated( idmode, idblendMode, idnormal );
executeAction( idfill, desc235, DialogModes.NO );
}