show_brushes_object();
show_brushes_tree();
if (!select_brush("Mesh - Medium", "Legacy Brushes", "Faux Finish Brushes"))
alert("Wrong Brush!");
else
alert("Brush Selected!")
// next function works correctly only if the highlighting of the brush is visible
// alert_curr_brush();
////////////////////////////////////////////////////////////////////////////////////////////////////
function get_brushes_tree(donot_split)
{
try
{
var tree = "";
var r = new ActionReference();
r.putProperty( charIDToTypeID( "Prpr" ), stringIDToTypeID( "brushes" ) );
r.putEnumerated( charIDToTypeID("capp"), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") );
eval("var b = " + executeActionGet(r).getString(stringIDToTypeID("brushes")) + ".brushes");
process_brushes(b, "");
if (donot_split != true) tree = tree.split("\n");
return tree;
function process_brushes(b, set)
{
for (var i = 0; i < b.length; i++)
{
if (b.children)
{
tree += set + b.name + "\\" + "\n";
if (b.children.length)
process_brushes(b.children, set + b.name + "\\");
}
else
{
tree += set + b.name + "\n";
}
}
}
}
catch (e) { alert(e); throw(e); }
}
////////////////////////////////////////////////////////////////////////////////////////////////////
function get_brush_idx(name)
{
var tree = get_brushes_tree();
var s = "";
for (var i = 1; i < arguments.length; i++) s += arguments + "\\";
s += name;
for (var i = 0; i < tree.length; i++) if (tree == s) return i+1;
return 0;
}
////////////////////////////////////////////////////////////////////////////////////////////////////
function select_brush_idx(idx)
{
try
{
if (idx)
{
var d = new ActionDescriptor();
var r = new ActionReference();
r.putIndex(stringIDToTypeID("brush"), idx);
d.putReference(stringIDToTypeID("null"), r);
executeAction(stringIDToTypeID("select"), d, DialogModes.NO);
return true;
}
return false;
}
catch (e) { return false; }
}
////////////////////////////////////////////////////////////////////////////////////////////////////
function select_brush(name)
{
var tree = get_brushes_tree();
var s = "";
for (var i = 1; i < arguments.length; i++) s += arguments + "\\";
s += name;
var idx = 0;
for (var i = 0; i < tree.length; i++) if (tree == s) { idx = i+1; break; }
return select_brush_idx(idx);
}
////////////////////////////////////////////////////////////////////////////////////////////////////
function show_brushes_object()
{
try {
var d = new Window("dialog", "Brushes Object");
d.t = d.add("edittext", undefined, "", {multiline: true, readonly: true, scrolling:true, fontsize: '30pt' });
d.t.preferredSize = [1000, 750];
var r = new ActionReference();
r.putProperty( charIDToTypeID( "Prpr" ), stringIDToTypeID( "brushes" ) );
r.putEnumerated( charIDToTypeID("capp"), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") );
d.t.text = executeActionGet(r).getString(stringIDToTypeID("brushes"));
d.add("button", undefined, "OK");
d.show();
d = null;
}
catch (e) { alert(e); throw(e); }
}
////////////////////////////////////////////////////////////////////////////////////////////////////
function show_brushes_tree()
{
try {
var d = new Window("dialog", "Brushes Tree");
d.t = d.add("edittext", undefined, "", {multiline: true, readonly: true, scrolling:true, fontsize: '30pt' });
d.t.preferredSize = [1000, 750];
d.t.text = get_brushes_tree(true);
d.add("button", undefined, "OK");
d.show();
d = null;
}
catch (e) { alert(e); throw(e); }
}
////////////////////////////////////////////////////////////////////////////////////////////////////
function alert_curr_brush()
{
try {
var tmp = Math.random().toString().substr(2) + Math.random().toString().substr(2);
var d = new ActionDescriptor();
var r = new ActionReference();
r.putClass(stringIDToTypeID("brush"));
d.putReference(stringIDToTypeID("null"), r);
d.putString(stringIDToTypeID("name"), tmp);
var r1 = new ActionReference();
r1.putProperty(stringIDToTypeID("property"), stringIDToTypeID("currentToolOptions"));
r1.putEnumerated(stringIDToTypeID("application"), stringIDToTypeID("ordinal"), stringIDToTypeID("targetEnum"));
d.putReference(stringIDToTypeID("using"), r1);
executeAction(stringIDToTypeID("make"), d, DialogModes.NO);
var d = new ActionDescriptor();
var r = new ActionReference();
r.putName(stringIDToTypeID("brush"), tmp);
d.putReference(stringIDToTypeID("null"), r);
var idx = executeAction(stringIDToTypeID("delete"), d, DialogModes.NO).getReference(stringIDToTypeID("null")).getIndex() - 1;
select_brush_idx(idx);
var tree = get_brushes_tree();
alert("Current Brush:\n\n" + tree[idx-1]);
}
catch (e) { alert(e); throw(e); }
}
////////////////////////////////////////////////////////////////////////////////////////////////////
function alert_curr_brush_v2()
{
try {
var tmp = new File(Folder.temp.fsName + "\\" + "TMP");
if (tmp.exists) tmp.remove();
var d = new ActionDescriptor();
d.putPath(stringIDToTypeID("null"), tmp);
var r = new ActionReference();
r.putProperty(stringIDToTypeID("property"), stringIDToTypeID("brush"));
r.putEnumerated(stringIDToTypeID("application"), stringIDToTypeID("ordinal"), stringIDToTypeID("targetEnum"));
d.putReference(stringIDToTypeID("to"), r);
executeAction(stringIDToTypeID("set"), d, DialogModes.NO);
var tree1 = get_brushes_tree();
var d = new ActionDescriptor();
var r = new ActionReference();
r.putEnumerated(stringIDToTypeID("brush"), stringIDToTypeID("ordinal"), stringIDToTypeID("targetEnum"));
d.putReference(stringIDToTypeID("null"), r);
ret = executeAction(stringIDToTypeID("delete"), d, DialogModes.NO);
var tree2 = get_brushes_tree();
for (var i = 0; i < tree2.length; i++)
{
if (tree2 != tree1) break;
}
var d = new ActionDescriptor();
var r = new ActionReference();
r.putProperty(stringIDToTypeID("property"), stringIDToTypeID("brush"));
r.putEnumerated(stringIDToTypeID("application"), stringIDToTypeID("ordinal"), stringIDToTypeID("targetEnum"));
d.putReference(stringIDToTypeID("null"), r);
d.putPath(stringIDToTypeID("to"), tmp);
d.putBoolean(stringIDToTypeID("append"), false);
executeAction(stringIDToTypeID("set"), d, DialogModes.NO);
tmp.remove();
select_brush_idx(i+2);
var tree = get_brushes_tree();
alert("Current Brush:\n\n" + tree[i+2]);
}
catch (e) { throw(e); }
}