Page 1 of 1

Layer To Be Centered

Posted: Fri Sep 14, 2018 1:52 pm
by Sudarshan2016
Can i get help on this. I have multiple layers in group with different names but layers are not in center of canvas.I want to select the group and center all the layer in it to the canvas.

Re: Layer To Be Centered

Posted: Fri Sep 14, 2018 6:51 pm
by Kukurykus
Select an group with layers you want to center and run script. For more information read a sent to you PM:

Code: Select all

sTT = stringIDToTypeID

nme = (aD = activeDocument).activeLayer.name
runMenuItem(sTT('ungroupLayersEvent'));
(sel = aD.selection).selectAll();

(ref2 = new ActionReference()).putEnumerated
(sTT('layer'), sTT('ordinal'), sTT('targetEnum'));
(dsc = new ActionDescriptor()).putReference(sTT('null'), ref2)

for(i = 0; i < (arr = ['V', 'H']).length;) {
dsc.putEnumerated(sTT('using'), sTT('alignDistributeSelector'),
sTT('ADSCenters' + arr[i++])), executeAction(sTT('align'), dsc)
}

sel.deselect(), (ref1 = new ActionReference()).putClass(sTT('layerSection'))
dsc.putReference(sTT('null'), ref1), dsc.putReference(sTT('from'), ref2);
(dsc2 = new ActionDescriptor()).putString(sTT('name'), nme)
dsc.putObject(sTT('using'), sTT('layerSection'), dsc2)
executeAction(sTT('make'), dsc)

Re: Layer To Be Centered

Posted: Mon Sep 17, 2018 7:40 am
by Sudarshan2016
Thankyou Kukurykus for your help Now i combined centering script with scaling script together and its working fine
I am not good in scripting just mix and try if it work.. this work thankyou again
(function (){
var startRulerUnits = app.preferences.rulerUnits;
app.preferences.rulerUnits = Units.PIXELS;
var bounds = activeDocument.activeLayer.bounds;
var width = bounds[2].value - bounds[0].value;
var height = bounds[3].value - bounds[1].value;
var newWidth = (100 / width) * 3857;
var newHeight = (100 / height) * 3593;
activeDocument.activeLayer.resize(newWidth, newHeight, AnchorPosition.MIDDLECENTER);
app.preferences.rulerUnits = startRulerUnits;
})();


sTT = stringIDToTypeID

nme = (aD = activeDocument).activeLayer.name
runMenuItem(sTT('ungroupLayersEvent'));
(sel = aD.selection).selectAll();

(ref2 = new ActionReference()).putEnumerated
(sTT('layer'), sTT('ordinal'), sTT('targetEnum'));
(dsc = new ActionDescriptor()).putReference(sTT('null'), ref2)

for(i = 0; i < (arr = ['V', 'H']).length;) {
dsc.putEnumerated(sTT('using'), sTT('alignDistributeSelector'),
sTT('ADSCenters' + arr[i++])), executeAction(sTT('align'), dsc)
}

sel.deselect(), (ref1 = new ActionReference()).putClass(sTT('layerSection'))
dsc.putReference(sTT('null'), ref1), dsc.putReference(sTT('from'), ref2);
(dsc2 = new ActionDescriptor()).putString(sTT('name'), nme)
dsc.putObject(sTT('using'), sTT('layerSection'), dsc2)
executeAction(sTT('make'), dsc)