Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects fill color setValue

  • fill color setValue

    Posted by Valentin Badoi on February 21, 2020 at 11:28 am

    Hello,
    I have the code below and i need to take the color form colorpicker and set it as fill color for my shape, but i dont figure out how to get the value from colorpicker and put it in <==fillGroup.property(“Color”).setValue(………………………);==>

    // DIALOG
    // ======

    var dialog = new Window(“dialog”);
    dialog.text = “Add Shape”;
    dialog.preferredSize.width = 280;
    dialog.orientation = “column”;
    dialog.alignChildren = [“center”,”top”];
    dialog.spacing = 10;
    dialog.margins = 16;

    // PANEL1
    // ======
    var panel1 = dialog.add(“panel”, undefined, undefined, {name: “panel1”});
    panel1.text = “Add Elispse”;
    panel1.preferredSize.width = 250;
    panel1.orientation = “column”;
    panel1.alignChildren = [“left”,”top”];
    panel1.spacing = 10;
    panel1.margins = 10;

    // GROUP3
    // ======
    var group3 = panel1.add(“group”, undefined, {name: “group3”});
    group3.orientation = “row”;
    group3.alignChildren = [“left”,”center”];
    group3.spacing = 10;
    group3.margins = 0;

    var checkbox1 = group3.add(“checkbox”, undefined, undefined, {name: “checkbox1”});
    checkbox1.text = “Fill”;

    var colorbutton1 = group3.add(‘iconbutton’, undefined, undefined, {name:’coloroption1′, style: ‘toolbutton’});
    colorbutton1.size = [100,20];
    colorbutton1.fillBrush = colorbutton1.graphics.newBrush( colorbutton1.graphics.BrushType.SOLID_COLOR, [0, 0, 0, 1] );
    colorbutton1.textPen = colorbutton1.graphics.newPen (colorbutton1.graphics.PenType.SOLID_COLOR,[1,1,1], 1);
    colorbutton1.onDraw = customDraw;

    // GROUP4
    // ======
    var group4 = dialog.add(“group”, undefined, {name: “group4”});
    group4.orientation = “row”;
    group4.alignChildren = [“left”,”center”];
    group4.spacing = 10;
    group4.margins = 0;

    var button1 = group4.add(“button”, undefined, undefined, {name: “button1”});
    button1.text = “Add”;

    var button2 = group4.add(“button”, undefined, undefined, {name: “button2”});
    button2.text = “Cancel”;

    //FUNCTIONS
    //======

    //ADD ELIPSE BUTTON
    //======
    button1.onClick = function() {
    app.beginUndoGroup(“Process”);
    addElipse();
    app.endUndoGroup();
    }

    //CANCEL BUTTON
    //======
    button2.onClick = function(){
    dialog.close();
    }

    //ADD ELIPSE FUNCTION
    //======
    function addElipse() {
    var project = app.project;
    var comp = project.activeItem;

    if(comp == null) {
    comp = project.items.addComp(“CompCreated”, 1920, 1080, 1, 30, 30);
    }
    comp.openInViewer();

    var shapeLayer = comp.layers.addShape();
    var elipseGroup = shapeLayer.property(“Contents”).addProperty(“ADBE Vector Shape – Ellipse”);
    elipseGroup.property(“Size”).setValue([300,300]);
    if(checkbox1.value == true){
    var fillGroup = shapeLayer.property(“Contents”).addProperty(“ADBE Vector Graphic – Fill”);
    fillGroup.property(“Color”).setValue(………………………); }
    }
    //COLOR PICKER
    //======
    function colorpicker (result_color) {
    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();
    if (color_decimal<0) return null; // added this line, to handle the case where the dialog is dismissed (else: errors)
    var color_hexadecimal = color_decimal.toString(16);
    var color_rgb = hexToRGB(parseInt(color_hexadecimal, 16));
    var result_color = [color_rgb[0] / 255, color_rgb[1] / 255, color_rgb[2] / 255];
    return result_color;
    }

    function customDraw()
    { with( this ) {
    graphics.drawOSControl();
    graphics.rectPath(0,0,size[0],size[1]);
    graphics.fillPath(fillBrush);
    if( text ) graphics.drawString(text,textPen,(size[0]-graphics.measureString (text,graphics.font,size[0])[0])/2,3,graphics.font);
    }}

    function onButtonClick(){

    var newcolor1 = colorpicker ();
    if (newcolor1===null) return; // dialog dismissed
    this.fillBrush = this.graphics.newBrush(this.graphics.BrushType.SOLID_COLOR, newcolor1);
    // no need to call w.update()
    // no need to reassign onDraw for the button, it’s done already
    // call onDraw for the button:
    this.notify(“onDraw”);
    }

    colorbutton1.onClick = onButtonClick;

    //
    //======

    dialog.show();

    Graham Quince replied 6 years, 6 months ago 2 Members · 1 Reply
  • 1 Reply

We use anonymous cookies to give you the best experience we can.
Our Privacy policy | GDPR Policy