Last active
October 12, 2020 17:32
-
-
Save ahules/9d860de987ea512d896c5ab8f3a68004 to your computer and use it in GitHub Desktop.
Set brush settings jsx adobe photoshop
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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