Page 1 of 1

Managing Color Swatches

Posted: Tue Aug 15, 2006 4:15 pm
by xbytor
After this thread (with some helpful input and code from Larry), I've implemented a comprehensive API for working with Swatches.

The external class are SwatchPalette for performing opertaitons on the runtime palette and ColorSwatches for reading and writing swatch files in various formats.

Here's a first cut at the API. It still needs to be tuned and names will probably be tweaked, but the core (including all of the color conversions) appear to be working fine.

SwatchPalette
getColor(name) - get a color by name from the runtime palette. e.g SwatchPalette.getColor("FloralWhite");
saveRuntimeSwatches(file) - save the runtime palette to a .aco file.
addRuntime(color, name) - add a SolidColor to the runtime palette using the given name.
appendSwatchFile(file) - append the swatches in the file to the runtime palette.
loadSwatchFile(file) - replace the rutime palette with the swatches in the file.
deleteFromRuntime(index) - delete the color at the given index. I need to implement a named version.
renameRuntimeSwatch(index, newName) - delete the color at the given index. I need to implement a named version.
resetRuntime - reset the Swatches Palette back to its default values.

ColorSwatches
addColor(color, name) - add a color to a swatches table.
readFromRuntime() - load the runtime palette into a swatche table
readFromACOFile(file) - read in swatches from a .aco file
readFromX11File(file) - read in swatches from an X11-style rgb.txt file
readFromCSVFile(file) - read in swatches from a .csv file
writeToRuntime() - write the swatches table to the runtime palette
writeToACOFile(file) - write the swatches table to a .aco file
writeToTextFile(file) - write the swatches table to a text file
getColorByName(name) - retrieve a color from the table by name

The attached zip file contains the script (with test code), an X11 rgb.txt file, and the rgb.aco file that was generated from the rgb.txt file.

I've already done similar work for layer styles, including the file I/O. I'll probably write up a generic interface for the Palette code now that I've got a better sense on how to use it from JavaScript. The file I/O portions will have to be done on an "as needed" (or an "as funded") basis.

Thanks again to Larry for getting me moving in this direction.

-X

Managing Color Swatches

Posted: Fri May 15, 2009 7:22 pm
by smoothdeity
I downloaded the attached file above and didn't see the API from the post anywhere. I also downloaded xtools and checked for it in there as well. Is it possible that the wrong file got attached, or am I just missing something?

Managing Color Swatches

Posted: Fri May 15, 2009 7:36 pm
by xbytor
I just missing something?

Code: Select allThe external class are SwatchPalette for performing opertaitons on the runtime palette and ColorSwatches for reading and writing swatch files in various formats.


Looking in the xtools/xlib does reveal a file called 'ColorSwatches.jsx' which contains both of the required classes.

Managing Color Swatches

Posted: Fri May 15, 2009 8:17 pm
by smoothdeity
D'oh- I missed them in there. Can't thank you enough- this will be really useful...

Re: Managing Color Swatches

Posted: Thu Aug 01, 2019 1:57 pm
by ssmily32
Hi, where are the files to download plz ?

Re: Managing Color Swatches

Posted: Wed Aug 07, 2019 12:01 am
by Kukurykus