Bonjour, /*Utilisation du script : 1 Ouvrir ou créer un fichier (.ai) Mode de colorimétrie RVG ou CMJN, 2 importer le fichier texte .csv, et placer le caractère @ au début de la première ligne, Corinthien,0,35,15,0, si le texte est captif pas besion d'ajuster, le contenu est dans la mémoire. 3 lancer le script, Remarque: Si pas de texte le tableau mapObjt est pris en compte. */ // JavaScript Document for Illustrator
//paletteCouleurCMJN_01.js
// Landry René - elleere Fri, 23 March 2018 10:16:41 GMT
//------------------------------------------------------
/*Utilisation du script :
1 Ouvrir ou créer un fichier (.ai) Mode de colorimétrie RVG ou CMJN,
2 importer le fichier texte .csv, et placer le caractère @
au début de la première ligne, Corinthien,0,35,15,0, si le texte est captif pas besion d'ajuster,
le contenu est dans la mémoire.
3 lancer le script,
Remarque: Si pas de texte le tableau mapObjt est pris en compte.
*/
//-----------------------------------------------------------
var indice = "@"; // indice pour indentifier le bon texte
var sep1 = "\r"; // saut ligne
var sep2 = ","; // séparateur (non <- couleur CMJN))
var Grpname = "Ral_Perso"; // nom du groupe de nuances
var mapObjt = [["Rose Corinthien",0, 35, 15, 0],["Vert pomme",100,12,50,10]];
//-------------
var docRef = activeDocument;
var ok = false;
if (docRef.textFrames.length) {
for (var t = 0; t < docRef.textFrames.length; t++) {
var text = docRef.textFrames[t];
if (text.contents.charAt(0) == indice) {
ok = true;
break;
}
}
}
if (ok) mapObjt = initTab(text,indice,sep1,sep2)
var grp = docRef.swatchGroups.add();
grp.name = Grpname;
for (var i = 0; i < mapObjt.length; i++) {
couleur = macmykColor(mapObjt[i]);
sw =docRef.swatches.add();
sw.color = couleur;
sw.name = mapObjt[i][0];
grp.addSwatch(sw);
}
//--------
function initTab(text,indice,s1,s2) {
// Initialisation d'un tableau à 2 dimensions
var textContent = text.contents;
textContent = textContent.substring(1);
var tab = textContent.split(s1);
for (var i = 0; i < tab.length; i++) {
tab[i] = tab[i].split(s2);
}
return tab;
}
//--------
function macmykColor(c)
{ //cree une nouvelle couleur CMJN
var cmykColor = new CMYKColor();
with (cmykColor) {cyan = c[1]*1; magenta = c[2]*1; yellow = c[3]*1; black = c[4]*1;}
return cmykColor;
}
//-------- Exemple de texte correspondant au tableau mapObjt
... View more