Move a Group into a Group with Layerindex
Hello dear community,
Unfortunately I'm stuck at the moment and need your help.
I have a script in which I have a layer and save the layer index of this layer and whether this is possibly in a group:
var originalLayer = app.activeDocument.activeLayer;
function findLayerIndex(layer, parentGroup, parentName) {
for (var i = 0; i < parentGroup.length; i++) {
if (parentGroup[i] === layer) {
return { index: i, group: parentName };
}
if (parentGroup[i].typename === "LayerSet") {
var result = findLayerIndex(layer, parentGroup[i].layers, parentGroup[i].name);
if (result) return result;
}
}
return null;
}
// Get Doc & Layer
var doc = app.activeDocument;
var layers = doc.layers;
var originalLayer = doc.activeLayer; // Active layer
var result = findLayerIndex(originalLayer, layers, "Root");
if (result) {
var layerIndex = result.index;
var parentGroup = result.group;
// alert("Layer-Index: " + layerIndex);
// alert("Gruppe gespeichert: " + parentGroup);
} else {
alert("no Layer found");
}Then I just do some copys of them and put them in a new group, this is then created at the top of all levels. Then I want to move this group to the original position. if the level was not within a group, everything works correctly. I just can't get it to move the new group back into the old group and the correct position. do you have any ideas?
if (parentGroup !== "Root") {
alert("here i need the code to move my Group in the saved Group and index position ")
}else{
// Move Group to Root index
doc.activeLayer = group;
//alert("Group Selected")
while (doc.activeLayer != layers[layerIndex]) {
doc.activeLayer.move(layers[layerIndex], ElementPlacement.PLACEAFTER);};
};Thank you for your help 🙏
