0

我刚开始用 javascript 编写脚本,我的知识非常少。

我有几行代码在其中创建了一个实体,但是我想要一个 GUI 颜色选择器来提示,以便用户可以选择颜色。下面是一个例子:

var myComp = app.project.item(1); //points to my comp

var mySolid = myComp.layers.addSolid([10,10,10],"Shape", 10, 10, 1.0); // creates a 10 pixel shape

addSolid 的第一个参数之一是我们输入以 RGB 值标识的数组值的颜色。我想知道我是否可以使用附加到颜色选择器 GUI 的变量来覆盖这个值?extendscript 实用程序中是否有任何对象或方法可以轻松创建颜色选择器?就是想。

我希望我的问题很清楚。谢谢

4

1 回答 1

3

查看http://yearbookmachine.github.io/esdocs/#/Javascript/$/colorPicker

colorPicker(Number color)
调用特定于平台的颜色选择对话框,并返回选定的颜色。
参数 数字 颜色 对话框中预选的颜色,如 0xRRGGBB,或 -1 为平台默认值。

var color = $.colorPicker();
alert(color);

编辑1:

AE 主要使用 4 值数组中的颜色,其值从 0 到 1 [r, g, b, a] 但实体不能具有 alpha 值。

Edit2(使其完整和可用):

// check out [http://yearbookmachine.github.io/esdocs/#/Javascript/$/colorPicker](http://yearbookmachine.github.io/esdocs/#/Javascript/$/colorPicker)

// colorPicker(Number color)  
// Invokes the platform-specific color selection dialog, and returns the selected color.  
// Parameters Number color The color to be preselected in the dialog, as 0xRRGGBB, or -1 for the platform default.  

// convert a hexidecimal color string to 0..255 R,G,B
// found here https://gist.github.com/lrvick/2080648
var hexToRGB = function(hex) {
  var r = hex >> 16;
  var g = hex >> 8 & 0xFF;
  var b = hex & 0xFF;
  return [r, g, b];
};

var color_decimal = $.colorPicker();
$.writeln(color_decimal);

var color_hexadecimal = color_decimal.toString(16);
$.writeln(color_hexadecimal);

var color_rgb = hexToRGB(parseInt(color_hexadecimal, 16));
$.writeln(color_rgb);

var color_that_ae_add_solid_understands = [color_rgb[0] / 255, color_rgb[1] / 255, color_rgb[2] / 255];
$.writeln(color_that_ae_add_solid_understands);

// also check out the AE scripting guide on addSolid and its parameters
// https://blogs.adobe.com/aftereffects/files/2012/06/After-Effects-CS6-Scripting-Guide.pdf?file=2012/06/After-Effects-CS6-Scripting-Guide.pdf

var comp = app.project.items.addComp(name = "new comp",
  width = 100,
  height = 100,
  pixelAspect = 1,
  duration = 1,
  frameRate = 25);

var solid = comp.layers.addSolid(color_that_ae_add_solid_understands,
  name = "solid",
  width = 10,
  height = 10,
  pixelAspect = 1,
  duration = 1);
于 2014-09-10T19:54:27.423 回答