Skip to main content
Participant
February 6, 2021
Question

Change color of Path Item using JavaScript

  • February 6, 2021
  • 1 reply
  • 359 views

Hello, I'm using the following function below to draw some lines in photoshop.

 

What I'm wondering is, how does one change the color of a path before drawing it? I haven't been able to find anything on changing color for paths specifically. 

 

 

function drawLine(doc, start, stop) {

var startPoint = new PathPointInfo();

startPoint.anchor = start;

startPoint.leftDirection = start;

startPoint.rightDirection = start;

startPoint.kind = PointKind.CORNERPOINT;

var stopPoint = new PathPointInfo();

stopPoint.anchor = stop;

stopPoint.leftDirection = stop;

stopPoint.rightDirection = stop;

stopPoint.kind = PointKind.CORNERPOINT;

 

var spi = new SubPathInfo();

spi.closed = false;

spi.operation = ShapeOperation.SHAPEXOR;

spi.entireSubPath = [startPoint, stopPoint];

var line = doc.pathItems.add("Line", [spi]);

line.strokePath(ToolType.PENCIL);

line.remove();

};

drawLine(app.activeDocument, [100,100], [200,200]);

 

This topic has been closed for replies.

1 reply

Chuck Uebele
Community Expert
Community Expert
February 6, 2021

Use scriptListener to record changing the path color, then you can replace the color numbers with variables to script the color change. Kind of have to do this after you draw the path and convert it to a shape. 

Participant
February 6, 2021

Oh I didn't know about script listener. Awesome I will try that.

 

Thank you