Example script

A script to see a working case

This script moves the layers in a desired order, and then applies line colors and thickness.

// declaring the document
var doc = app.activeDocument;

const continuous = [];
const dots = [0, 1];
const dashed = [2, 3];
const dashdot = [2, 2, 0, 2];

// layers z-order
var layers = doc.layers;

try {
    var layerToMove = layers["00-Data::00-LB-Bake::05-Trait-Couleur-04-Continu"];
    layerToMove.zOrder(ZOrderMethod.BRINGTOFRONT);
} catch (e) {};

try {
    var layerToMove = layers["00-Data::00-LB-Bake::04-Trait-Couleur-03-Continu"];
    layerToMove.zOrder(ZOrderMethod.BRINGTOFRONT);
} catch (e) {};

try {
    var layerToMove = layers["00-Data::00-LB-Bake::11-Trait-Couleur-05-Pointille"];
    layerToMove.zOrder(ZOrderMethod.BRINGTOFRONT);
} catch (e) {};

try {
    var layerToMove = layers["00-Data::00-LB-Bake::06-Trait-Couleur-05-Continu"];
    layerToMove.zOrder(ZOrderMethod.BRINGTOFRONT);
} catch (e) {};

try {
    var layerToMove = layers["00-Data::00-LB-Bake::02-Trait-Couleur-01-Continu"];
    layerToMove.zOrder(ZOrderMethod.BRINGTOFRONT);
} catch (e) {};

try {
    var layerToMove = layers["00-Data::00-LB-Bake::13-Aplat-Couleur-02"];
    layerToMove.zOrder(ZOrderMethod.BRINGTOFRONT);
} catch (e) {};

try {
    var layerToMove = layers["00-Data::00-LB-Bake::14-Aplat-Couleur-03"];
    layerToMove.zOrder(ZOrderMethod.BRINGTOFRONT);
} catch (e) {};

try {
    var layerToMove = layers["00-Data::00-LB-Bake::15-Aplat-Couleur-04"];
    layerToMove.zOrder(ZOrderMethod.BRINGTOFRONT);
} catch (e) {};

try {
    var layerToMove = layers["00-Data::00-LB-Bake::16-Aplat-Couleur-05"];
    layerToMove.zOrder(ZOrderMethod.BRINGTOFRONT);
} catch (e) {};

try {
    var layerToMove = layers["00-Data::00-LB-Bake::00-Grille-Continu"];
    layerToMove.zOrder(ZOrderMethod.BRINGTOFRONT);
} catch (e) {};


// creating the makeColor function in order to easily handle colors
function makeColor(r, g, b){
    var color = new RGBColor();
    color.red = r;
    color.green = g;
    color.blue = b;
    return color;
};

try {
  lines = doc.layers['00-Data::00-LB-Bake::00-Grille-Continu'].pathItems;
  for (i = 0; i < lines.length; i++) {
    lines[i].strokeDashes = continuous;
    lines[i].strokeColor = makeColor(0,0,0);
    lines[i].strokeWidth = 0.25;
    lines[i].filled = false;
  }
} catch (e) {};

try {
  lines = doc.layers['00-Data::00-LB-Bake::02-Trait-Couleur-01-Continu'].pathItems;
  for (i = 0; i < lines.length; i++) {
    lines[i].strokeDashes = continuous;
    lines[i].strokeColor = makeColor(7, 59, 76);
    lines[i].strokeWidth = 1.00;
    lines[i].filled = false;
  }
} catch (e) {};

try {
  lines = doc.layers['00-Data::00-LB-Bake::04-Trait-Couleur-03-Continu'].pathItems;
  for (i = 0; i < lines.length; i++) {
    lines[i].strokeDashes = continuous;
    lines[i].strokeColor = makeColor(6, 214, 160);
    lines[i].strokeWidth = 1.00;
    lines[i].filled = false;
  }
} catch (e) {};

try {
  lines = doc.layers['00-Data::00-LB-Bake::05-Trait-Couleur-04-Continu'].pathItems;
  for (i = 0; i < lines.length; i++) {
    lines[i].strokeDashes = continuous;
    lines[i].strokeColor = makeColor(255, 209, 102);
    lines[i].strokeWidth = 1.00;
    lines[i].filled = false;
  }
} catch (e) {};

try {
  lines = doc.layers['00-Data::00-LB-Bake::06-Trait-Couleur-05-Continu'].pathItems;
  for (i = 0; i < lines.length; i++) {
    lines[i].strokeDashes = continuous;
    lines[i].strokeColor = makeColor(239, 71, 111);
    lines[i].strokeWidth = 1.00;
    lines[i].filled = false;
  }
} catch (e) {};

try {
  lines = doc.layers['00-Data::00-LB-Bake::11-Trait-Couleur-05-Pointille'].pathItems;
  for (i = 0; i < lines.length; i++) {
    lines[i].strokeDashes = dashed;
    lines[i].strokeColor = makeColor(239, 71, 111);
    lines[i].strokeWidth = 1.00;
    lines[i].filled = false;
  }
} catch (e) {};

try {
  lines = doc.layers['00-Data::00-LB-Bake::13-Aplat-Couleur-02'].pathItems;
  for (i = 0; i < lines.length; i++) {
    lines[i].strokeDashes = continuous;
    lines[i].strokeColor = makeColor(0, 0, 0);
    lines[i].strokeWidth = 0.25;
    lines[i].filled = true;
    lines[i].fillColor = makeColor(17, 138, 178);
  }
} catch (e) {};

try {
  lines = doc.layers['00-Data::00-LB-Bake::14-Aplat-Couleur-03'].pathItems;
  for (i = 0; i < lines.length; i++) {
    lines[i].strokeDashes = continuous;
    lines[i].strokeColor = makeColor(0, 0, 0);
    lines[i].strokeWidth = 0.25;
    lines[i].filled = true;
    lines[i].fillColor = makeColor(6, 214, 160);
  }
} catch (e) {};

try {
  lines = doc.layers['00-Data::00-LB-Bake::15-Aplat-Couleur-04'].pathItems;
  for (i = 0; i < lines.length; i++) {
    lines[i].strokeDashes = continuous;
    lines[i].strokeColor = makeColor(0, 0, 0);
    lines[i].strokeWidth = 0.25;
    lines[i].filled = true;
    lines[i].fillColor = makeColor(255, 209, 102);
  }
} catch (e) {};

try {
  lines = doc.layers['00-Data::00-LB-Bake::16-Aplat-Couleur-05'].pathItems;
  for (i = 0; i < lines.length; i++) {
    lines[i].strokeDashes = continuous;
    lines[i].strokeColor = makeColor(0, 0, 0);
    lines[i].strokeWidth = 0.25;
    lines[i].filled = true;
    lines[i].fillColor = makeColor(239, 71, 111);
  }
} catch (e) {};

Last updated