-
-
Save hilukasz/03b17ee78414aadff995 to your computer and use it in GitHub Desktop.
var docRef = app.activeDocument; | |
cTID = function(s) { return app.charIDToTypeID(s); }; | |
sTID = function(s) { return app.stringIDToTypeID(s); }; | |
function newGroupFromLayers(doc) { | |
var desc = new ActionDescriptor(); | |
var ref = new ActionReference(); | |
ref.putClass( sTID('layerSection') ); | |
desc.putReference( cTID('null'), ref ); | |
var lref = new ActionReference(); | |
lref.putEnumerated( cTID('Lyr '), cTID('Ordn'), cTID('Trgt') ); | |
desc.putReference( cTID('From'), lref); | |
executeAction( cTID('Mk '), desc, DialogModes.NO ); | |
}; | |
function undo() { | |
executeAction(cTID("undo", undefined, DialogModes.NO)); | |
}; | |
function getSelectedLayers(doc) { | |
var selLayers = []; | |
newGroupFromLayers(); | |
var group = doc.activeLayer; | |
var layers = group.layers; | |
for (var i = 0; i < layers.length; i++) { | |
selLayers.push(layers[i]); | |
} | |
undo(); | |
return selLayers; | |
}; | |
var selectedLayers = getSelectedLayers(app.activeDocument); | |
for( i = 0; i < selectedLayers.length; i++) { | |
selectedLayers[i].selected = true; | |
docRef.activeLayer = selectedLayers[i]; | |
alert(docRef.activeLayer.name) | |
} |
when i do selectedLayers[i].resize it resizes all layers in selection set. cant figure out why it happens. could you help?
got it. we need to select each layer for resize
@myrecs
Well you can change the function to your liking, so for example results ze each one after the other. Depends where you out the resize
When i think about it, it should actually resize each layer one by one. At least if you out the code like you wrote. Since its using [i] per layer. Dont understand why it would resize them all at once. My only guess is that it also resize the artlayergroup at the end. It would need some extra code it guess
One thing, the script's name isnt correct I believe. SInce this groups layers, why not name accordingly. PS why is that undo() in that loop?
My opinion, the main idea of this script is get the child layer, after grouping. He collect the child layer by that group (doc.activeLayer.layers), after collecting, he undo back to ungroup.
@no
I think this resize all items at once and the undoes the grouping.
when i do selectedLayers[i].resize it resizes all layers in selection set. cant figure out why it happens. could you help?