Skip to content

Instantly share code, notes, and snippets.

@ahules
Last active October 12, 2020 17:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ahules/9d860de987ea512d896c5ab8f3a68004 to your computer and use it in GitHub Desktop.
Save ahules/9d860de987ea512d896c5ab8f3a68004 to your computer and use it in GitHub Desktop.
Set brush settings jsx adobe photoshop
// Took here, just refactored and add ability to set mode
// https://community.adobe.com/t5/photoshop/q-is-accessible-get-set-for-brush-settings-lock-features/m-p/9509960?page=1
setBrushSettings({opacity: 100, mode: "normal", hardness: 100, flow: 100, diameter: 10});
function setBrushSettings(params) {
try {
var refGet = new ActionReference();
refGet.putProperty(charIDToTypeID("Prpr"), stringIDToTypeID("tool"));
refGet.putEnumerated(charIDToTypeID("capp"), charIDToTypeID("Ordn"), charIDToTypeID("Trgt"));
var result = executeActionGet(refGet);
var options = result.getObjectValue(stringIDToTypeID("currentToolOptions"));
var tool = result.getEnumerationType(stringIDToTypeID("tool"));
var brush = options.getObjectValue(stringIDToTypeID("brush"));
if (params.opacity !== undefined) {
options.putInteger(stringIDToTypeID("opacity"), params.opacity)
}
if (params.mode !== undefined) {
options.putEnumerated( stringIDToTypeID( "mode" ), stringIDToTypeID( "blendModel" ), stringIDToTypeID(params.mode) );
}
if (params.flow !== undefined) {
options.putInteger(stringIDToTypeID("flow"), params.flow);
}
if (params.smooth !== undefined && spacing != 0) {
options.putInteger(stringIDToTypeID("smooth"), params.smooth);
options.putDouble(stringIDToTypeID("smoothingValue"), Math.round(params.smooth / 100 * 255));
}
if (params.diameter !== undefined) {
brush.putUnitDouble(charIDToTypeID("Dmtr"), charIDToTypeID("#Pxl"), params.diameter)
}
if (params.hardness !== undefined) {
brush.putUnitDouble(charIDToTypeID("Hrdn"), charIDToTypeID("#Prc"), params.hardness)
}
if (params.spacing === 0) {
brush.putBoolean(stringIDToTypeID("interfaceIconFrameDimmed"), false);
} else if (params.spacing !== undefined) {
brush.putBoolean(stringIDToTypeID("interfaceIconFrameDimmed"), true);
brush.putUnitDouble(charIDToTypeID("Spcn"), charIDToTypeID("#Prc"), params.spacing);
}
options.putObject(stringIDToTypeID("brush"), stringIDToTypeID("null"), brush);
var refSet = new ActionReference();
refSet.putClass(tool);
var desc = new ActionDescriptor();
desc.putReference(stringIDToTypeID("null"), refSet);
desc.putObject(stringIDToTypeID("to"), stringIDToTypeID("null"), options);
executeAction(stringIDToTypeID("set"), desc, DialogModes.NO);
} catch (e) {
alert(e)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment