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 😀
Andrei
My Envato portfolio.