Javascript 如何使用CMYK build的步长增量向新矩形添加颜色构建
我正在努力建立一个颜色样本书。我只是先从CMYK开始,一旦我首先建立了CMYK,我就会用这种格式进入其他领域。我已经能够开发出所有需要的容器,但我无法为这些盒子添加填充色。我觉得我不知道该怎么做。有人能帮我一下吗?下面是我的脚本。请记住,我的CMYK值必须能够作为变量ex输入 Var c=0 Var m=0 变量y=0 Var k=0 当我在一个循环中运行它时,我将它增加5%,所以它将是c=c+5,然后它将在我的循环中迭代Javascript 如何使用CMYK build的步长增量向新矩形添加颜色构建,javascript,adobe-indesign,Javascript,Adobe Indesign,我正在努力建立一个颜色样本书。我只是先从CMYK开始,一旦我首先建立了CMYK,我就会用这种格式进入其他领域。我已经能够开发出所有需要的容器,但我无法为这些盒子添加填充色。我觉得我不知道该怎么做。有人能帮我一下吗?下面是我的脚本。请记住,我的CMYK值必须能够作为变量ex输入 Var c=0 Var m=0 变量y=0 Var k=0 当我在一个循环中运行它时,我将它增加5%,所以它将是c=c+5,然后它将在我的循环中迭代 myDocument = app.activeDocument;
myDocument = app.activeDocument;
{//Create a layer to hold the printers marks (if it does not already exist).
var myLayer = myDocument.layers.item("ColorSwatches");
try{
myLayerName = myLayer.name;
}
catch (myError){
var myLayer = myDocument.layers.add({name:"ColorSwatches"});
}
}
//Create Rectangle
//Set the bounds of the rectangle [x1, y1, x2, y2]
//The x1, y1 refers to the upper left coordinate position; the x2, y2 refers to the lower right coordinate
//x2 = Height and y2 = Width
var myPage = myDocument.pages.item(0);
var y1=1.76
var y2=2.21
var x1=1.05
var x2=1.5
for (i = 0; i<105; i=i+5) {
for (m=0;m<105;m=m+5){
var myRectangle = myPage.rectangles.add({geometricBounds:[x1, y1, x2, y2]});
y1=y1+.50
y2=y2+.50
}
y1=1.76
y2=2.21
x1=x1+.50
x2=x2+.50
}
myDocument=app.activeDocument;
{//创建一个层来保存打印机标记(如果它不存在)。
var myLayer=myDocument.layers.item(“色样”);
试一试{
myLayerName=myLayer.name;
}
捕获(myError){
var myLayer=myDocument.layers.add({name:“colorsatches”});
}
}
//创建矩形
//设置矩形[x1,y1,x2,y2]的边界
//x1,y1表示左上角的坐标位置;x2,y2表示右下角的坐标
//x2=高度,y2=宽度
var myPage=myDocument.pages.item(0);
变量y1=1.76
变量y2=2.21
var x1=1.05
var x2=1.5
对于(i=0;i矩形对象具有fillColor属性:
myRectangle.fillColor[5,5,5,5];
必须创建样例并将其应用于矩形:
var myDoc = app.documents[0];
var myRectangle = myDoc.rectangles[0];
var myColor = myDoc.colors.add();
myColor.colorValue = [5,5,5,5];
myColor.name = "My New Color";
myRectangle.fillColor = myColor;
这是基于Kasyan Servetsky对此帖子的回复一些评论:
- 根据ID Obj模型object.geometricBounds坐标顺序为y1、x1、y2、x2-->其中“y”为垂直,“x”为水平;“1”为垂直,“2”为右下
你认为在增加步长=5?< < /P> 时要创建颜色计数。
测试以下示例代码:
const
myDocument = app.activeDocument,
myPage = myDocument.pages[0],
recLimit = 441, // count of rectangles to be created
colorValueJumper = 5,
boxSide = Math.floor(Math.sqrt(recLimit)),
pageWidth = myPage.bounds[3] - myPage.bounds[1],
squareSize = Math.floor(pageWidth/boxSide);
var
myLayer = myDocument.layers.item("ColorSwatches"),
step = 0,
c, m, y, k, currentColor;
if(!myLayer.isValid) myLayer = myDocument.layers.add({name:"ColorSwatches"});
for(k = 0; k<=100; k = k+colorValueJumper)
for(y = 0; y<=100; y = y+colorValueJumper)
for(m = 0; m<=100; m = m+colorValueJumper)
for(c = 0; c<=100; c = c+colorValueJumper) {
if (++step == recLimit) exit();
currentColor = myDocument.colors.add({
model: ColorModel.PROCESS,
space: ColorSpace.CMYK,
colorValue: [c,m,y,k],
name: ("00000" + step).slice(-5) + "_CMYK: " + [c,m,y,k].join(" - ")
});
createRec(step, currentColor);
}
function createRec(cnt, cColor) {
var
y0 = cnt%boxSide*squareSize,
x0 = Math.floor(cnt/boxSide)*squareSize,
y1 = (cnt%boxSide + 1)*squareSize,
x1 = (Math.floor(cnt/boxSide) + 1)*squareSize,
mRec = myPage.rectangles.add({
geometricBounds: [y0,x0,y1,x1],
itemLayer: myLayer,
fillColor: cColor
});
}
const
myDocument=app.activeDocument,
myPage=myDocument.pages[0],
recLimit=441,//要创建的矩形计数
colorValueJumper=5,
boxSide=数学地板(数学sqrt(重新限制)),
pageWidth=myPage.bounds[3]-myPage.bounds[1],
squareSize=数学地板(页面宽度/箱侧);
变量
myLayer=myDocument.layers.item(“色样”),
步长=0,
c、 m,y,k,currentColor;
如果(!myLayer.isValid)myLayer=myDocument.layers.add({name:“色样”});
对于(k=0;kI)刚尝试了这一行脚本,它进入了调试模式,在这一行出现了错误。我同意矩形具有这种颜色属性,但我不认为它是这样使用的,从我看到的情况来看,你需要将其称为字符串。你是对的,它需要一个样例。请参阅我的其他答案