Hi Costin,
here is a jsx script that should do what you need I hope....:)
You can change the pivot position as well or the mirror direction... check the command examples to see how.
/*
UL-------UC--------UR
| |
| |
CL-------CC--------CR
| |
| |
DL-------DC--------DR
direction: 'Horizontal', 'Vertical', 'Both'
command examples:
bcm_mirrorAllCH(getSelectedLayersIdx(),'CC', 'Horizontal' );
bcm_mirrorAllCH(getSelectedLayersIdx(),'UR', 'Both' );
*/
bcm_mirrorAllCH(getSelectedLayersIdx(),'CR', 'Horizontal' );
function bcm_mirrorAllCH( idx, pivotPos, mirrorDirection ){
if( idx.constructor != Array ) idx = [ idx ];
for( var a = 0; a < idx.length; a++ ){
var x = 0;
var y = 0;
var r = 0;
var i = idx[a];
for(i; i > 0 ; i--){
ref = new ActionReference();
ref.putIndex( charIDToTypeID( 'Lyr ' ), i );
var desc = executeActionGet(ref);
var layerName = desc.getString(charIDToTypeID( 'Nm ' ));
var ls = desc.getEnumerationValue(stringIDToTypeID("layerSection"));
ls = typeIDToStringID(ls);
if(ls == "layerSectionStart"){ x++};
if(layerName.match(/^<\/Layer group/) )
{
y ++;
r = x - y;
if(r == 0 && ls == "layerSectionEnd"){break};
continue;
};
if(ls == "layerSectionContent"){mirrorByIndex( i, pivotPos, mirrorDirection )};
};
}
multiSelectByIDx(idx);
}
function mirrorByIndex( idx, pivotPos, mirrorDirection ){
multiSelectByIDx(idx);
/* pivot::
UL-------UC--------UR
| |
| |
CL-------CC--------CR
| |
| |
DL-------DC--------DR
Qst0----Qcs4-----Qcs1
| |
| |
Qcs7----Qcsa-----Qcs5
| |
| |
Qcs3----Qcs6-----Qcs2
*/
var piv = "Qcsa";
switch(pivotPos){
case "UL":
piv = "Qst0";
break;
case "UC":
piv = "Qcs4";
break;
case "UR":
piv = "Qcs1";
break;
case "CL":
piv = "Qcs7";
break;
case "CC":
piv = "Qcsa";
break;
case "CR":
piv = "Qcs5";
break;
case "DL":
piv = "Qcs3";
break;
case "DC":
piv = "Qcs6";
break;
case "DR":
piv = "Qcs2";
break;
}
var dirr = {w:100, h:100};
switch(mirrorDirection){
case "Horizontal":
dirr = {w:-100, h:100};
break;
case "Vertical":
dirr = {w:100, h:-100};
break;
case "Both":
dirr = {w:-100, h:-100};
break;
}
// alert(piv + " :: " + dirr.toSource());
var idTrnf = charIDToTypeID( "Trnf" );
var desc22 = new ActionDescriptor();
var idnull = charIDToTypeID( "null" );
var ref14 = new ActionReference();
ref14.putIndex(charIDToTypeID( "Lyr " ), idx);
desc22.putReference( idnull, ref14 );
var idFTcs = charIDToTypeID( "FTcs" );
var idQCSt = charIDToTypeID( "QCSt" );
var idQcsfive = charIDToTypeID( piv );
desc22.putEnumerated( idFTcs, idQCSt, idQcsfive );
var idOfst = charIDToTypeID( "Ofst" );
var desc23 = new ActionDescriptor();
var idHrzn = charIDToTypeID( "Hrzn" );
var idPxl = charIDToTypeID( "#Pxl" );
desc23.putUnitDouble( idHrzn, idPxl, 0.000000 );
var idVrtc = charIDToTypeID( "Vrtc" );
var idPxl = charIDToTypeID( "#Pxl" );
desc23.putUnitDouble( idVrtc, idPxl, 0.000000 );
var idOfst = charIDToTypeID( "Ofst" );
desc22.putObject( idOfst, idOfst, desc23 );
var idWdth = charIDToTypeID( "Wdth" );
var idPrc = charIDToTypeID( "#Prc" );
desc22.putUnitDouble( idWdth, idPrc, dirr.w );
var idHght = charIDToTypeID( "Hght" );
var idPrc = charIDToTypeID( "#Prc" );
desc22.putUnitDouble( idHght, idPrc, dirr.h );
var idIntr = charIDToTypeID( "Intr" );
var idIntp = charIDToTypeID( "Intp" );
var idBcbc = charIDToTypeID( "Bcbc" );
desc22.putEnumerated( idIntr, idIntp, idBcbc );
executeAction( idTrnf, desc22, DialogModes.NO );
}
function hasBackground(){// function to check if there is a background layer
var res = undefined;
try{
var ref = new ActionReference();
ref.putProperty( charIDToTypeID("Prpr") , charIDToTypeID("Nm "));
ref.putIndex( charIDToTypeID("Lyr "), 0 );
executeActionGet(ref).getString(charIDToTypeID("Nm ") );
res = true;
}catch(e){ res = false}
return res;
}
function getSelectedLayersIdx(){// get the selected layers index( positon in layer editor)
var selectedLayers = new Array;
var ref = new ActionReference();
ref.putEnumerated( charIDToTypeID('Dcmn'), charIDToTypeID('Ordn'), charIDToTypeID('Trgt') );
var desc = executeActionGet(ref);
var add = 1;
if(hasBackground()){add = 0}
if( desc.hasKey( stringIDToTypeID( 'targetLayers' ) ) ){
desc = desc.getList( stringIDToTypeID( 'targetLayers' ));
var c = desc.count
var selectedLayers = new Array();
for(var i=0;i<c;i++){
selectedLayers.push( (desc.getReference( i ).getIndex()) + add);
}
}else{
var ref = new ActionReference();
ref.putProperty( charIDToTypeID('Prpr') , charIDToTypeID( 'ItmI' ));
ref.putEnumerated( charIDToTypeID('Lyr '), charIDToTypeID('Ordn'), charIDToTypeID('Trgt') );
srs = hasBackground()?executeActionGet(ref).getInteger(charIDToTypeID( 'ItmI' ))-1:executeActionGet(ref).getInteger(charIDToTypeID( 'ItmI' ));
selectedLayers.push( srs);
}
return selectedLayers;
}
function multiSelectByIDx(idx) {
if( idx.constructor != Array ) idx = [ idx ];
var layers = new Array();
var id54 = charIDToTypeID( "slct" );
var desc12 = new ActionDescriptor();
var id55 = charIDToTypeID( "null" );
var ref9 = new ActionReference();
for (var i = 0; i < idx.length; i++) {
layers[i] = charIDToTypeID( "Lyr " );
ref9.putIndex(layers[i], idx[i]);
}
desc12.putReference( id55, ref9 );
var id58 = charIDToTypeID( "MkVs" );
desc12.putBoolean( id58, false );
executeAction( id54, desc12, DialogModes.NO );
}