Copy link to clipboard
Copied
I am working on a custom HTML panel for controlling brush parameters to improve my workflow.
By using the ScriptListener I was able to get a simple script to change the size of the brush dynamically.
Unfortunately, ScriptListener does not update the script output when I change the brush roundness or the angle.
Does anybody know the right parameters? I have been trying to figure them out with the documentation but all I got was a headache.
Here is the js for rotation (what I am looking for is the equivalent for both roundness and angle):
function setBrushSize(size) {
var idSet = charIDToTypeID( "setd" );
var idNull = charIDToTypeID( "null" );
var idBrush = charIDToTypeID( "Brsh" );
var idOrdinal = charIDToTypeID( "Ordn" );
var idTarget = charIDToTypeID( "Trgt" );
var idTo = charIDToTypeID( "T " );
var idBrushSize = stringIDToTypeID( "masterDiameter" );
var idPixels = charIDToTypeID( "#Pxl" );
var desc1 = new ActionDescriptor();
var desc2 = new ActionDescriptor();
var ref1 = new ActionReference();
ref1.putEnumerated( idBrush, idOrdinal, idTarget );
desc1.putReference( idNull, ref1 );
desc2.putUnitDouble( idBrushSize, idPixels, size );
desc1.putObject( idTo, idBrush, desc2 );
executeAction( idSet, desc1, DialogModes.NO );
}
Thanks in advance!
Pol
I think Mike Hale posted this code a while back, but it only applies to default round brush-tips, not sampled ones, erodible etc.
#target photoshop
function setBrushFeatures(Diameter, Hardness, Angle, Roundness, Spacing, Flipy, Flipx) {
var ref = new ActionReference();
ref.putEnumerated(charIDToTypeID("capp"), charIDToTypeID("Ordn"), charIDToTypeID("Trgt"));
var appDesc = executeActionGet(ref);
var toolDesc = appDesc.getObjectValue(stringIDToTypeID('currentToolOptions'));
var brushDesc =
...
Copy link to clipboard
Copied
Ok, after some more research I found the name of the parameter that I believe would change the angle of the brush: "brushPoseAngle".
I found the name here:
http://ps-scripts.cvs.sourceforge.net/viewvc/ps-scripts/xtools/xlib/PSConstants.js?revision=1.18
Using this reference I try to create a function that would modify the brush angle, but I still have had no luck.
Here is my failed attempt:
function setBrushRotation(deg) {
var idSet = charIDToTypeID( "setd" );
var idNull = charIDToTypeID( "null" );
var idBrush = charIDToTypeID( "Brsh" );
var idOrdinal = charIDToTypeID( "Ordn" );
var idTarget = charIDToTypeID( "Trgt" );
var idWhat = charIDToTypeID( "What" );
var idBrushAngle = stringIDToTypeID( "brushPoseAngle" );
var idAngle = charIDToTypeID( "#Ang" );
var desc1 = new ActionDescriptor();
var desc2 = new ActionDescriptor();
var ref1 = new ActionReference();
ref1.putEnumerated( idBrush, idOrdinal, idTarget );
desc1.putReference( idNull, ref1 );
desc2.putUnitDouble( idBrushAngles, idAngle, deg );
desc1.putObject( idWhat, idBrush, desc2 );
executeAction( idSet, desc1, DialogModes.NO );
}
It is basically the one that I have working with brush size but this time replacing the new variable plus changing the units to angle instead of pixels.
Any feedback welcome!
Thanks,
Pol
Copy link to clipboard
Copied
I think Mike Hale posted this code a while back, but it only applies to default round brush-tips, not sampled ones, erodible etc.
#target photoshop
function setBrushFeatures(Diameter, Hardness, Angle, Roundness, Spacing, Flipy, Flipx) {
var ref = new ActionReference();
ref.putEnumerated(charIDToTypeID("capp"), charIDToTypeID("Ordn"), charIDToTypeID("Trgt"));
var appDesc = executeActionGet(ref);
var toolDesc = appDesc.getObjectValue(stringIDToTypeID('currentToolOptions'));
var brushDesc = toolDesc.getObjectValue(stringIDToTypeID('brush'));
if (brushDesc.hasKey(stringIDToTypeID('sampledData'))) {
var SampleData = brushDesc.getString(stringIDToTypeID('sampledData'));
var Name = brushDesc.getString(stringIDToTypeID('name'))
Hardness = undefined;
}else{
if (Hardness == undefined) Hardness = brushDesc.getDouble(stringIDToTypeID('hardness'));
}
if (Diameter == undefined) Diameter = brushDesc.getDouble(stringIDToTypeID('diameter'));
if (Angle == undefined) Angle = brushDesc.getDouble(stringIDToTypeID('angle'));
if (Roundness == undefined) Roundness = brushDesc.getDouble(stringIDToTypeID('roundness'));
if (Spacing == undefined) Spacing = brushDesc.getDouble(stringIDToTypeID('spacing'));
if (Flipy == undefined) Flipy = brushDesc.getBoolean(stringIDToTypeID('flipY'));
if (Flipx == undefined) Flipx = brushDesc.getBoolean(stringIDToTypeID('flipX'));
var SampleIntr = brushDesc.getBoolean(charIDToTypeID('Intr'));
var desc = new ActionDescriptor();
var ref = new ActionReference();
ref.putEnumerated(charIDToTypeID("Brsh"), charIDToTypeID("Ordn"), charIDToTypeID("Trgt"));
desc.putReference(charIDToTypeID("null"), ref);
var desc1 = new ActionDescriptor();
desc1.putDouble(stringIDToTypeID('diameter'), Diameter);
if (Hardness != undefined) desc1.putDouble(stringIDToTypeID('hardness'), Hardness);
desc1.putDouble(stringIDToTypeID('angle'), Angle);
desc1.putDouble(stringIDToTypeID('roundness'), Roundness);
desc1.putDouble(stringIDToTypeID('spacing'), Spacing);
desc1.putBoolean(stringIDToTypeID('flipY'), Flipy);
desc1.putBoolean(stringIDToTypeID('flipX'), Flipx);
if (brushDesc.hasKey(stringIDToTypeID('sampledData'))) {
desc1.putString(stringIDToTypeID('sampledData'), SampleData);
desc1.putString(stringIDToTypeID('name'), Name);
desc1.putBoolean(charIDToTypeID('Intr'), SampleIntr);
}
var desc5 = new ActionDescriptor();
var idnull = charIDToTypeID("null");
var ref3 = new ActionReference();
var idBrsh = charIDToTypeID("Brsh");
var idOrdn = charIDToTypeID("Ordn");
var idTrgt = charIDToTypeID("Trgt");
ref3.putEnumerated(idBrsh, idOrdn, idTrgt);
desc5.putReference(idnull, ref3);
var idsampledBrush = stringIDToTypeID("sampledBrush");
desc5.putObject(charIDToTypeID("T "), idsampledBrush, desc1);
executeAction(charIDToTypeID("setd"), desc5, DialogModes.NO);
}
setBrushFeatures(undefined, undefined, 45, undefined, undefined, undefined)
Copy link to clipboard
Copied
Thanks, c.pfaffenbichler!!
I got it to work with the code you suggested from Mike Hale. One little detail, in line 52 there is a missing space in the "T " command, should be "T ".
I cleaned up the code an label it for others who might be interested:
function setBrushFeatures(Diameter, Hardness, Angle, Roundness, Spacing, Flipy, Flipx) {
// get app object
var appAR = new ActionReference();
appAR.putEnumerated(charIDToTypeID("capp"), charIDToTypeID("Ordn"), charIDToTypeID("Trgt"));
var app = executeActionGet(appAR);
// get brush settings
var brush = app.getObjectValue(stringIDToTypeID('currentToolOptions')).getObjectValue(stringIDToTypeID('brush'));
// set defaults if undefined (copies current brush values)
if (brush.hasKey(stringIDToTypeID('sampledData'))) {
var SampleIntr = brush.getBoolean(charIDToTypeID('Intr'));
var SampleData = brush.getString(stringIDToTypeID('sampledData'));
var Name = brush.getString(stringIDToTypeID('name'))
Hardness = undefined;
} else if(Hardness == undefined) Hardness = brush.getDouble(stringIDToTypeID('hardness'));
if (Diameter == undefined) Diameter = brush.getDouble(stringIDToTypeID('diameter'));
if (Angle == undefined) Angle = brush.getDouble(stringIDToTypeID('angle'));
if (Roundness == undefined) Roundness = brush.getDouble(stringIDToTypeID('roundness'));
if (Spacing == undefined) Spacing = brush.getDouble(stringIDToTypeID('spacing'));
if (Flipy == undefined) Flipy = brush.getBoolean(stringIDToTypeID('flipY'));
if (Flipx == undefined) Flipx = brush.getBoolean(stringIDToTypeID('flipX'));
// action with the new parameters
var paramsAD = new ActionDescriptor();
paramsAD.putDouble(stringIDToTypeID('diameter'), Diameter);
if (Hardness != undefined) paramsAD.putDouble(stringIDToTypeID('hardness'), Hardness);
paramsAD.putDouble(stringIDToTypeID('angle'), Angle);
paramsAD.putDouble(stringIDToTypeID('roundness'), Roundness);
paramsAD.putDouble(stringIDToTypeID('spacing'), Spacing);
paramsAD.putBoolean(stringIDToTypeID('flipY'), Flipy);
paramsAD.putBoolean(stringIDToTypeID('flipX'), Flipx);
if (brush.hasKey(stringIDToTypeID('sampledData'))) {
paramsAD.putString(stringIDToTypeID('sampledData'), SampleData);
paramsAD.putString(stringIDToTypeID('name'), Name);
paramsAD.putBoolean(charIDToTypeID('Intr'), SampleIntr);
}
// action to modify brush
var brushAD = new ActionDescriptor();
var brushAR = new ActionReference();
brushAR.putEnumerated(charIDToTypeID("Brsh"), charIDToTypeID("Ordn"), charIDToTypeID("Trgt"));
brushAD.putReference(charIDToTypeID("null"), brushAR);
// execute action to modify brush with the new parameters
brushAD.putObject(charIDToTypeID("T "), stringIDToTypeID("sampledBrush"), paramsAD);
executeAction(charIDToTypeID("setd"), brushAD, DialogModes.NO);
}
Thanks so much again!
Pol
Copy link to clipboard
Copied
One little detail, in line 52 there is a missing space in the "T " command, should be "T ".
Sorry, I have had problems like this before but had forgotten to check if the code had pasted intact.
Copy link to clipboard
Copied
I corrected both codes.
Copy link to clipboard
Copied
Great code!
But the maximum value I can use for the spacing parameter is 1000. What should I do to use a value greater than 1000?
Is it possible?
Thanks!
Copy link to clipboard
Copied
In the Brush Settings Panel 1000% is the maximum.