ADOBE AFTER EFFECTS: Forum Expressions Tutorials Creative Cloud

Copy Shape Path to Position Property via Scripting

COW Forums : Adobe After Effects Expressions

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
Tomas Bumbulevičius
Copy Shape Path to Position Property via Scripting
on Jan 2, 2020 at 12:51:24 pm

Hello everyone, as the title says - is it possible to copy a path from shape layer and paste it to other layer's position property? (To get rove across time like it does while made manually)

Tried various options to copy and paste it through Extendscript with no luck (selecting the particular shape/copying with app.executeCommand, deselecting, selecting position prop - does nothing, as well as isolating specific props from shape). I guess simply copying the shape doesn't work this way.

Any insights would be much appreciated.

Thanks!

Find out more:
After Effects Tutorials: motion design, expressions, scripting.
Boxer - Dynamic Text Boxes Template with a Live Preview


Return to posts index

Andrei Popa
Re: Copy Shape Path to Position Property via Scripting
on Jan 2, 2020 at 3:11:12 pm

Hi Tomas. Make sure you have nothing selected before running this function.

function copyPathToPosition(pathLayer, positionLayer){

var myPosition = positionLayer("Transform")("Position");
var myPath = pathLayer("Contents")(1)("Contents")(1)("Path");

pathLayer.selected = true;
myPath.selected = true;
app.executeCommand(19); //Copy
pathLayer.selected = false;

positionLayer.selected = true;
myPosition.selected = true;
app.executeCommand(20); //Paste
positionLayer.selected = false;
}




I use a function like this one to make sure nothing is selected:

function deselectEverything(myActiveComp) {
mySelectedItems = myActiveComp.selectedLayers;
for (i = 0; i < mySelectedItems.length; i++){
mySelectedItems[i].selected = false;
}
}


Andrei
My Envato portfolio.


Return to posts index

Tomas Bumbulevičius
Re: Copy Shape Path to Position Property via Scripting
on Jan 2, 2020 at 4:00:35 pm

Hey Andrei, thanks a lot for your insights!

I was doing almost the same thing, except instead of selecting 'layer of position', been directly making selection of position within that layer. While it was the only difference and I was going to celebrate, a bit too early, unfortunately !

The 'shape path' in my setup is under this structure:
var curShape = shapeLayer.property("ADBE Root Vectors Group").property("ADBE Vector Group").property("ADBE Vectors Group").property("ADBE Vector Shape - Group").property("ADBE Vector Shape");

Could this be a case?I tried your direct access without matchnames, and both ways retrieve the same shape object, so I guess it shouldn't be a problem for shape is built and declared. However, nothing happens.

My assumption is that copying doesn't occur, because if I debug after copying is made, there are no actionable 'paste data'. Any ideas why? All layers are deselected, and I am selecting the path as :

shapeLayer.selected = true;
curShape.selected = true;


While debugging, I can see that proper items are selected (the path with stopwatch). But the copying of its data seems to be failing.

Find out more:
After Effects Tutorials: motion design, expressions, scripting.
Boxer - Dynamic Text Boxes Template with a Live Preview


Return to posts index


Andrei Popa
Re: Copy Shape Path to Position Property via Scripting
on Jan 2, 2020 at 4:23:51 pm

I don't know where your error comes from. I used it like this in a fresh project with 2 layers. I even used the same layer(I copied the Path data to the Position of the same layer) and it worked.


function copyPathToPosition(pathLayer, positionLayer){

var myPosition = positionLayer.property("ADBE Transform Group").property("ADBE Position");
var myPath = pathLayer.property("ADBE Root Vectors Group").property("ADBE Vector Group").property("ADBE Vectors Group").property("ADBE Vector Shape - Group").property("ADBE Vector Shape");

pathLayer.selected = true;
myPath.selected = true;
app.executeCommand(19); //Copy
pathLayer.selected = false;

positionLayer.selected = true;
myPosition.selected = true;
app.executeCommand(20); //Paste
positionLayer.selected = false;
}


L1 = app.project.item(1).layer(1);
L2 = app.project.item(1).layer(2);
copyPathToPosition(L1,L2);


I assume it may be something other that you use in your script that does not allow the things to happen. Maybe if you give some more details, i can try to figure out why it's not working.

I have tested it in AE 2017 and AE 2020

Andrei
My Envato portfolio.


Return to posts index

Tomas Bumbulevičius
Re: Copy Shape Path to Position Property via Scripting
on Jan 2, 2020 at 5:05:59 pm

Thanks a lot for your help Andrei! I just narrowed down this up to the point, that it definitely works in a blank project, but it doesn't in my 'shape case'.

If I trigger this script in a dummy project and stop after 'copy' step, data is copied.
If I do the same in my script - it doesn't.

This leads to the point, where copying does not execute, just passes that step without any thrown error either. I can see the only reason myself:
*Not properly built shape path?* I have a shape layer in the comp, which contains plain 'Contents' such as stoke and fill.

var shapeLayer = comp.layer(1);
var pathShape = new Shape();
var pathGroup = shapeLayer.property("Contents").addProperty("ADBE Vector Group");
pathGroup.name = "path";
var myPath = pathGroup.property("Contents").addProperty("ADBE Vector Shape - Group");


Then just applying vertices array built in other step:

pathShape.vertices = verticesArray;
myPath.property("Path").setValue(pathShape)
pathGroup.moveTo(1);


Path builds without any problems, with proper vertices.

If you see a way where to look further, it would be amazing to receive some guideline, as I am hitting head into a wall for a while already!

Find out more:
After Effects Tutorials: motion design, expressions, scripting.
Boxer - Dynamic Text Boxes Template with a Live Preview


Return to posts index

Andrei Popa
Re: Copy Shape Path to Position Property via Scripting
on Jan 2, 2020 at 6:25:15 pm

There is some black magic going here, I'm telling you. It seems to work on my side. Here are details.

So what i did:
Blank project.
I draw a layer as source for the script created path. I name this layer "Source Path". This will be layer 3.
I create a dummy layer that i use for pasting to position property. This will be layer 2.
I run this first to create a new Shape and paste the vertices from the other "Source Path" layer. This is the code you provided except the first line where i create the layer.


var shapeLayer = app.project.activeItem.layers.addShape();
var pathShape = new Shape();
var pathGroup = shapeLayer.property("Contents").addProperty("ADBE Vector Group");
pathGroup.name = "path";
var myPath = pathGroup.property("Contents").addProperty("ADBE Vector Shape - Group");

verticesArray = app.project.item(1).layer("Source Path")("ADBE Root Vectors Group")(1)("ADBE Vectors Group")(1)("ADBE Vector Shape").value.vertices;
pathShape.vertices = verticesArray;
myPath.property("Path").setValue(pathShape)
pathGroup.moveTo(1);


Now we have layer one which is a shape layer created by the script and layer 2 which is the dummy to test the position.

I run this and it works. Turns out you did not need to select the layer before the property. I had this in a larger function and i think i used it for something else.

function copyPathToPosition(pathLayer, positionLayer){

var myPosition = positionLayer.property("ADBE Transform Group").property("ADBE Position");
var myPath = pathLayer.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(19); //Copy
pathLayer.selected = false;


myPosition.selected = true;
app.executeCommand(20); //Paste
positionLayer.selected = false;
}


L1 = app.project.item(1).layer(1);
L2 = app.project.item(1).layer(2);
copyPathToPosition(L1,L2);


Now you need to figure out what in your project is not like in this project.

Some things that complicated my stuff in the past:

Having layers with the same name
Having properties in the same group with the same name
Getting the property variable using matchName without index. I had a problem like this where it got only the first shape in a group with multiple shapes.
A variable of the wrong type. Sometimes I used setValue or the = operator or some sort of methods on 2 variables that were not compatible. Script broke sometimes with no errors shown.

This is pretty much everything i can get with the information you provided.
Good luck on your which hunt :D

Andrei
My Envato portfolio.


Return to posts index


Tomas Bumbulevičius
Re: Copy Shape Path to Position Property via Scripting
on Jan 3, 2020 at 6:43:42 am
Last Edited By Tomas Bumbulevičius on Jan 3, 2020 at 6:54:29 am

Andrei, thanks a lot for your insights!

Yesterday I tried all possible scenarios without any luck. Yet today, first thing in the morning solution literally popped into my hear... The comp is not active in my script !

With that said, not sure how this slipped through, but yourLayersComp.openInViewer() solves this in ease ☺

Thanks for participating, Andrei, there was a bunch of useful pin points to check.

On the other hand, is there a way to control 'time duration' of pasted roving end keyframe, without deleting and creating a new keyframe?

Find out more:
After Effects Tutorials: motion design, expressions, scripting.
Boxer - Dynamic Text Boxes Template with a Live Preview


Return to posts index

<< PREVIOUS   •   VIEW ALL   •   PRINT   •   NEXT >>
© 2020 CreativeCOW.net All Rights Reserved
[TOP]