• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
1

how to write Adobe Swatch Exchange ase file

Explorer ,
Nov 28, 2019 Nov 28, 2019

Copy link to clipboard

Copied

good morning community,

do you know if there is a already functioning solution to produce Adobe Swatch Exchange ase file starting from a simple txt or xml file?

I've a lot of color to import in my ID.

 

Thx, Milko

TOPICS
How to , Print , Scripting

Views

3.7K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 28, 2019 Nov 28, 2019

Copy link to clipboard

Copied

Try https://www.cyotek.com/blog/reading-adobe-swatch-exchange-ase-files-using-csharp

It's for reading, not writing, and the source code is for C#, not Javascript or Applescript or VBA, but the writer explains the file structure in that article. There is also a follow-up: https://www.cyotek.com/blog/writing-adobe-swatch-exchange-ase-files-using-csharp -- but that 'only' writes back the values that are read. Still worth briefly checking out as the writer examines a potential bug in depth and you may need to do the same thing.

Only then in Javascript.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Nov 28, 2019 Nov 28, 2019

Copy link to clipboard

Copied

hello Jongware_

thx for your help.

the file structure from the 1st link its ok,

despite this I'm looking for something already created  😄

thx

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 01, 2019 Dec 01, 2019

Copy link to clipboard

Copied

I've checked around and there is nothing existing. So that's your answer.

...

Oh alright, let's have a bit of fun! The pages I pointed you towards are a great start; I had an ASE reader up and running in no time. Fortunately, Adobe software comes with *lots* of sample ASE files to test with, even though they all seem to be using CMYK. But creating samples is as easy as defining some random colors in InDesign and then exporting them.

With that successfully done, the next step is to write them. In theory, easy as π. In practice: not so much. I have often lamented the lack of modern features in JavaScript, and lo and behold, reading and writing floating point numbers is one of them. I've concocted my own read-and-write float routines below, so if it does not work for you that might be the problem. However, of course I tested this and the small list of CSS color names and their values happily import into InDesign, so I declare this Mission Accomplished.

As you can see, at the start there is a simple array of name, red,green,blue values. You did not specify the input format in detail, nor what the color model should be, but I made sure to document my code for practically every line you'd need to change for different formats and so I am sure this should give you a good start in changing it per your unnamed requirements.

 

 

 

//DESCRIPTION:Create ASE file from array
// A Jongware Script 01-Dec-2019
source = [
	'darkkhaki',189,183,107,
	'darkmagenta',139,0,139,
	'darkolivegreen',85,107,47,
	'darkorange',255,140,0,
	'darkorchid',153,50,204,
	'darkred',139,0,0,
	'darksalmon',233,150,122,
	'darkseagreen',143,188,143
];

File.prototype.writeLong = function (value)
{
	var buf = String.fromCharCode((value>>24) & 0xff)+String.fromCharCode((value>>16) & 0xff)+String.fromCharCode((value>>8) & 0xff)+String.fromCharCode((value>>0) & 0xff);
	this.write (buf);
}

File.prototype.writeShort = function (value)
{
	var buf = String.fromCharCode((value>>8) & 0xff)+String.fromCharCode((value>>0) & 0xff);
	this.write (buf);
}

/* warning: not tested for invalid numbers such as
   too small, too large, or +/-Inf */
/* (so you have been warned) */
File.prototype.writeFloat = function (value)
{
	var sign,value,exponent,mantissa_pre,mantissa,i;
	if (value == 0)
	{
		this.writeLong(0);
		return;
	}
	sign = value < 0 ? 0x80000000 : 0;
	value = Math.abs(value);
	exponent = 127;
	if (value <= 1)
	{
		while (value < 1)
		{
			exponent--;
			value *= 2;
		}
	} else
	{
		/* tested 'caus I need it! */
		while (value >= 2)
		{
			exponent++;
			value /= 2;
		}
	}
	mantissa_pre = value-Math.floor(value);
	/* rough conversion to binary */
	mantissa = 0;
	for (i=0; i<22; i++)
	{
		mantissa_pre *= 2;
		mantissa <<= 1;
		mantissa += (mantissa_pre>>0);
		mantissa_pre -= (mantissa_pre>>0);
	}
	/* final bit */
	mantissa <<= 1;
	mantissa_pre = Math.round(2*mantissa_pre);
	mantissa += (mantissa_pre>>0);
	/* concatenate all */
	result = sign + (exponent<<23)+mantissa;
	this.writeLong (result);
}

aseFile = File(Folder.myDocuments+'/mylist.ase')
if (aseFile.open('w') == false)
{
	alert ('okay, we cannot write that file');
	exit();
}
aseFile.encoding = "binary";

/* Signature */
aseFile.write ('ASEF');
aseFile.writeLong(0x10000);

/* Number of colors */
aseFile.writeLong(source.length/4);

/* The colors themselves */
for (i=0; i<source.length/4; i++)
{
	/* Block type: color */
	aseFile.writeShort(1);
	/* Block length: nameLength + 2*name + '0,0' + 'mode' + 3*value + 'type' */
	aseFile.writeLong (2+2*source[4*i].length+2+4+3*4+2);
	/* Name, in unicode (presumably!) */
	aseFile.writeShort (source[4*i].length+1);
	for (j=0; j<source[4*i].length; j++)
	{
		aseFile.writeShort(source[4*i].charCodeAt(j));
	}
	/* .. terminating 0 .. */
	aseFile.writeShort(0);
	/* Mode: RGB */
	aseFile.write ('RGB ');
	/* Values */
	r = source[4*i+1]/255;
	g = source[4*i+2]/255;
	b = source[4*i+3]/255;
	aseFile.writeFloat(r);
	aseFile.writeFloat(g);
	aseFile.writeFloat(b);
	/* type: normal */
	aseFile.writeShort(0);
}
aseFile.close();

 

 

(Edit: Ah – the ol' OCD kicking in. I just had to re-visit that writeFloat and check if it could write larger numbers as well. It didn't so I fixed it, just in case it's of any use for anyone else.)

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Dec 14, 2021 Dec 14, 2021

Copy link to clipboard

Copied

This is awesome work!  I think it's taken somebody 2 years to acknowledge your effort 🙂  It's really helped me, just wanted to say a massive thank you!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 14, 2021 Dec 14, 2021

Copy link to clipboard

Copied

quote

  It's really helped me, just wanted to say a massive thank you!

Unfortunately, Jongware will never read your thanks…

https://community.adobe.com/t5/indesign-discussions/theunis-de-jong-1966-2020/m-p/11653669

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jan 13, 2022 Jan 13, 2022

Copy link to clipboard

Copied

I have done mobile iPhone/iPad app for that, also it can be started on macOS M1. Wide support of different formats for import and export. You can use such format as gpl, it is a plain text.
Color Palette Finder 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Feb 01, 2022 Feb 01, 2022

Copy link to clipboard

Copied

LATEST

If the colours are in a format that are valid SVG-colors (let's say: HTML/CSS colors) and you do not need the names of the colors to be stored in the swatches and you have access to Illustrator, then:

  1. Create a SVG file with 1 rectangle per color. (*)
  2. Open the SVG file in Illustrator
  3. Select all artwork, open Swatches panel, choose create new Color Group --> DONE

 

At 1, (*):

Use an advanced text-editor like TextMate that allows for multi-caret selection. Paste the list of colors into the editor and make sure there is a cursor (caret) in front off every color. Now, you can wrap each color in a SVG-rect tag, as such:

<rect width='10' height='10' fill='#F5D6B2' />

You can do this for all colours simultaneously! Add an '<svg>' tag in the front and a </svg> closing tag at the end, save as "MyFirstColorList.svg" or whatever and open in Illustrator.

 

Note also that:

  1. This might also be possible in InDesign straight away, but I do not know that.
  2. Turning a list of colors into a list of rectangles might also be possible with command-line magic or smart search-and-replacing in MSWord or any other text-editor or word processor.

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines