Forum Replies Created

Page 1 of 32
  • Xavier Gomez

    October 18, 2017 at 9:31 pm in reply to: get an property address dynamically

    You can use eval.
    myPath being the string stored in the file:

    var myProperty;
    try{myProperty = eval(myPath);}
    catch(e){alert(e);};

    Xavier

  • Xavier Gomez

    October 15, 2017 at 10:17 pm in reply to: how to create a color picker with extendscript

    try replace you colorpicker() function with this one:

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

    and the onClick callbacks for buttons by this:

    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;
    colorbutton2.onClick = onButtonClick;

    It should work, but beware, there are a few bugs with ScriptUI and onDraw now (in CC2014 and later i think).

    Xavier.

  • The After Effects scripting guide has a very loosy description of app.project.activeItem.
    If you follow it, you might think it is only determined by the panel selection, but it’s not.

    It seems to be determined in this order:

    if the Project Panel is active, then it is the unique selected item in that Panel, or null.
    if the Project Panel is not active, then it is the front comp in the Timeline Panel if any, or null again.

    (paradoxally, viewers dont play a role, you can have all viewers closed and no project selection, and still have a comp “active”: the one in front in the timeline panel).

    So you can do this:

    var X = app.project.activeItem;
    if (X instanceof CompItem && !X.selected){
    // X is the comp in front in the timeline
    }
    else{
    // stuck
    };

    If you have CS6 or later, you can do this prior to querying activeItem:

    if (app.activeViewer!=null && (app.activeViewer.type==ViewerType.VIEWER_COMPOSITION)){
    app.activeViewer.setActive();
    // at this stage, app.project.activeItem is necessarily the front comp in the timeline panel
    var comp = app.project.activeItem;
    var layers = comp.selectedLayers;
    }
    else{
    // ask to activate a comp
    };

    Xavier

  • Xavier Gomez

    August 27, 2017 at 11:46 am in reply to: Would love some input

    Here is an attempt to make it more compact. Not sure it actually brings something though.
    Your expression is more readable.

    Xavier

    Px=transform.scale[0].value > 0; // Px true <==> positive xScale
    Py=transform.scale[1].value > 0; // Py true <==> positive yScale
    Rot=transform.rotation.value % 360; if (Rot<0) rot += 360;
    cPos=transform.position.value;
    i=0;
    j=0;
    if (Rot%90 === 0){
    A = Rot%180 === 0; // true for 0 and 180, false for 90 or 270
    // result for 0 and 90 :
    if ( (Px===Py) ? (Px ? !A : A) : (!Px) ) i=1;
    if ( A ? !Py : !Px) j=1;
    // 180 or 270 : invert
    if (Rot===180 || Rot===270){ i=1-i; j=1-j;};
    };
    // result
    cPos + [14*i, 14*j];

  • Xavier Gomez

    August 11, 2017 at 5:41 pm in reply to: app.executeCommand() for 100% Zoom

    You can do it without a menu command, using the viewer object:

    if (app.activeViewer) app.activeViewer.views[0].options.zoom = 1.0;

    (it can’t be used to “Fit up to 100%” though, only absolute values).

    Xavier

  • Xavier Gomez

    August 6, 2017 at 1:15 pm in reply to: Scripting: Retrieving Label Color from Preferences

    The code failed to be written correctly, and i can’t edit, so once again:

    function prefCodeToHexCode(str){
    return str.replace(/"([^"]+)"/g, function(u, code){
    var result = "";
    for (var i=0; i

  • Xavier Gomez

    August 6, 2017 at 1:12 pm in reply to: Scripting: Retrieving Label Color from Preferences

    Sorry, i didnt check the thread much after writing to it.
    getPrefAslong doesnt work and, as you already said, getPrefAsString produces a string that is hardly usable.

    It seems that one can recover the actual hex color code from the string as written in the prefs file by converting everything that is in between quotes like this:

    function prefCodeToHexCode(str){
    return str.replace(/”([^”]+)”/g, function(u, code){
    var result = “”;
    for (var i=0; i

  • You could try getPrefAsLong(), which should produce a number.
    Most probably an integer in the range 0 – (255*255*255-1).
    Then you should convert that number to an array [R, G, B], all entries in the range 0-255, then divide all entries by 255 to get an array [r, g, b], entries in the range [0,1], which is what After Effects uses.
    I havent tried, but worth trying.

    Xavier.

  • Xavier Gomez

    June 9, 2017 at 6:55 pm in reply to: In theory, how many times will this code run

    What is sure is that the string is build at least once for the text layer, and is evaluated three different times, once per shape layer.
    Now, is the string rebuilt everytime it is required by one of the shape layers, that’s a question i always wondered about. I would say no, but that’s just a guess. Only an Adobe engineer could answer i think. Or maybe Dan!

    Xavier

  • Xavier Gomez

    May 30, 2017 at 12:59 pm in reply to: app.executeCommand Question

    You’ll probably have to store the layer selection, deselect all layers except the one you want, use the command, and eventually reselect.

    Xavier

Page 1 of 32

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