Copy link to clipboard
Copied
I'm a digital painter and comic book colorist, and I'm always on the lookout for ways to speed up my palette creation process. I already have a script that samples all the unique colors of a document and saves them to the swatches panel. What I want now is a way to sort the current swatches by either their H, S, or B values. Does anyone know how I could get an object reference to the current swatches?
To be clear, I know how I could sort an array of colors BEFORE saving them to the swatches panel. I'm looking for a way to take whatever is already in the swatches panel, and sort by hue, saturation, or brightness on the fly without having to save, parse, and reorder an ACO file or something.
Copy link to clipboard
Copied
AFAIK, you can't sort the swatch palette in place. You need to go the ACO route.
Here's some code that might help if you don't already have it:
http://ps-scripts.cvs.sourceforge.net/viewvc/ps-scripts/xtools/xlib/ColorSwatches.jsx
Copy link to clipboard
Copied
As much as I don't want you to be right, I've hit a wall trying to get anything more than grabbing a list of strings for each swatch's name by cycling through the Preset Manager. It's baffling that there's no way to get at this through the object model, honestly.
I've managed to add the sorting behavior I was after to my existing color-sampling script, and I'm going to use the code from the file you linked to to output a sorted ACO from whatever colors may be in the swatches panel at a given time. Close enough, I guess.
Thanks!
Copy link to clipboard
Copied
PS is a half legged giant from the scripting perspective. It's JS DOM seems abadomned since years and the low level scripting "interface" can't be handled by a mortal being. The Script listener plugin don't log the interresting part. BUT it logs the tremendously useful Visual Basic and Applescript instead!
Copy link to clipboard
Copied
The JS/PS DOM does have features added on occasion, most noticeably on the Application class. It's not much but it's there and it would be nice if the added a ChangeLog and an Errata section with each new rev of the docs.
Copy link to clipboard
Copied
What if the community make a new and more complete DOM, using javascript and prototypes?
It could use the users big knowledge of the low level PS calls. It could be an open source project, with volunteers committing to it.
I imagine a layer object which is containing all the possible properties what PS is know about. It would be able to get and set these automatically with low level calls in the background.
A timeline object wich is able to maintain it's frames, frametimes, jump to one its frames, get the number of frames....
A layerSet which is able to recursively walk it's childs and call a function on every child, fold, mark, cache...
I am dreaming. Easy to come out with ideas like this, for me whose knowledge is so little.
Copy link to clipboard
Copied
Ideally, the way to do this would be to add new methods to classes like Document and ArtLayer. Unfortunately, having include files that do this is pretty much impossible. When the PS/JS interpreter starts up classes like Document have not been added to the interpreter so you can't added new methods to Document.prototype. The class objects don't get added until accessed via some other object like app.activeDocument. In light of this I requested that they add a method like $.loadClass("Document") so I could call that then add a bunch of my own methods to Document. This never came about.
I've add new classes in xtools/xlib for objects that don't exist in the PS/JS DOM like ColorSwatches and PresetManager and I imagine others have done this for other parts of PS. I image someone could gather up all of these classes and create a shared repository (maybe after standardizing the interfaces). ps-scripts2.com would be a great place to coordinate this.
Copy link to clipboard
Copied
In writing that ColorSwatches script, did you see a way to access the actual swatch color values (RGB/CMYK mixtures, etc.), or is the swatch name the only thing that can be accessed from the Preset Manager list?
Copy link to clipboard
Copied
The swatch name was the only thing I could get at the time. The only way to get the color values was to write/read an aco file which is done in ColorSwatches.readFromRuntime().