Copy link to clipboard
Copied
With following script we can flip all layers one by one:
//Script to flip all layers horizontally
//Just collect all layers in an array and then flip each one by looping
//if background layer is present it has to be transformed into a normal layer, then flipped, and then turned back into a
//Not really recomended for multiple frame animations.
//get the document
doc = app.activeDocument;
//get the array with all the layers
allLayers = [];
allLayers = collectAllLayers(doc, allLayers);
//loop and flip
for (var i = 0; i < allLayers.length; i++) {
//flip all layers that aren't backgorund
if (allLayers[i].isBackgroundLayer == false) {
var vis = allLayers[i].visible; //save whether the layer was visible or not
allLayers[i].visible = true; //set to visible so the layer is editable
allLayers[i].resize(-100, undefined, AnchorPosition.MIDDLECENTER); //flip the layer
allLayers[i].visible = vis; //set the visibility back to what it was before editing
}
else {
//flip the backgorund layer (if existant)
allLayers[i].visible = true; //set to visible so the layer is editable
allLayers[i].isBackgroundLayer = false; //transform background layer into normal layer
allLayers[i].resize(-100, undefined, AnchorPosition.MIDDLECENTER); //flip it
allLayers[i].isBackgroundLayer = true; //turn back into backgorund layer
allLayers[i].visible = vis; //set the visibility back to what it was before editing
}
}
function collectAllLayers (doc, allLayers){
//returns array containing all posible layers.
for (var m = 0; m < doc.layers.length; m++){
var theLayer = doc.layers[m];
if (theLayer.typename === "ArtLayer"){
allLayers.push(theLayer);
}else{
collectAllLayers(theLayer, allLayers);
}
}
return allLayers;
}
Now if i want to flip only selected layers one by one, what changes i must apply to above script?
Please do not revise your posts in this way in future.
[ This thread is now closed by moderator. ]
The following script can be used as a framework to process only selected layers:
Here it is modified for only the selected layers:
#target photoshop
/* Start Process selected layers - from jazz-y */
var s2t = stringIDToTypeID;
(r = new ActionReference()).putProperty(s2t('property'), p = s2t('targetLayersIDs'));
r.putEnumerated(s2t('document'), s2t('ordin
...
Copy link to clipboard
Copied
Nobody known? maybe this is my last request in this forum. this is very important.
Copy link to clipboard
Copied
@c.pfaffenbichler @Stephen_A_Marsh @Chuck Uebele
If have any idea to modify that script plz provide here.
Copy link to clipboard
Copied
… Sometimes i have selection like following that i must flip from top to down one by one …
… But the above code has the following two problems:
it flip all layers (i want to flip only selected areas).If the selected areas are not divided into dedicated layers, the above script will only flip the main layer …By @abolfazl29032603daba
Sorry.
Unfortunately, you are subject to a fundamental error.
It is not the script that has the two problems. You are trying to use a script that was not written for the purpose you intended.
You are trying to mirror multiple non-transparent parts of a single layer that have been bounded by a selection. But that's not the problem either. In addition, you still want to align the individual non-transparent parts within the same selection (each separately) to the right.
This can only work if you distribute the individual parts on separate layers and then go through the layers in a loop and mirror them and align them to the right.
No longer applicable, as the original post has been completely revised several times and the question is now a completely different one.
[ edited by pixxxelschubser ]
Copy link to clipboard
Copied
my script flip all layers, if i want to flip only selected layers then what changes i must apply to my script to do it?
Copy link to clipboard
Copied
The following script can be used as a framework to process only selected layers:
Here it is modified for only the selected layers:
#target photoshop
/* Start Process selected layers - from jazz-y */
var s2t = stringIDToTypeID;
(r = new ActionReference()).putProperty(s2t('property'), p = s2t('targetLayersIDs'));
r.putEnumerated(s2t('document'), s2t('ordinal'), s2t('targetEnum'));
var lrs = executeActionGet(r).getList(p),
sel = new ActionReference();
for (var i = 0; i < lrs.count; i++) {
sel.putIdentifier(s2t('layer'), p = lrs.getReference(i).getIdentifier(s2t('layerID')));
(r = new ActionReference()).putIdentifier(s2t('layer'), p);
(d = new ActionDescriptor()).putReference(s2t("target"), r);
executeAction(s2t('select'), d, DialogModes.NO);
/* End Process selected layers - from jazz-y */
// Your code here:
if (activeDocument.activeLayer.isBackgroundLayer == false) {
var vis = activeDocument.activeLayer.visible; //save whether the layer was visible or not
activeDocument.activeLayer.visible = true; //set to visible so the layer is editable
activeDocument.activeLayer.resize(-100, undefined, AnchorPosition.MIDDLECENTER); //flip the layer
activeDocument.activeLayer.visible = vis; //set the visibility back to what it was before editing
}
else {
activeDocument.activeLayer.visible = true; //set to visible so the layer is editable
activeDocument.activeLayer.isBackgroundLayer = false; //transform background layer into normal layer
activeDocument.activeLayer.resize(-100, undefined, AnchorPosition.MIDDLECENTER); //flip it
activeDocument.activeLayer.isBackgroundLayer = true; //turn back into backgorund layer
}
}
Copy link to clipboard
Copied
@Stephen_A_Marsh wrote:The following script can be used as a framework to process only selected layers:
Here it is modified for only the selected layers:
#target photoshop
/* Start Process selected layers - from jazz-y */
var s2t = stringIDToTypeID;
(r = new ActionReference()).putProperty(s2t('property'), p = s2t('targetLayersIDs'));
r.putEnumerated(s2t('document'), s2t('ordinal'), s2t('targetEnum'));
var lrs = executeActionGet(r).getList(p),
sel = new ActionReference();
for (var i = 0; i < lrs.count; i++) {
sel.putIdentifier(s2t('layer'), p = lrs.getReference(i).getIdentifier(s2t('layerID')));
(r = new ActionReference()).putIdentifier(s2t('layer'), p);
(d = new ActionDescriptor()).putReference(s2t("target"), r);
executeAction(s2t('select'), d, DialogModes.NO);
/* End Process selected layers - from jazz-y */
// Your code here:
if (activeDocument.activeLayer.isBackgroundLayer == false) {
var vis = activeDocument.activeLayer.visible; //save whether the layer was visible or not
activeDocument.activeLayer.visible = true; //set to visible so the layer is editable
activeDocument.activeLayer.resize(-100, undefined, AnchorPosition.MIDDLECENTER); //flip the layer
activeDocument.activeLayer.visible = vis; //set the visibility back to what it was before editing
}
else {
activeDocument.activeLayer.visible = true; //set to visible so the layer is editable
activeDocument.activeLayer.isBackgroundLayer = false; //transform background layer into normal layer
activeDocument.activeLayer.resize(-100, undefined, AnchorPosition.MIDDLECENTER); //flip it
activeDocument.activeLayer.isBackgroundLayer = true; //turn back into backgorund layer
}
}
can you tell me why you not added following to your code?
//Script to flip all layers horizontally
//Just collect all layers in an array and then flip each one by looping
//if background layer is present it has to be transformed into a normal layer, then flipped, and then turned back into a
//Not really recomended for multiple frame animations.
//get the document
doc = app.activeDocument;
//get the array with all the layers
allLayers = [];
allLayers = collectAllLayers(doc, allLayers);
//loop and flip
for (var i = 0; i < allLayers.length; i++) {
//flip all layers that aren't backgorund
and
function collectAllLayers (doc, allLayers){
//returns array containing all posible layers.
for (var m = 0; m < doc.layers.length; m++){
var theLayer = doc.layers[m];
if (theLayer.typename === "ArtLayer"){
allLayers.push(theLayer);
}else{
collectAllLayers(theLayer, allLayers);
}
}
return allLayers;
}
Copy link to clipboard
Copied
can you tell me why you not added following to your code?
//Script to flip all layers horizontally //Just collect all layers in an array and then flip each one by looping //if background layer is present it has to be transformed into a normal layer, then flipped, and then turned back into a //Not really recomended for multiple frame animations. //get the document doc = app.activeDocument; //get the array with all the layers allLayers = []; allLayers = collectAllLayers(doc, allLayers); //loop and flip for (var i = 0; i < allLayers.length; i++) { //flip all layers that aren't backgorund
and
function collectAllLayers (doc, allLayers){ //returns array containing all posible layers. for (var m = 0; m < doc.layers.length; m++){ var theLayer = doc.layers[m]; if (theLayer.typename === "ArtLayer"){ allLayers.push(theLayer); }else{ collectAllLayers(theLayer, allLayers); } } return allLayers; }
By @abolfazl29032603daba
Does the code work as expected?
I only copied and modified the code that I believed was applicable to work on selected layers.
Copy link to clipboard
Copied
Does the code work as expected?
I only copied the code that I believed was applicable to work on selected layers.
By @Stephen_A_Marsh
yes it worked :))
Copy link to clipboard
Copied
Does the code work as expected?
I only copied the code that I believed was applicable to work on selected layers.
By @Stephen_A_Marshyes it worked :))
By @abolfazl29032603daba
Then all is good! :]
Copy link to clipboard
Copied
thanks for the correct solution.
subsequent editing of posts is a useful function to remove spelling mistakes or make necessary additions. However, if, as in this case, the opening post is changed so that the question afterwards is a completely different one, answers already given become pointless at best. Or at worst, even inappropriate.
I am glad that a solution has been found for you.
Please do not revise your posts in this way in future.
[ This thread is now closed by moderator. ]
--------------------------------------------------------------------------------------------------------------------------------------------------
Here is the original post with the original pictures inserted.
Sometimes i have selection like following that i must flip from top to down one by one:
now i want to flip only selected areas without separate layers like following:
please note that i don't want to separate selected area to multiple layers. If this is not possible without separate selection, please provide code with separate selection to multiple layers.
Preference is given to without separate selection.
I have following script to flip all layers:
//Script to flip all layers horizontally //Just collect all layers in an array and then flip each one by looping //if background layer is present it has to be transformed into a normal layer, then flipped, and then turned back into a //Not really recomended for multiple frame animations. //get the document doc = app.activeDocument; //get the array with all the layers allLayers = []; allLayers = collectAllLayers(doc, allLayers); //loop and flip for (var i = 0; i < allLayers.length; i++) { //flip all layers that aren't backgorund if (allLayers[i].isBackgroundLayer == false) { var vis = allLayers[i].visible; //save whether the layer was visible or not allLayers[i].visible = true; //set to visible so the layer is editable allLayers[i].resize(-100, undefined, AnchorPosition.MIDDLECENTER); //flip the layer allLayers[i].visible = vis; //set the visibility back to what it was before editing } else { //flip the backgorund layer (if existant) allLayers[i].visible = true; //set to visible so the layer is editable allLayers[i].isBackgroundLayer = false; //transform background layer into normal layer allLayers[i].resize(-100, undefined, AnchorPosition.MIDDLECENTER); //flip it allLayers[i].isBackgroundLayer = true; //turn back into backgorund layer allLayers[i].visible = vis; //set the visibility back to what it was before editing } } function collectAllLayers (doc, allLayers){ //returns array containing all posible layers. for (var m = 0; m < doc.layers.length; m++){ var theLayer = doc.layers[m]; if (theLayer.typename === "ArtLayer"){ allLayers.push(theLayer); }else{ collectAllLayers(theLayer, allLayers); } } return allLayers; }
But the above code has the following two problems:
- it flip all layers (i want to flip only selected areas).
- If the selected areas are not divided into dedicated layers, the above script will only flip the main layer.
If it possible help to solve following two problems.
PNG sample for test attached to post.
THEMENAktionen und Skripte--2023-0001.pngVorschau
By @abolfazl29032603daba