Copy link to clipboard
Copied
My app has already shipped and i'm encountering an issue, so I am happy to pay cash today for this help via cashapp/paypal so I can get this running again.
I'm looking for a way to fetch the names of the users installed patterns. For example, "Trees", "Grass", "Water". I want my extension to automatically install a pattern pack, however what happens is that it reinstalls the same patterns every time it runs. I would like to check if the pattern pack name matches any of the users installed pattersn, and if not, install them.
I would also be okay with an alternative method of installation that doesn't require that, but gets the same job done.
var r = new ActionReference();
r.putProperty(stringIDToTypeID("property"), stringIDToTypeID("presetManager"));
r.putEnumerated(stringIDToTypeID("application"), stringIDToTypeID("ordinal"), string
Copy link to clipboard
Copied
You can take this script as a basis
var r = new ActionReference();
r.putProperty(stringIDToTypeID("property"), stringIDToTypeID("presetManager"));
r.putEnumerated(stringIDToTypeID("application"), stringIDToTypeID("ordinal"), stringIDToTypeID("targetEnum"));
var list = executeActionGet(r).getList(stringIDToTypeID("presetManager")).getObjectValue(4).getList(stringIDToTypeID("name"));
var patterns = new Array();
for (var i = 0; i < list.count; i++) patterns.push(list.getString(i));
alert(patterns);
Copy link to clipboard
Copied
Thank you, where should I send a check?!
I'm serious thank you a ton. One question, this seems to deliver the individual texture names instead of the folder/group name. Is that possible to retrieve?
Copy link to clipboard
Copied
var r = new ActionReference();
r.putProperty(stringIDToTypeID("property"), stringIDToTypeID("presetManager"));
r.putEnumerated(stringIDToTypeID("application"), stringIDToTypeID("ordinal"), stringIDToTypeID("targetEnum"));
var list = executeActionGet(r).getList(stringIDToTypeID("presetManager")).getObjectValue(4).getList(stringIDToTypeID("name"));
var patterns = new Array();
for (var i = 0; i < list.count; i++) patterns.push(list.getString(i));
var file = new File(Folder.temp.fsName + "/" + "TMP");
file.remove();
var d = new ActionDescriptor();
d.putPath(stringIDToTypeID("null"), file);
var r = new ActionReference();
r.putProperty(stringIDToTypeID("property"), stringIDToTypeID("pattern"));
r.putEnumerated(stringIDToTypeID("application"), stringIDToTypeID("ordinal"), stringIDToTypeID("targetEnum"));
d.putReference(stringIDToTypeID("to"), r);
executeAction(stringIDToTypeID("set"), d, DialogModes.NO);
patterns.reverse();
file.open("r");
file.encoding = "BINARY";
var s = file.read();
file.remove();
var n = s.indexOf("8BIMphry");
if (n > 0)
{
s = s.substr(n+12);
var d = new ActionDescriptor();
d.fromStream(s);
var list = d.getList(stringIDToTypeID("hierarchy"));
var hierarchy = new Array();
var grp = new Array();
for (var i = 0; i < list.count; i++)
{
// switch (list.getClass(i)) // not working in ps2021
switch (list.getObjectType(i)) // edited 1-aug-2021 by r-bin
{
case stringIDToTypeID("group"):
var nm = list.getObjectValue(i).getString(stringIDToTypeID("name"));
grp.push(nm);
hierarchy.push({path:[]});
for (var x = 0; x < grp.length; x++) hierarchy[hierarchy.length-1].path.push(grp[x]);
break;
case stringIDToTypeID("groupEnd"):
grp.pop();
break;
case stringIDToTypeID("preset"):
hierarchy.push({path:[]});
for (var x = 0; x < grp.length; x++) hierarchy[hierarchy.length-1].path.push(grp[x]);
hierarchy[hierarchy.length-1].pattern = patterns.pop();
break;
}
}
alert(hierarchy.toSource())
}
Copy link to clipboard
Copied
I tried your script in 22.4.3 release to be sure it works with no problem.
I'm getting Internal error (require failed) in switch (list.getClass(i))
Copy link to clipboard
Copied
Provide a file (TMP) that the script uses to parse. I'll take a look (on PS2020).
Copy link to clipboard
Copied
I sent it by Private Message.
I know you have older Ps release, but does the script work on your side (without my .tmp)?
Copy link to clipboard
Copied
On PS2020 your file and "hierarchy" list are parsed without problems or errors. In the screenshot, the names of the patterns are not specified, because I omitted the creation of the patterns array from the presetManager. The array is just empty.
Look for the specific source of the problem and what causes it yourself.
P.S.
Copy link to clipboard
Copied
I finished up in this topic somehow and noticed you created the code for the user but the answer was not marked as correct, so first that came to my mind was: 'aha, another user is asking for help, but when it's given to him, he suddenly vanishes without any feedback'.
As I learnt not once that 'you check everything before posting' as you always 'check your work' I marked the answer as correct. That of course would be stupid to do so without testing whether the code works indeed. There was still chance the user didn't mark the correct solution as the code didn't work for him, that he did not say.
I checked your code myself and that didn't work. So again like in the other topic I met the same situation: either I had to unmark the correct answer or ask you if that does work, however maybe not for me for unknown reason.
Ps. for now I have no idea how to find that specific source of problem 😉
Copy link to clipboard
Copied
22.4.3 same problem
list.getObjectType(i) instead list.getClass(i) works.
P.S. How did you know that after 8BIMphry there is a descriptor in the file? I understand, experience and all that, but the hell, how? 🙂
I found a mention of the 8BIM signature Adobe Photoshop File Formats Specification November 2019, but no more.
Copy link to clipboard
Copied
I changed getClass to getObjectType and it works for me too.
Copy link to clipboard
Copied
Didn't understand how it helped you? All types are a "descriptor" (sort of)
Copy link to clipboard
Copied
I would answer, but I don't know what you ask me now for?
jazz-y figured out it works with getObjectType, so I used it and the code worked.
Copy link to clipboard
Copied
Copy link to clipboard
Copied
@r-bin I tried to create a new object with an arbitrary class ID, put it in an empty List. getClass () doesn't work for that list item. It's weird that this used to work
Copy link to clipboard
Copied
@r-bin I tried to create a new object with an arbitrary class ID, put it in an empty List. getClass () doesn't work for that list item. It's weird that this used to work
By @jazz-y
It would be nice to bring the code.
So you did putClass and then getClass?
Does this not work for ActionList only or for ActionDescriptor too?
Probably a bug, you need to report with an example.
How does this code work for you?
var d = new ActionDescriptor();
d.putClass(stringIDToTypeID("name"), stringIDToTypeID("group"));
alert(d.getClass(stringIDToTypeID("name")))
var d = new ActionList();
d.putClass(stringIDToTypeID("group"));
alert(d.getClass(0))
getClass is used in my eventslistener script, for example when the tool select command is executed.
I wonder how the ScriptListener plugin works. It does not use getClass from the scripted DOM, but must do something similar to get the class from this command.
Copy link to clipboard
Copied
для jazz-y
Ну, во-первых, там структура как у дескриптора, видны всякие там 'Objc', 'TEXT' и прочая лабуда присущая дескриптору. Во-вторых, там магические цифры 00 00 00 10.
fromStream(string) отрабатывает только если строка начинается с этой фигни, я так думаю это версия.
Если fromStream() отработает без ошибок, значит точно десритор. Ну а дальше дело техники разобраться что там. Типо как-то так... 🙂
Copy link to clipboard
Copied
Я посмотрел несколько файлов пресетов. Так понял, что 8BIM - это общее обозначение ресурсов, а phry идет только там, где за ним следует дескриптор, т.е., видимо, это сигнатура его обозначающая.
Спасибо за подсказку, покопаюсь 🙂
Может я загоняюсь, но в документации написано что для actionList getClass - Gets the value of a list element of type class, а getObjectType - Gets the class ID of a list element
of type object. Т.е. одна функция для классов, а другая для объектов.
Copy link to clipboard
Copied
Нет
8BIM или 8B64 это сигнатура ресурса. Далее обычно идёт 4-char название ресурса. В нашем случае это "phry", в других другое. Часто в этих ресурсах сидят дескрипторы. В описании формата (PSD(B)), если читать внимательно, многое описано.
Copy link to clipboard
Copied
Перечитал внимательно - да. Моя ошибка в том, что я смотрел только файлы пресетов, видимо, phry это и есть "пресет".
Copy link to clipboard
Copied
phry == Preset HieRarchY - я так думаю : )
Copy link to clipboard
Copied
Copy link to clipboard
Copied
Wow! Where did you find it?
Copy link to clipboard
Copied
Copy link to clipboard
Copied
@r-bin , sarcasm? 🙂 this pdf is in the archive with other SDK documents