Copy link to clipboard
Copied
I want to copy the shape layer contents to another shape layer by scripting.
I tried to this by using
Copy link to clipboard
Copied
And what is the rest of the code around it? Of course none of this will do anything without checking whether a layer is correctly selected, what type it is, in which comp it is and so on. If that's all you have, this will never work.
Mylenium
Copy link to clipboard
Copied
function shapeMerge() {
try {
var comp = app.project.activeItem
var selectedLayers = comp.selectedLayers;
var contents = {};
for (var i = 0; i < selectedLayers.length; i++) {
var selectedLayer = selectedLayers[i];
contents[selectedLayer.name] = []
for (var j = 1; j <= selectedLayer.property("ADBE Root Vectors Group").numProperties; j++) {
contents[selectedLayer.name][j] = selectedLayer.property("ADBE Root Vectors Group")(j);
}
}
var newShapeLayer = comp.layers.addShape();
for (var i = 0; i < Object.keys(contents).length; i++) {
var shapeGroup = newShapeLayer.property('ADBE Root Vectors Group').addProperty('ADBE Vector Group')
shapeGroup.name = Object.keys(contents)[i];
for (var j = 1; j < contents[Object.keys(contents)[i]].length; j++) {
deselectAll(comp);
contents[Object.keys(contents)[i]][j].selected = true;
app.executeCommand(19);
deselectAll(comp);
shapeGroup.selected = true;
app.executeCommand(20);
}
}
newShapeLayer.moveBefore(getTopLayer(selectedLayers));
for (var i = 0; i < selectedLayers.length; i++) {
var selectedLayer = selectedLayers[i];
selectedLayer.enabled = false;
}
} catch (e) {
alert(e)
}
}
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[i].selected = false;
}
}
Copy link to clipboard
Copied
Both your functions are in the same loop and will constantly interfere with each other by toggling the selection state. Why not simply create the new layer after the copy and then insert the content i a structured why into the default shape group?
Mylenium
Copy link to clipboard
Copied
it mean this?
for (var i = 0; i < Object.keys(contents).length; i++) {
for (var j = 1; j < contents[Object.keys(contents)[i]].length; j++) {
deselectAll(comp);
contents[Object.keys(contents)[i]][j].selected = true;
app.executeCommand(19);
}
}
var newShapeLayer = comp.layers.addShape();
for (var i = 0; i < Object.keys(contents).length; i++) {
var shapeGroup = newShapeLayer.property('ADBE Root Vectors Group').addProperty('ADBE Vector Group')
shapeGroup.name = Object.keys(contents)[i];
deselectAll(comp);
shapeGroup.selected = true;
app.executeCommand(20);
}
this will paste only last one copied content