charIDToTypeID and stringIDToTypeID

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

Moderators: xbytor, DavideBarranca, Paul MR

User avatar
Kukurykus
Posts: 176
Joined: Mon Jul 25, 2016 12:36 pm

charIDToTypeID and stringIDToTypeID

Postby Kukurykus » Sun Dec 25, 2016 1:03 am

I just finished writing new program, however made before by Mikaeru69, though I never neither saw his code or ran myself. I heard that takes 5 minutes to get the result. Either it's wrote some specific way it works such time (maybe because later it's rewritten to json, if it is) or it does some other stuff I'm not aware of.

Following script is doing as follows:

- from 18`974`736 four characters codes it searches for Photoshop 1779 (CS 5.1) of them ie. charIDToTypeID
- it checks is each of them used as string ie. stringIDToTypeID, so can recognise those used for Photoshop
- right after a script is ran you get the choise to process slower way with progress bar, or faster, without
- when Progress Bar was checked then a script can be cancelled by pressing ESC (between every 100 found chars)
- there's chance to stop process at all, or (make manually a loop to) continue it and stop again (to quit it)
- however process was cancelled or not a cs.txt file will be created on Desktop with appropiate un/full content

On my Computer with Windows 10 and Ps 5.1 x64 it took 86 seconds with progress bar and 69 seconds without

Depends on what version of Photoshop a user got it finds so much Photoshop chars/strings (1779 for CS 5.1)
A titbit of news: on CS2 with no progress bar a process took 49 seconds, but there was just 1752 rows/lines


I hope you have fun, but if not by finding some bugs or ideas how to enhance this script let me know!

Code: Select all

#target photoshop

function SPC(v) {spc = ''; while(spc.length < v) {spc += '\u00A0'}; return spc}
function rw(v1, v2, v3) {v2.open(v1), v1 < 'w' ? v3 = v2.read() : v2.write(v3), v2.close(); return v3};

var lst = [], ESC, I = 0, esc = false, ARR = [];

(win = new Window("dialog", SPC(6) + 'Would you like:')).margins = 5; win.spacing = 5
for(var i = 0; i <= 1; i++) {
win.add('radiobutton', undefined, !i ?'Slower with progressBar,' : 'or 1 / 4 faster without ?')
}
win.ok = win.add ("button", [0, 0, 160, 29], "OK", {name:'close'}), win.children[0].value = true, win.show()
yon = win.children[0].value == true ? true : false

ASC =[], arr = [], asc(32, 33), asc(35, 36), asc(48, 58), asc(64, 91), asc(94, 95), asc(97, 123)
function asc(v1, v2){for(i = v1; i < v2; i++) {ASC.push(String.fromCharCode(v1++))}}

function spd(v) {
function pgb(v) {
eval("win.bar = (win = new Window('palette', (txt = 'Wait to end of this process...') &&\
yon ? SPC(3) + txt : ''))" + (yon ?".add('progressbar', [0,0,177.9, 35], n = 0, w = 1779)" :
".add('statictext {text:' + uneval(txt) + '}')")), win.margins = 5; return win
}
(function beg(){try{PGB= pgb(v), win.show(), refresh()} catch(errBef) {beg()}})()
}

SPD = spd(yon); // as result 1/3 slower with progressBar, or faster without

(function rot(v) {
try{
function prc(v) {
for(i = v; i < len = ASC.length; i++) {for(j = 0; j <len; j++) {for(k = 0; k < len; k++) {for(l = 0; l < len; l++) {
(str = typeIDToStringID(charIDToTypeID(chr = ASC[i] + ASC[j] + ASC[k] + ASC[l]))) ?
(arr.push('\n' + chr + (function(){for(s = ' ', (S = 30 - str.length), L = 0; L <= S; L++) s += ' '; return s})() + str),
yon ? (n++, ((n == w) || !(n % 100)) ? (PGB.bar.value = n + 1, refresh()) : n) : null) : null
if (esc) (lst.push(arr[arr.length - 1].match(/.*$/))), ESC = esc, esc = false
}}}}
}
prc(v || 0)
}
catch(err) {
win.close(), bol = false; function okn() {
grp = (win = new Window('dialog')).add('group')
cnt = grp.add('button', undefined, 'Continue'), cnl = grp.add('button', undefined, 'Cancel')
cnt.onClick = function () {win.close(), bol = true, esc = true, SPD = spd(yon), n = arr.length, PGB.bar.value = n, rot(i)}
cnl.onClick = function () {win.close(), bol = true}, win.show()
}
while (!bol) okn()
}
})()

rw('w', File('~/Desktop/cs.txt'), (STR = "String(arr).replace(/,/g, '')") && lst.length ?
(function(){while(lst.length) {var r = (r || eval(STR)).replace(RegExp('((?:[\\w #@^]*\\n)*)(' + lst[0] +
')\\n(?:[\\w #@^]*\\n)*?' + lst[0] + '((?:\\n[\\w #@^]*)*)', 'g'), '$1$2$3'); LST = lst.shift()}; return r})() : eval(STR))
DOWNLOAD BOTH TWO FILES:
(+1 times before replacement)
Attachments
Chars and Strings.rar
(1.53 KiB) Downloaded 141 times
Last edited by Kukurykus on Mon Jan 02, 2017 12:32 am, edited 1 time in total.

xbytor
Posts: 20
Joined: Thu Jan 01, 1970 12:00 am

Re: charIDToTypeID and stringIDToTypeID

Postby xbytor » Sun Dec 25, 2016 2:07 am

Just a quick note about ProgressBar stuff, it may be better to update the progress bar every 4 or 10 or more iterations instead of every iteration. In general, I would take what ever the total was and use 5% as the update chunk so there would only be 20 ProgressBar updates regardless of how many iterations are required.

User avatar
Kukurykus
Posts: 176
Joined: Mon Jul 25, 2016 12:36 pm

Re: charIDToTypeID and stringIDToTypeID

Postby Kukurykus » Sun Dec 25, 2016 2:20 am

Yes, you are right, it would take too long if it'd update every iteration, but fortunatelly I did so that progress bar updates takes palce every 100 iterations, I mean every 100 found Photoshop 4 characters from about 1779, not every 100 of all 66 x 66 x 66 x 66 combinations :D Normally without progress bar it takes as I mentioned 69 seconds on my computer, while with progress bar just 16 seconds more, so not much to even norrow down using a refresh function :) Now there are only 17 progress bar updates, so just 1 procent of all possible cases. It's almost like you proposed to do, so I'm happy to say I speak the same language with Xbytor ;)
Last edited by Kukurykus on Sun Dec 25, 2016 2:28 am, edited 1 time in total.

xbytor
Posts: 20
Joined: Thu Jan 01, 1970 12:00 am

Re: charIDToTypeID and stringIDToTypeID

Postby xbytor » Sun Dec 25, 2016 2:27 am

Also, xtools/xlib/PSConstants.js might be relevant here. It's auto generated via a perl script from PS SDK header files. If , it lets you use
PSKey.Shadow instead of charIDToTypeID("shdw").

xbytor
Posts: 20
Joined: Thu Jan 01, 1970 12:00 am

Re: charIDToTypeID and stringIDToTypeID

Postby xbytor » Sun Dec 25, 2016 2:30 am

Now there are only 17 progress bar updates
Ah. I didn't look at you code in depth. It's good to see that we are both on the same page here.

User avatar
Kukurykus
Posts: 176
Joined: Mon Jul 25, 2016 12:36 pm

Re: charIDToTypeID and stringIDToTypeID

Postby Kukurykus » Sun Dec 25, 2016 2:32 am

Yes I saw this functionality in some of your scripts and I loved it much. Only I look more into I'm going to use it, as writing even in shortened form brackets and quotation marks isn't that I like to do! :x That even looks much better: PSKey.Shadow than shorter cTT("shdw"), the only what could be bad for others (or maybe not as its shape is quite visible) is that in ExtendScript Editor it would be visible in the same colour as other regular code, not green (if set) for plain text for example.

JavierAroche
Posts: 29
Joined: Sat Jul 30, 2016 3:52 am

Re: charIDToTypeID and stringIDToTypeID

Postby JavierAroche » Wed Dec 28, 2016 4:07 am

Hey Kukurykus, this is pretty interesting! I'm still trying to identify exactly how you get these values :)

I've been depending on xbytor's PSConstants, but it's pretty cool that you can get them directly from ExtendScript. Do you know if this script produces the same number of constants as xbytor's?

Btw, you might want to add quotes for the charIDs. Some of them might have spaces.
For example, the layer constant:
Lyr layer
We know it's a 4 char constant, but it might be hard for newer users to know that it is actually "Lyr ". You could add quotes like this:
"Lyr " layer

Good job man!

User avatar
Kukurykus
Posts: 176
Joined: Mon Jul 25, 2016 12:36 pm

Re: charIDToTypeID and stringIDToTypeID

Postby Kukurykus » Wed Dec 28, 2016 5:43 am

Yes, always good ideas from you as I recently noticed. I'm going to that thing with quotes! And after all they'll get one colour if copied to extendscript, as there are regular text, strings, numbers, system names and reserved names.

That wasn't taken by ExtendScript, but Photoshop. In only ESTK it wouldn't work, or you meant Extendscript as language used by Photoshop :)

The only thing I had to see how works is how to convert chars to strings, and after putting appropiate phrase to Adobe forums finder I got my answer from one of Paul Riggott reply.

To check any individual result of such convertion you only need to put in Extendscript (with Photoshop pointe) on) for example: typeIDToStringID(charIDToTypeID('Lyr '))

Regarding the same number of constants, you had to link me to them in Xbytor works, so I'm going to check it, but if you mean those long numbers for ex. (just a hit: 734592740573047) I thought to generate them as well in the third column, as I think they are stable. Probably I'll do so in a next verstion. Now I didn't because I saw them only in some of R.I.P Mke Hall scripts, but never tried myself.


Ps. please answer to my question in my previous topic, as I'm lost about how to implement that clipboard thing. I think I described everything what exactly didn't work. Maybe you'll have at least some suggestion, because it's true as far as many people use Mac's it's not nice to make help of external Windows programs: https://forums.adobe.com/thread/2249343


UPDATE1: it was easy to put in quotes every single character from characters column. I'll update a code later, probably together with those constants you mentioned (if we talk about the same thing). For now I'll show only how certain line will be look after replacement to achive those quotes in result:

Code: Select all

(arr.push('\n' + chr + (function(){for(s = ' ', (S=30-str.length), L = 0; L <= S; L++) s += ' '; return s})() + str),
for:

Code: Select all

(arr.push('\n"' + chr + '"' + (function(){for(s = ' ', (S=30-str.length), L=0; L<=S; L++) s += ' '; return s})() + str),
so this part:

Code: Select all

'\n' + chr +
for this:

Code: Select all

'\n"' + chr + '"' +

UPDATE2: Now when we know result of all combinations, it's possible to write an algorithm, that it many skips empty searches. For example there is no character starting from whitespace, but my pattern included it, like many other combinations, for ex. there is only one time where it uses ^ and @ characters in "c@#^", but it searches for combinations with this characters from beginning to the end. Well, if I excluded many searching cases then process could last much less than now. For example for sure a process with progress bar could be faster than now it's witout it, while process without progress bar if it takes 69 on my computer could be maybe over twice less, so about 30 seconds! When I have time maybe I write such algorithm. It could help to work with this script not once a time but at the moment of working with other scripts when you need to call many constants (perhaps not all) at once.

JavierAroche
Posts: 29
Joined: Sat Jul 30, 2016 3:52 am

Re: charIDToTypeID and stringIDToTypeID

Postby JavierAroche » Sat Dec 31, 2016 5:07 am

Hey Kukurykus, sorry I haven't been online as much these days

Code: Select all

'\n"' + chr + '"' +
Cool! Yeah adding those quotes will help developers not get frustrated when their charID doesn't work :)
The only thing I had to see how works is how to convert chars to strings, and after putting appropiate phrase to Adobe forums finder I got my answer from one of Paul Riggott reply.
I'll look into this :)
Regarding the same number of constants, you had to link me to them in Xbytor works, so I'm going to check it, but if you mean those long numbers for ex. (just a hit: 734592740573047) I thought to generate them as well in the third column, as I think they are stable. Probably I'll do so in a next verstion. Now I didn't because I saw them only in some of R.I.P Mke Hall scripts, but never tried myself.
I'm talking about the PSConstants file that xbytor generated, and was talking about in his post above. I don't think those long numbers are needed. They're not descriptive at all.
http://ps-scripts.cvs.sourceforge.net/v ... iew=markup
Ps. please answer to my question in my previous topic, as I'm lost about how to implement that clipboard thing.
Ah sure thing! Sorry I totally missed that. I'll look into it :)

User avatar
Kukurykus
Posts: 176
Joined: Mon Jul 25, 2016 12:36 pm

Re: charIDToTypeID and stringIDToTypeID

Postby Kukurykus » Sat Dec 31, 2016 12:28 pm

Javier, thx for all replys. Of course I'm going to check is it working with xbytor constans, or I do my best it could work. Let me only finish my next project. Originally that had to be used only in a job where I work, but I found it might be good time (coming new year) to change that a little it won't be same a company I work for is going to use (actually used so far but manually). I'm talking about calendar beeing generated by Photoshop after you'll specify a month and a year only you want that was used as first month of that year to strat off with following next 13 months.

Ah and that topic I need your help with is: https://forums.adobe.com/thread/2249343 / Don't hurry up, just keep in mind ;)


Return to “Photoshop Scripts”

Who is online

Users browsing this forum: No registered users and 5 guests