Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity › Forums › Adobe After Effects Expressions › Custom language parse, compiler

  • Custom language parse, compiler

    Posted by Dinesh Salunke on October 19, 2014 at 2:09 pm

    Hello All,

    I have written a small script to automate my and my colleagues usual day to day work, it involves creating keyframes on markers and at specific time.

    I was looking at possibility to include a small expression kind of system where I can write small peice of codes to set the keyframe values based on other factors.

    Below I have explained my requirement with pseudo code of the script.

    function setKeyAt ( property, time, value, expression )
    {
    var keyIndex = property.addKey( time );
    if ( value )
    property.setValueAtKey ( keyIndex, val );

    if ( expression )
    {
    var val = eval( expression );
    property.setValueAtKey ( keyIndex, val );
    }
    }

    var prop = PROPERTY_REFERENCE;
    var nTime = 1;
    var exp = "property.keyValue( keyIndex -2 )";
    setKeyAt( prop, nTime, undefined, exp );

    above code works for me and creates keys at given time, and assings value which is equal to the value at current index – 2.

    I want to extend this and implement a way to incorporate something similar to expressions, so that I can create keys using code

    currently what I have is, I am looking for key words in the expression string and then replace those with values based on the current property,
    EXAMPLE :
    currComp.width
    is replaced by evaluated value of below string

    var layer = property.propertyGroup( property.propertyDepth );
    var comp = layer.containingComp;
    comp.width;

    Hope I was able to explain my problem, and also hope I am not expecting or attempting too much 😉

    Thanks,

    Dinesh Salunke replied 11 years, 11 months ago 2 Members · 2 Replies
  • 2 Replies
  • Dan Ebberts

    October 19, 2014 at 6:11 pm

    I’m not sure this is what you’re talking about, but when I need a script to construct an expression where certain elements are not known at the time the script is written, I use an identifiable string like $PARM1, $PARM2, etc. Then I create a function that will substitute the actual string for a placeholder parm at run time.

    Dan

  • Dinesh Salunke

    October 19, 2014 at 7:02 pm

    Hello Dan,

    I am talking on the similar lines, currently I am also doing pretty much the same way you do, but its really dirty way, and i am still learning the whole coding thing.

    currently, I am using a string.contains to find keywords, then using a switch statement I am calculating and substituting the keyswords with calculated values

    this works but is surely not the best way to do it. also I want to be able to write keywords for functions for example


    /*
    Key Object which represents each keyframe in property
    */
    function Key ( args )
    {

    }

    //This functions takes care of setting the key and assigning the values
    Key.prototype.setAt = function ( property, time )
    {
    var _layer = property.propertyGroup( property.propertyDepth );
    var _comp = _layer.containingComp;

    if ( this.ValueType == undefined || this.ValueType !== property.propertyValueType )
    return 0;
    if ( this.nTimeOffset == undefined )
    return 0;

    var keyIndex = property.addKey ( time + this.nTimeOffset );
    if ( this.nValue !== undefined )
    property.setValueAtKey ( keyIndex, this.nValue );

    if ( this.Expression !== undefined || this.Expression !== "" )
    {
    var val = eval( this.Expression );
    if ( val !== undefined )
    property.setValueAtKey ( keyIndex, val );
    }
    }

    //helper function which can be called from the script to get the value of certain key frame
    function _KeyValueAt ( index )
    {

    }

    Sample Expression :

    "_keyValueAt ( -2 );"

    this expression will be evaluated in the setAt function,

    this works but I want the function to know the 3 variables
    1. property
    2. _layer
    3. _comp

    so that it can use these to calculate the values

    hope I was right to the point this time

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