首页 > 解决方案 > 如何在 JS 中指定路径的颜色属性(填充和描边)

问题描述

所以我试图在我的过程中优化一些设计,对于这个任务,我正在为 Illustrator 和 Photoshop 试验 javascript,我现在遇到的问题是绘制、填充和更改路径的笔触颜色。那么如何在 JS 中为 Illustrator 使用一组颜色来填充一种颜色的路径和另一种颜色的描边呢?

正确知道它只是采用我最后声明的 CMYK 颜色并忽略以前的颜色。

代码:

var RectangleColor = new CMYKColor();
RectangleColor.black = 0;
RectangleColor.cyan = 0;
RectangleColor.magenta = 0;
RectangleColor.yellow = 0;

var RectangleColorStroke = new CMYKColor();
RectangleColor.black = 0;
RectangleColor.cyan = 80;
RectangleColor.magenta = 80;
RectangleColor.yellow = 0;

并在绘图方法中

rect.filled = true;
rect.fillColor = RectangleColor;
rect.strokeColor = RectangleColorStroke;

注意:我真的不知道是否存在名为 的属性strokeColor,但由于它没有显示任何错误,因此决定使用它。

标签: javascriptjavascript-objectsphotoshop-script

解决方案


好吧,我知道这不是最干净的方法,但已经找到了方法。

声明了这个变量

  var col = new GrayColor();
  col.gray = 100;

在代码中有这个

var rect = artLayer.pathItems.rectangle (monthsCubeY,monthsCubeX,180,100); //draw rectangle at the selected coordenates
                    monthsCubeX = monthsCubeX + 190; //move the coordenates for the next rectangle
 rect.filled = true; 
 rect.stroked = true; 
 strokeWidth = 1;
 rect.fillColor = RectangleColor;
 strokeColor = col;

我不太了解编码,但这似乎对我有用。


推荐阅读