Layer To Be Centered
-
- Posts: 2
- Joined: Mon Dec 05, 2016 4:41 pm
Layer To Be Centered
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
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)
- Attachments
-
- Layers of Set Centering.rar
- (638 Bytes) Downloaded 690 times
-
- Posts: 2
- Joined: Mon Dec 05, 2016 4:41 pm
Re: Layer To Be Centered
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)
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)