Modification incrémentielle d'un échantillon Indesign avec Extendscript (JavaScript)

Sep 10 2020

J'ai un document InDesign avec le swatch nommé "mySwatch" qui est C10 M20 Y30 K40. J'ai écrit la ligne:

app.activeDocument.colors.item("mySwatch").colorValue = [9,19,30,41];

de changer à un ensemble spécifique de valeurs ( 9,19,30,41), mais je voudrais ajouter ou soustraire à la place des valeurs existantes, disons [ -1, -1, unchanged, +1].

Est-ce possible?

Réponses

fabianmoronzirfas Sep 11 2020 at 11:40

Vous devrez extraire les valeurs en les affectant à une nouvelle variable.

var myvalues = app.activeDocument.colors.item("mySwatch").colorValue

Faites vos opérations sur eux.

myvalues[0] = myvalues[0] - 1

Réaffectez-les à votre échantillon.

app.activeDocument.colors.item("mySwatch").colorValue = myvalues 

(Pas testé)

YuriKhristich Sep 29 2020 at 21:06
function change_color(a, b) {
    return [a[0] += b[0], a[1] += b[1], a[2] += b[2], a[3] += b[3]];
}

var color  = app.activeDocument.colors.item("mySwatch").colorValue; // [10,20,30,40]
var change = [-1, -1,  0,  1];
app.activeDocument.colors.item("mySwatch").colorValue = change_color(color, change); // [9,19,30,41];

Testé.