Skip to main content
This topic has been closed for replies.

6 replies

Lumenn
Inspiring
August 8, 2019

Yeah, this code creates only one color, if you want to add more, the best shot will be to close this in a for loop.

Jon Fritz
Community Expert
August 8, 2019

Oops, nevermind, I mistook Ten A for the original poster.

Ten A
Community Expert
August 9, 2019

No problem, Jon. (^_^)/

I added more detail, How to determine loop length and do looping.

However, It's necessary to know XML structure when we read it and processing children.

var colour =

<root>

   <color id="clr1">

      <cyan>80</cyan>

      <magenta>30</magenta>

      <yellow>0</yellow>

      <black>0</black>

   </color>

   <color id="clr2">

      <cyan>50</cyan>

      <magenta>0</magenta>

      <yellow>100</yellow>

      <black>0</black>

   </color>

   <color id="clr3">

      <cyan>0</cyan>

      <magenta>50</magenta>

      <yellow>100</yellow>

      <black>0</black>

   </color>

   <color id="clr4">

      <cyan>00</cyan>

      <magenta>40</magenta>

      <yellow>20</yellow>

      <black>35</black>

   </color>

   <color id="clr5">

      <cyan>0</cyan>

      <magenta>0</magenta>

      <yellow>50</yellow>

      <black>50</black>

   </color>

</root>;

var xml = new XML(colour);

var num = xml.children().length();

var clr, newSwatch;

for (var i=0;i<num;i++){

clr = new CMYKColor();

clr.cyan = Number(xml.children().cyan);

clr.magenta = Number(xml.children().magenta);

clr.yellow = Number(xml.children().yellow);

clr.black = Number(xml.children().black);

newSwatch = app.activeDocument.swatches.add();

newSwatch.color = clr;

}

Ten A
Community Expert
August 8, 2019

Can you show pice of your XML?

Here is an example code, Work with XML.

var colour =

<root>

   <color id="clr1">

      <cyan>80</cyan>

      <magenta>30</magenta>

      <yellow>0</yellow>

      <black>0</black>

   </color>

   <color id="clr2">

      <cyan>80</cyan>

      <magenta>30</magenta>

      <yellow>0</yellow>

      <black>0</black>

   </color>

</root>;

var xml = new XML(colour);

var clr = new CMYKColor();

clr.cyan = Number(xml.color.(@id=="clr1").cyan);

clr.magenta = Number(xml.color.(@id=="clr1").magenta);

clr.yellow = Number(xml.color.(@id=="clr1").yellow);

clr.black = Number(xml.color.(@id=="clr1").black);

var newSwatch = app.activeDocument.swatches.add();

newSwatch.color = clr;

Jon Fritz
Community Expert
August 8, 2019

There's gotta be more to the code than that, isn't there?

Right now, they only have code for one color (even though they create ids for two)

CMYK: 80, 30, 0, 0

Jon Fritz
Community Expert
August 7, 2019

The XML file should be using colors that are valid under html. Those colors should be easily duplicated in the AI or PS color pallets. There are fields for pretty much all of them built in.

For example...

"background-color: rgb(52,0,246);"

....is simply...

R: 52
G: 0
B: 246

...in AI's color pallet and...

"color: #3400f6;"


..is just 3400f6 in the # field on the bottom of the color pallet.

If you need help discerning what the colors are in the code, post it here and I should be able to separate them out pretty easily for you.

Srishti Bali
Community Manager
Community Manager
August 7, 2019

Hi Praveen,

I agree with Mylenium, there is no way of doing this directly in Illustrator, however, it might be possible through scripting. Hence, I am moving this discussion to Illustrator Scripting community, so that you can get some more responses from our scripting experts.

You can also check out some suggestions shared on this similar discussion : Importing Color to Swatch Library from Text File​ and see if that works.

Regards,

Srishti

Monika Gause
Community Expert
August 7, 2019

You could try if any other CC app can make anything out of the XML and then create swatches from there and put them into the CC libraries to transfer them to Illustrator.

I would try Dreamweaver or XD (and maybe take a look at XD plugins if it still doesn't work.

Mylenium
Brainiac
August 7, 2019

There is no such functionality. You would need to create a script that converts the values to ASE or whatever so they can be imported into the color palette.

Mylenium