classID of new ActionDescriptor

Upload Photoshop Scripts, download Photoshop Scripts, Discussion and Support of Photoshop Scripts

Moderators: Tom, Kukurykus

boogalooper
Posts: 4
Joined: Sun Oct 06, 2019 1:51 pm

classID of new ActionDescriptor

Post by boogalooper »

Recently, I needed to write a script that compared the newly created ActionDescpriptor with a previously saved one in the process. I ran into the following problem: the number of properties and their values ​​in the two ActionDescpriptor are the same (I checked this), however functions like .isEqual () or .toStream () show that the objects are different.

This can be demonstrated by the following simplified example:

Code: Select all

#target photoshop
s2t = stringIDToTypeID;

(A = new ActionDescriptor).putInteger(s2t('test'), 0);
(B = new ActionDescriptor).putInteger(s2t('test'), 0);

//(C = new ActionDescriptor).putObject(s2t('test'), s2t('object'), A);
//(D = new ActionDescriptor).putObject(s2t('test'), s2t('object'), B);

alert ('A equal B ? ' + A.isEqual(B) + '\nA toStream B ? ' + (A.toStream ()== B.toStream())+ '\nproperty value from A == property value from B ? ' + (A.getInteger(s2t('test')) == B.getInteger(s2t('test')))  )
If you remove the first comment (line (C = new ActionDescriptor) .putObject (s2t ('test'), s2t ('object'), A)), the script will report that the objects are different (despite the fact that we change ActionDescpriptor A, but just put it in another ActionDescpriptor)

If you remove the second comment (line (D = new ActionDescriptor) .putObject (s2t ('test'), s2t ('object'), B)), the script will report that the objects are the same again.

For a long time I could not understand what was the matter. I tried to parse the .toStream () byte array and saw that when placing ActionDescriptor A in another ActionDescriptor, several characters are appended to its beginning. By exception method, I realized that this is the classID specified when A was placed in C.

I.e:
a) the newly created ActionDescpriptor does not contain a classID
b) if you place this ActionDescpriptor as an object in another ActionDescpriptor, then the original ActionDescpriptor will also be changed - the classID specified in the process of writing to the object will be added to it.

I don’t know why I am writing all this, but maybe this information will be useful to someone. I have previously encountered this problem and I had to parse ActionDescpriptor
on properties to correctly compare, now I understand that it is enough to assign the same classID to two ActionDescpriptor
User avatar
Kukurykus
Posts: 528
Joined: Mon Jul 25, 2016 12:36 pm

Re: classID of new ActionDescriptor

Post by Kukurykus »

In Javascript objects are not equel, even if contain exaclty same content, but maybe in ActionManager that's different.

Anyway thanks for posting it, and how "to assign the same classID to two ActionDescpriptor"? You mean uncommenting D as well?
boogalooper
Posts: 4
Joined: Sun Oct 06, 2019 1:51 pm

Re: classID of new ActionDescriptor

Post by boogalooper »

The ActionManager has the functions .isEqual() and .toSream () (an analogue of .toSource () for ordinary objects) - with their help, if necessary, you can compare ActionDescpriptor objects without sorting them into values. This is not the most common task, but sometimes they are useful.

As far as I understand, the already assigned classID cannot be deleted from the ActionDescriptor, you can only reassign it.

That is, in order to correctly compare the newly created ActionDescriptor and obtained from another object, you must first place the new ActionDescriptor as an object in any other ActionDescriptor with the desired classID assigned.
Last edited by boogalooper on Fri Jun 05, 2020 1:09 pm, edited 1 time in total.
User avatar
Kukurykus
Posts: 528
Joined: Mon Jul 25, 2016 12:36 pm

Re: classID of new ActionDescriptor

Post by Kukurykus »

It seems you can teach me something. How to exaclty check classID?
boogalooper
Posts: 4
Joined: Sun Oct 06, 2019 1:51 pm

Re: classID of new ActionDescriptor

Post by boogalooper »

I know only one way - by the key from the parent ActionDescriptor (actually, that's why I thought that the classID is stored in the parent object). It is unlikely that you did not know about it :)

Code: Select all

#target photoshop
s2t = stringIDToTypeID;
t2s = typeIDToStringID;

(A = new ActionDescriptor).putInteger(s2t('test'), 0);
(B = new ActionDescriptor).putObject(s2t('test'), s2t('object'), A);

alert (t2s(B.getClass (s2t('test'))))
User avatar
Kukurykus
Posts: 528
Joined: Mon Jul 25, 2016 12:36 pm

Re: classID of new ActionDescriptor

Post by Kukurykus »

So only values are still the same:

Code: Select all

sTT = stringIDToTypeID; (dsc1 = new ActionDescriptor).putInteger(sTT(0), 0);
(dsc2 = new ActionDescriptor).putObject(sTT(0), sTT('object'), dsc1)
typeIDToStringID(dsc2.getObjectValue(sTT(0)).getInteger(sTT(0)))