Copy link to clipboard
Copied
Hi everybody,
I have a question again. Is it possible to filter from the list of toolpresets only those for a certain tool (not the active tool)
In the code sample you get the name, but is there still a type that you can call to recognize what a toolpreset it is eg. for a stamp, or brush.
function getToolPresetNames() {
var ref = new ActionReference();
ref.putEnumerated(charIDToTypeID("capp"), charIDToTypeID("Ordn"), charIDToTypeID("Trgt"));
var appDesc = executeActionGet(ref);
var List = appDesc.getList(stringIDToTypeID('presetManager'));
var presetNames = [];
var list = List.getObjectValue(7).getList(charIDToTypeID('Nm '));
for (var i = 0; i < list.count; i++) {
var str = list.getString(i);
presetNames.push(str);
}
return presetNames;
};
Is there a solution?
Thanks in advance for the help
If you are using CC2018, you can slightly change the code suggested by SuperMerlin to accurately determine the tool class for the corresponding preset.
...alert(getToolPresetNames().join("\n"));
function getToolPresetNames() {
var ref = new ActionReference();
ref.putProperty(stringIDToTypeID("property"), stringIDToTypeID("presetManager"));
ref.putEnumerated(charIDToTypeID("capp"), charIDToTypeID("Ordn"), charIDToTypeID("Trgt"));
var appDesc = executeActionGet(ref);
Copy link to clipboard
Copied
No time to do it but I think the easiest way is to make a loop over current ToolPresets activating each one at same time. This way each of them will be selected on Tools Bar as well. At the time of each selection during such loop you could then each of them add to existing array, so you had 2 informations at same time, Tool Preset name and a name of tool that represents.
Copy link to clipboard
Copied
Thanks Kukurykus,
how can i get the current ToolPresets?
Do you have an code example for me
Copy link to clipboard
Copied
function sTT(v) {return stringIDToTypeID(v)}
(ref = new ActionReference()).putEnumerated(sTT('application'), sTT('ordinal'), sTT('targetEnum'))
lst = executeActionGet(ref).getList(sTT('presetManager')).getObjectValue(7).getList(sTT('name'))
for (pN = [], i = 0; i < lst.count; i++) {
(ref = new ActionReference()).putName(sTT('toolPreset'), str = lst.getString(i));
(dsc = new ActionDescriptor()).putReference(sTT('null'), ref)
executeAction(sTT('select'), dsc, DialogModes.NO);
(ref = new ActionReference()).putProperty(sTT('property'), sTT('tool')), ref.putClass(sTT('application'))
pN.push([[(!i ? '' : '\n') + str], [(typeIDToStringID(executeActionGet(ref).getEnumerationType(sTT('tool'))))]])
}
alert(pN)
Copy link to clipboard
Copied
Thanks Kukurykus,
does that only work if, the checkbox for "Current Tool only" unchecked?
Otherwise I have an error in line 9.
German Version
Copy link to clipboard
Copied
alert(getToolPresetNames().join("\n"));
function getToolPresetNames() {
var ref = new ActionReference();
ref.putProperty(stringIDToTypeID("property"), stringIDToTypeID("presetManager"));
ref.putEnumerated(charIDToTypeID("capp"), charIDToTypeID("Ordn"), charIDToTypeID("Trgt"));
var appDesc = executeActionGet(ref);
var List = appDesc.getList(stringIDToTypeID("presetManager"));
var presetNames = [];
var list = List.getObjectValue(7).getList(charIDToTypeID("Nm "));
var list2 = List.getObjectValue(7).getList(stringIDToTypeID("title"));
for (var i = 0; i < list.count; i++) {
var str = list.getString(i);
var str2 = list2.getString(i);
presetNames.push([str,str2]);
}
return presetNames;
};
Copy link to clipboard
Copied
Here is an example script to select tool presets.
N.B. It is noot perfect as the Type tools have non standard names compared with the rest of the tools, so you would have to add extra checks.
#target photoshop;
app.bringToFront();
var toolPresets = getToolPresetNames();
var tools =[];
for(var x in toolPresets){tools.push(toolPresets
[1].toString());}; tools = ReturnUniqueSortedList(tools);
var win = new Window("dialog","Preset Tools",undefined,{closeButton: true});
win.p1= win.add("panel", undefined, undefined, {borderStyle:"black"});
win.g1 = win.p1.add("group");
win.g1.orientation = "row";
win.title = win.g1.add("statictext",undefined,"Tool Presets");
var g = win.title.graphics;
g.font = ScriptUI.newFont("Georgia","BOLDITALIC",22);
win.g10 = win.p1.add("group");
win.g10.orientation = "row";
win.g10.dd1 = win.g10.add("dropdownlist");
win.g10.dd1.preferredSize=[200,20];
for(var p in tools){win.g10.dd1.add("item",tools
.toString());}
win.g10.dd2 = win.g10.add("dropdownlist");
win.g10.dd2.preferredSize=[200,20];
var tmp=[];
for(var z in toolPresets){
if(toolPresets
[1].toString() == tools[0].toString()) tmp.push(toolPresets [0]); }
tmp=tmp.sort();
for(var y in tmp){win.g10.dd2.add("item",tmp
.toString());} win.g10.dd1.selection=0;
win.g10.dd2.selection=0;
win.g10.dd1.onChange = function() {
tmp=[];
win.g10.dd2.removeAll();
for(var z in toolPresets){
if(toolPresets
[1].toString() == tools[win.g10.dd1.selection.index].toString()) tmp.push(toolPresets [0]); }
tmp=tmp.sort();
for(var y in tmp){win.g10.dd2.add("item",tmp
.toString());} win.g10.dd2.selection=0;
}
win.g100 = win.p1.add("group");
win.g100.orientation = "row";
win.g100.bu1 = win.g100.add("button",undefined,"Use Preset");
win.g100.bu2 = win.g100.add("button",undefined,"Cancel");
win.g100.bu1.preferredSize=[150,40];
win.g100.bu2.preferredSize=[150,40];
win.g100.bu1.onClick=function(){
win.close(0);
var selTool = win.g10.dd1.selection.text.toString().replace(/\s+/g,"");
selTool = selTool.charAt(0).toLowerCase() + selTool.substr(1);
if(selTool == "verticalTypeTool") selTool ="typeVerticalCreateOrEditTool";
selectTool(selTool);
selectToolPreset(win.g10.dd2.selection.text.toString());
}
win.show();
function getToolPresetNames() {
var ref = new ActionReference();
ref.putProperty(stringIDToTypeID("property"), stringIDToTypeID("presetManager"));
ref.putEnumerated(charIDToTypeID("capp"), charIDToTypeID("Ordn"), charIDToTypeID("Trgt"));
var appDesc = executeActionGet(ref);
var List = appDesc.getList(stringIDToTypeID("presetManager"));
var presetNames = [];
var list = List.getObjectValue(7).getList(charIDToTypeID("Nm "));
var list2 = List.getObjectValue(7).getList(stringIDToTypeID("title"));
for (var i = 0; i < list.count; i++) {
var str = list.getString(i);
var str2 = list2.getString(i);
presetNames.push([str,str2]);
}
return presetNames;
};
function ReturnUniqueSortedList(ArrayName){
var unduped = new Object;
for (var i = 0; i < ArrayName.length; i++) {
unduped[ArrayName] = ArrayName;
}
var uniques = new Array;for (var k in unduped) {
uniques.push(unduped
); }
uniques.sort();
return uniques;
}
function selectToolPreset(TOOL) {
var desc = new ActionDescriptor();
var ref = new ActionReference();
ref.putName( stringIDToTypeID('toolPreset'),TOOL );
desc.putReference( charIDToTypeID('null'), ref );
try{
executeAction( charIDToTypeID('slct'), desc, DialogModes.NO );
}catch(e){/*$.writeln("tool = " + TOOL + "\n" + e);*/}
};
function selectTool(tool) {
var desc = new ActionDescriptor();
var ref = new ActionReference();
ref.putClass( app.stringIDToTypeID(tool) );
desc.putReference( app.charIDToTypeID('null'), ref );
try{
executeAction( app.charIDToTypeID('slct'), desc, DialogModes.NO );
}catch(e){/*$.writeln("tool = " + tool + "\n" + e);*/}
};
Copy link to clipboard
Copied
Thanks SuperMelrin,
looks great. Is it right its works only if "Current Tool only" unchecked?
Copy link to clipboard
Copied
It should work if the checkbox is ticked or not ticked as it tries to select the tool first.
Copy link to clipboard
Copied
For me, this only works if the checkbox is not activated. Can that be due to the language.
Copy link to clipboard
Copied
It could well be, I can't test any other language, sorry.
Copy link to clipboard
Copied
No problem, thanks for help .
I will test it again tomorrow.
Copy link to clipboard
Copied
The problem will be with these lines of code :-
var selTool = win.g10.dd1.selection.text.toString().replace(/\s+/g,"");
selTool = selTool.charAt(0).toLowerCase() + selTool.substr(1);
if(selTool == "verticalTypeTool") selTool ="typeVerticalCreateOrEditTool";
selectTool(selTool);
What happens is it gets second value from getToolPresetNames();
I.E.
Magnetic Lasso 24 pixels,Magnetic Lasso Tool
Crop 4 inch x 6 inch 300 ppi,Crop Tool
Crop 5 inch x 3 inch 300 ppi,Crop Tool
Crop 5 inch x 4 inch 300 ppi,Crop Tool
Crop 5 inch x 7 inch 300 ppi,Crop Tool
Crop 8 inch x 10 inch 300 ppi,Crop Tool
Fill with Bubbles Pattern,Paint Bucket Tool
The second value is the tool but to select the tool Magnetic Lasso Tool needs to be changed to magneticLassoTool
Crop Tool changed to cropTool etc.
that is what the above lines of code is doing then calling the selectTool function with the modified name.
This is where things might be going wrong?
Copy link to clipboard
Copied
Yes it has to be unchecked, at least in CS6 EXTENDED I guess you have to do it manually,
while in CC2018 I'm not sure, there may be some way, but I didn't try yet. Later I will see...
So it seems to be not possible or r-bin​ will show nothing is impossible for him in PS
As to my script it can work properly only when 'Only Current Tool' option is unchecked.
replace:
executeAction(sTT('select'), dsc, DialogModes.NO)
to this one:
try{executeAction(sTT('select'), dsc, DialogModes.NO)} catch(err){break}
also replace:
alert(pN)
to:
alert(pN.length ? pN : 'Make sure "Only Current Tool" option is unchecked!')
Do not forget to put $.level = 0; in front of first function if you'd like to run it from ESTK!
Copy link to clipboard
Copied
If you are using CC2018, you can slightly change the code suggested by SuperMerlin to accurately determine the tool class for the corresponding preset.
alert(getToolPresetNames().join("\n"));
function getToolPresetNames() {
var ref = new ActionReference();
ref.putProperty(stringIDToTypeID("property"), stringIDToTypeID("presetManager"));
ref.putEnumerated(charIDToTypeID("capp"), charIDToTypeID("Ordn"), charIDToTypeID("Trgt"));
var appDesc = executeActionGet(ref);
var List = appDesc.getList(stringIDToTypeID("presetManager"));
var presetNames = [];
var list = List.getObjectValue(7).getList(charIDToTypeID("Nm "));
var list2 = List.getObjectValue(7).getList(stringIDToTypeID("class"));
for (var i = 0; i < list.count; i++) {
var str = list.getString(i);
var str2 = typeIDToStringID(list2.getClass(i));
presetNames.push([str,str2]);
}
return presetNames;
};
Copy link to clipboard
Copied
Thank you so much for your kind help.
r-bin, that looks exactly like what I am looking for, thanks a bunch!
Copy link to clipboard
Copied
I found something weird in my code I was even not aware I used it in that time. I have no idea why I did that, but whichever code I'm looking at I see people every time use: ref.putEnumerated(sTT('application'), sTT('ordinal'), sTT('targetEnum'))
I changed it for a test in some of my codes to shortened vers., then compared results and found the speed is same, so why noone uses it but longer version? (in CS6 too): ref.putClass(sTT('application'))​ / Did you know it? Also you SuperMerlin​ ?
Copy link to clipboard
Copied
Because it should only be used in conjunction with putProperty and, for example, Photoshop (CS6 at least) falls at ref.putClass (sTT ('document')) for some properties.
Copy link to clipboard
Copied
Yes I know that with properties, while first longer version without them, but fact is when you do that first (longer) version without properties then it takes 1000 times longer to find certain object. I was thinking of document and maybe layer that may be differently but didn't try it yet. With time I'll see what properties with non-application fail, however sole application can be used in shorter version now when I know it.
Copy link to clipboard
Copied
You can use this for layer, channel and path. But I do not recommend it.
You can also use putIndex with and without putProperty
Copy link to clipboard
Copied
Yes, I often use Index, less often string etc, but why don't you recommend Class? Doesn't it give same results?
Copy link to clipboard
Copied
About charID, I think this can be known only by getting the source code of the photoshop itself.
I'm not sure about putClass. ScriptingListener does not do this often. So this is not done by the developers of the photoshop.
Copy link to clipboard
Copied
Ok, thx for your answers. Regarding that topic Document saved property not updating when manipulating guides it is possible to get many chars extracting them from objects if you know what property to use. Btw how we can know some property can be used. For ex. if there is something like it:
(ref = new ActionReference()).putProperty(sTT('property'), sTT('tool'))
ref.putEnumerated(sTT('application'), sTT('ordinal'), sTT('tergetEnum'))
how you can know such property as 'tool' can be used? It can be checked with many keywords by 'try...catch' statement but there are so many of them that this process would take much time, so what is other proper way?
Do you know some chars that can't be obtained by looking into available objects but needed to look into Ps source code?
Copy link to clipboard
Copied
how you can know such property as 'tool' can be used? It can be checked with many keywords by 'try...catch' statement but there are so many of them that this process would take much time, so what is other proper way?
There are not so many of them. Approximately 5000-6000.