Skip to main content
baldengineer
New Participant
May 25, 2015
Answered

Copy a Shape Layer's Path to a Still Layer's Path

  • May 25, 2015
  • 1 reply
  • 1155 views

I'm using Trim Paths on a shape layer to animate the "drawing" of the shape. Then I have a still image (my hand) that I want to track the drawing of the shape layer.

In AE, I do this today by setting the trim paths, then copy the Shape Layer's Path.  I go to the still layer, select the position attribute and paste. This gives is the still layer key frames which match up with the shape's animation.

I was thinking I could loop through something on the shape layer and then create the keyframes on the still layer. However, I'm not sure what makes sense?  Should I use valueAtTime() on the shape layer's path?

Any ideas how I can I replicate this workflow in ExtendScript?

This topic has been closed for replies.
Correct answer Dan Ebberts

Try this--it might get you as far as getting the shape layer path copied into the hand layer's position property:


function deselectAll(theComp){

  for (var i = 1; i <= theComp.numLayers; i++){

    theComp.layer(i).selected = false;

  }

  var theProps = theComp.selectedProperties;

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

    theProps.selected = false;

  }

}

var myComp = app.project.activeItem;

deselectAll(myComp);

var myPath =myComp.layer("Shape Layer 1").property("ADBE Root Vectors Group").property("ADBE Vector Group").property("ADBE Vectors Group").property("ADBE Vector Shape - Group").property("ADBE Vector Shape");

myPath.selected = true;

app.executeCommand(app.findMenuCommandId("Copy"));

deselectAll(myComp);

myProp = myComp.layer("Hand").property("Position");

myProp.selected = true;

app.executeCommand(app.findMenuCommandId("Paste")); 

Dan

1 reply

Dan Ebberts
Dan EbbertsCorrect answer
Community Expert
May 25, 2015

Try this--it might get you as far as getting the shape layer path copied into the hand layer's position property:


function deselectAll(theComp){

  for (var i = 1; i <= theComp.numLayers; i++){

    theComp.layer(i).selected = false;

  }

  var theProps = theComp.selectedProperties;

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

    theProps.selected = false;

  }

}

var myComp = app.project.activeItem;

deselectAll(myComp);

var myPath =myComp.layer("Shape Layer 1").property("ADBE Root Vectors Group").property("ADBE Vector Group").property("ADBE Vectors Group").property("ADBE Vector Shape - Group").property("ADBE Vector Shape");

myPath.selected = true;

app.executeCommand(app.findMenuCommandId("Copy"));

deselectAll(myComp);

myProp = myComp.layer("Hand").property("Position");

myProp.selected = true;

app.executeCommand(app.findMenuCommandId("Paste")); 

Dan

Mathias Moehl
Community Expert
May 25, 2015

Dan's solution is pretty clever since you don't need to handle the details of all keyframes explicitly.

But note that

app.findMenuCommandId("Copy")

will only work for the English version of AE.

To make it universal, you need to know how the "Copy" menu command is named in any other language you want to support.

Mathias Möhl - Developer of tools like BeatEdit and Automation Blocks for Premiere Pro and After Effects
Dan Ebberts
Community Expert
May 25, 2015

That's a good point. You could try using the numeric values, so instead of:

app.executeCommand(app.findMenuCommandId("Copy"));

you would use:

app.executeCommand(19);

and instead of:

app.executeCommand(app.findMenuCommandId("Paste"));

you would use:

app.executeCommand(20);

Dan