Copy link to clipboard
Copied
When I try to put the spacing of any brush type tool, it gets all the values but not the Spacing value [1-1000]
Is it a bug?
For example, when I try to put 2% has spacing value, the result will be always 25%. The same happens when I try other values. The result is 25%
Diameter,Hardness,Angle,Roundness,Flipy,Flipx are working well, but not Spacing
setBrushFeatures(130, 40,undefined,undefined,2,undefined,undefined);
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 (Diameter == undefined) Diameter = brushDesc.getDouble(stringIDToTypeID('diameter'));
if (Hardness == undefined) Hardness = brushDesc.getDouble(stringIDToTypeID('hardness'));
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 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);
desc1.putDouble(stringIDToTypeID('hardness'), Hardness);
desc1.putDouble(stringIDToTypeID('angle'), Angle);
desc1.putDouble(stringIDToTypeID('roundness'), Roundness);
desc1.putDouble(stringIDToTypeID('spacing'), Spacing); // ?????????????? Allways 25% !!
desc1.putBoolean(stringIDToTypeID('flipY'), Flipy);
desc1.putBoolean(stringIDToTypeID('flipX'), Flipx);
desc.putObject( stringIDToTypeID('to'), charIDToTypeID( "Brsh" ), desc1 );
executeAction( charIDToTypeID( "setd" ), desc, DialogModes.NO );
}
SuperMerlin Posted the statement in a different thrreat that will set spacing in your original script
desc1.putUnitDouble( stringIDToTypeID('spacing'), charIDToTypeID('#Prc'), Spacing);
...// Features(Diameter,Hardness,Angle,Roundness,Spacing,Flipy,Flipx)
//setBrushFeatures(undefined,undefined,undefined,undefined,undefined,undefined,undefined);
//setBrushFeatures(13,0,0,100,25,0,0); //Adobe Defaults
//setBrushFeatures(13,0,0,100,25,true,true); //Diameter,Hardness,Angle,Roundness,Spacin
Copy link to clipboard
Copied
You using action manager code. All things done in Photoshop can not be recorded. Actions have some limitations. When it come to setting Brushes in Photoshop Actions the only way I found I could set all the settings I wanted was to define Brush Presets with all the settings I want then select the preset in the action. The brush settings are not in the Action step or the scriptlistener Action manager code. All the setting are in the preset selected. If I were a betting man I would bet spacing is only scriptable by selecting the brush tool then selecting a Brush preset with the desired spacing. If the preset fails to select. load the saved preset file and then selecting it.
I tested your code is CS6, CC, CC 2104 and CC 2015. All versions will retrieve the current spacing correctly and all version will set all the other settings correctly. It make no difference if you put a spacing description in the action manager code or not. Brush spacing is always get set to 25%.
With the preset spacing will be set correctly as will all the other brush setting brush, brush dynamics in the preset. The is a problem with using presets not so much with brush preset for you can select the brush tool with scripting. The problem with presets is if the user has checked current tool only in the Photoshop tools preset UI. You can only select presets for the current Photoshop tool. If current tool only is not checked you can select any tool's preset and it will select the tool and set all the tools settings. The closest I came to scripting selecr toole preset is.
// Note: This script only works if the correct tool for the preset is currently selected.
// Or "current tool only" is not checked in Photoshop's "Tool Options Bar" Presets pull-down list dialog at the bottom left.
var ToolPresetName = "JJMack soft oval red brush" ; // The Photoshop Tool preset name that you created and saved into a set
var ToolPresetSet = "JJMackToolsPresetsSet"; // The SetName.tpl file need to be same folder as this Photoshop script.
try {SelectToolPreset(ToolPresetName);}
catch(e) {
if (LoadToolPresetSet(ToolPresetSet)) {
try {SelectToolPreset(ToolPresetName);}
catch(e) {alert('Was unable to Select the Tools Preset "' + ToolPresetName + '".\nUncheck Preset pulld-down dialog "Current Tool Only" check box');}
}
else {alert("Was unable to load Tools Presets Set " + ToolPresetSet);}
}
// =================================================== Helper functions ===================================================== //
function SelectToolPreset(PresetName) {
// === Select Preset, tool must be selected or 'show current tool only' unchecked ===
var desc = new ActionDescriptor();
var ref = new ActionReference();
ref.putName( stringIDToTypeID( "toolPreset" ), PresetName );
desc.putReference( charIDToTypeID( "null" ), ref );
executeAction( charIDToTypeID( "slct" ), desc, DialogModes.NO );
}
function LoadToolPresetSet(SetName) {
returncode = true;
var scriptLocation = String(findScript());
var path = scriptLocation.substr(0, scriptLocation.lastIndexOf("/") + 1 ) ;
var SetFile = new File(path + SetName + ".tpl"); // Requited to be in the script's folder
if (!SetFile.exists) { returncode = false; }
else {
try {LoadToolsSet(SetFile);}
catch(e) { returncode = false; }
}
return returncode ;
}
function LoadToolsSet(tplFile) {
// ========load a set of Tools Presets=========================
var desc = new ActionDescriptor();
var ref = new ActionReference();
ref.putProperty( charIDToTypeID( "Prpr" ), stringIDToTypeID( "toolPreset" ));
ref.putEnumerated( charIDToTypeID( "capp" ), charIDToTypeID( "Ordn" ), charIDToTypeID( "Trgt" ) );
desc.putReference( charIDToTypeID( "null" ), ref );
desc.putPath( charIDToTypeID( "T " ), new File( tplFile ) );
desc.putBoolean( charIDToTypeID( "Appe" ), true );
executeAction( charIDToTypeID( "setd" ), desc, DialogModes.NO );
}
// Find the location where this script resides
function findScript() {
var where = "";
try { FORCEERROR = FORCERRROR;}
catch(err) { where = File(err.fileName);}
return where ;
Copy link to clipboard
Copied
Cool function Pedro,
may I ask you how you've been able to get all the stringIDs – apparently I'm able to record only the "masterDiameter" via ScriptingListener using the contextual menu, everything else belonging to the Brush panel leave no trace.
Thank you!
Davide Barranca
Copy link to clipboard
Copied
Hi Davide
Sorry i didn't address its origin. My mistake.
I get it from Mike Hale (via c.pfaffenbichler post) in here
I also noticed this one to create a listener when someone change a brush name
Copy link to clipboard
Copied
SuperMerlin Posted the statement in a different thrreat that will set spacing in your original script
desc1.putUnitDouble( stringIDToTypeID('spacing'), charIDToTypeID('#Prc'), Spacing);
// Features(Diameter,Hardness,Angle,Roundness,Spacing,Flipy,Flipx)
//setBrushFeatures(undefined,undefined,undefined,undefined,undefined,undefined,undefined);
//setBrushFeatures(13,0,0,100,25,0,0); //Adobe Defaults
//setBrushFeatures(13,0,0,100,25,true,true); //Diameter,Hardness,Angle,Roundness,Spacing,Flipy,Flipx
//setBrushFeatures(13,0,0,100,25,1,0); //Diameter,Hardness,Angle,Roundness,Spacing,Flipy,Flipx
//setBrushFeatures(13,0,0,100,25,0); //Diameter,Hardness,Angle,Roundness,Spacing,Flipy
//setBrushFeatures(13,0,0,100,1); //Diameter,Hardness,Angle,Roundness,Spacing
//setBrushFeatures(13,0,0,50); //Diameter,Hardness,Angle,Roundness
//setBrushFeatures(13,0,45); //Diameter,Hardness,Angle
//setBrushFeatures(13,50); //Diameter,Hardness
setBrushFeatures(25); //Diameter
//==============================================================================================//
function setBrushFeatures (Diameter,Hardness,Angle,Roundness,Spacing,Flipy,Flipx) {
//A Brush tool must be the current tool
if (!app.toolSupportsBrushes(app.currentTool)) selectBrush(); //CC 2014
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 (Diameter == undefined) Diameter = brushDesc.getDouble(stringIDToTypeID('diameter'));
if (Hardness == undefined) Hardness = brushDesc.getDouble(stringIDToTypeID('hardness'));
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 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);
desc1.putDouble(stringIDToTypeID('hardness'), Hardness);
desc1.putDouble(stringIDToTypeID('angle'), Angle);
desc1.putDouble(stringIDToTypeID('roundness'), Roundness);
desc1.putUnitDouble( stringIDToTypeID('spacing'), charIDToTypeID('#Prc'), Spacing);
desc1.putBoolean(stringIDToTypeID('flipY'), Flipy);
desc1.putBoolean(stringIDToTypeID('flipX'), Flipx);
desc.putObject( stringIDToTypeID('to'), charIDToTypeID( "Brsh" ), desc1 );
executeAction( charIDToTypeID( "setd" ), desc, DialogModes.NO );
}
function selectBrush() {
//select brush scriptlistener code
var idslct = charIDToTypeID( "slct" );
var desc12 = new ActionDescriptor();
var idnull = charIDToTypeID( "null" );
var ref8 = new ActionReference();
var idPbTl = charIDToTypeID( "PbTl" );
ref8.putClass( idPbTl );
desc12.putReference( idnull, ref8 );
executeAction( idslct, desc12, DialogModes.NO );
}
Copy link to clipboard
Copied
Thanks, now the user-defined spacing works!