Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Forums Adobe After Effects Expressions Copy selected property to a Null Layer's Position

  • Copy selected property to a Null Layer's Position

  • Kevin Snyder

    September 6, 2021 at 8:24 pm

    I’m trying to write a script that will copy keyframes from a selected property to the position property of a new null. For example, in the image below I want to select Point1 keyframes from the Lockdown effect and have them copied to a null layer’s position with the name “Point1”.

    I am having a tough time getting the script to paste just the keyframes to the position value of the null instead of pasting the entire Lockdown effect.

    I have disabled the naming part of the script…can’t get it to work.

    app.beginUndoGroup("Copy to Null");
    {
    app.executeCommand(19); //copy
    var controller = app.project.activeItem.layers.addNull(); //Create null
    //myProp = app.project.item[0].layer[0].selectedProperties.name; //Selected property name
    controller.name = "myProp"; //Name null
    controller.enabled = true;
    nullLayer.property("position");
    app.executeCommand(20); //paste
    }
    app.endUndoGroup();

  • Fabrice Leconte

    September 6, 2021 at 11:43 pm

    Hello, maybe something like this:

    app.beginUndoGroup('Copy to Null');

    app.executeCommand(19);

    var controller = app.project.activeItem.layers.addNull();

    controller.name = 'myProp';

    controller.enabled = true;

    controller.property('position').selected = true;

    app.executeCommand(20);

    app.endUndoGroup();

  • Kevin Snyder

    September 7, 2021 at 3:36 am

    Yes! That’s working. Thank you. Is there any way to name the null layer based on the selected property and also have it create a null for each point selected so that there is a null titled “Point1”, “Point2” and so on depending on what’s selected?

  • Fabrice Leconte

    September 7, 2021 at 2:00 pm

    It should work.

    function createNulls() {

    var sLayers = thisComp.selectedLayers;

    if (!sLayers.length) {

    alert('Please, select a layer');

    return false;

    }

    var sProperties = thisComp.selectedLayers[0].selectedProperties;

    if (!sProperties.length || sProperties.length < 2) {

    alert('Please, select at least 1 property');

    return false

    }

    app.beginUndoGroup('Copy to Null');

    for (var i = 0; i < sProperties.length; i++) {

    var sProperty = sProperties[i];

    if (sProperty.numProperties == 2) {

    var myNull = thisComp.layers.addNull();

    myNull.name = sProperty.name;

    myNull.transform.position.expression = 'thisComp.layer("' + sLayers[0].name + '").effect("' + sProperty.name + '")(1)';

    myNull.transform.position.selected = true;

    // OPTIONAL

    // app.executeCommand(2639); // Convert Expression to Keyframes

    // myNull.transform.position.expression = ''; // Remove the Expression

    }

    }

    app.endUndoGroup();

    }

    var thisComp = app.project.activeItem;

    createNulls();

  • Kevin Snyder

    September 7, 2021 at 5:01 pm

    Thank you! I gave it a go but it’s not working. If I select a layer and the position property I get a message stating that I need to select at least one property and when I select the keyframes from the Lockdown plugin nothing happens.

  • Fabrice Leconte

    September 8, 2021 at 3:42 am

    For Lockdown use this code:

    function createNulls() {

    var sLayers = thisComp.selectedLayers;

    if (!sLayers.length) {

    alert('Please, select a layer');

    return false;

    }

    var sProperties = thisComp.selectedLayers[0].selectedProperties;

    if (!sProperties.length || sProperties.length < 2) {

    alert('Please, select at least 1 property');

    return false

    }

    app.beginUndoGroup('Copy to Null');

    for (var i = 0; i < sProperties.length; i++) {

    var sProperty = sProperties[i];

    if (sProperty.name.match(/Point[1-4]/)) {

    var myNull = thisComp.layers.addNull();

    myNull.name = sProperty.name;

    myNull.transform.position.expression = 'thisComp.layer("' + sLayers[0].name + '").effect("Lockdown")("' + sProperty.name + '")';

    // OPTIONAL

    // myNull.transform.position.selected = true;

    // app.executeCommand(2639); // Convert Expression to Keyframes

    // myNull.transform.position.expression = ''; // Remove the Expression

    }

    }

    app.endUndoGroup();

    }

    var thisComp = app.project.activeItem;

    createNulls();

  • Kevin Snyder

    September 8, 2021 at 3:26 pm

    Perfect. Thank you for your help. I really appreciate it.

  • Kevin Snyder

    September 21, 2021 at 4:05 am

    Fabrice Leconte,

    Are you available for hire? I have some ideas for some scripts that I would like to hire you to build if you’re interested.

Viewing 1 - 8 of 8 posts

Log in to reply.

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