在extendcript中创建颜色选择器gui的最佳方法是什么?

时间:2014-09-10 18:38:10

标签: javascript adobe extendscript after-effects

我刚开始用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的变量来超过这个值? extendcript实用程序中是否有任何可以轻松创建颜色选择器的对象或方法?就是想。

我希望我的问题很明确。谢谢

1 个答案:

答案 0 :(得分:3)

结帐http://yearbookmachine.github.io/esdocs/#/Javascript/$/colorPicker

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

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

EDIT1:

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

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);