Created
February 15, 2011 18:43
-
-
Save k2052/827981 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# For documentation see move_layer_to_group() | |
def move_layer_to_group(layer_name, group) | |
doc = @app.current_document | |
dest = find_layer_set(doc.layer_sets.to_a, group) | |
src = find_layer(doc.art_layers.to_a, doc.layer_sets.to_a, layer_name) | |
if src[:depth] > 0 | |
src[:depth] = src[:depth] - 1 | |
end | |
if dest[:depth] > 0 | |
dest[:depth] = dest[:depth] - 1 | |
end | |
move_js = <<-eos | |
#include '/Developer/xtools/xlib/stdlib.js' | |
var docRef = app.activeDocument; | |
var doc = app.activeDocument; | |
var layer_sets = doc.layerSets; | |
// src | |
var src; | |
var src_path = "#{src[:path].join(',')}"; | |
src_path = src_path.split(','); | |
var src_depth = #{src[:depth]}; | |
// dest | |
var dest; | |
var dest_path = "#{dest[:path].join(',')}"; | |
dest_path = dest_path.split(','); | |
var dest_depth = #{dest[:depth]}; | |
dest_loop_layer_sets = function(layer_set, depth) | |
{ | |
if(depth == undefined) { | |
depth = 1; | |
} | |
if(depth == (dest_path.length - 1)) { | |
dest = layer_set.layerSets.getByName(dest_path[depth]); | |
} | |
else | |
{ | |
layer_set = layer_set.layerSets.getByName(dest_path[depth]); | |
dest_loop_layer_sets(layer_set, depth++); | |
} | |
} | |
dest_loop_layer_sets(layer_sets.getByName(dest_path[0])); | |
if(src_depth == 0 ) { | |
src = doc.artLayers.getByName("#{layer_name}"); | |
} else { | |
src_loop_layer_sets(layer_sets); | |
} | |
src_loop_layers = function(layer_sets, depth) | |
{ | |
if(depth == undefined) { | |
depth = 0; | |
} | |
layer_set = layer_sets.getByName(src_path[depth]); | |
if((depth + 1) == src_path.length) { | |
src = layer_set.artLayers.getByName("#{layer_name}"); | |
} | |
else | |
{ | |
layer_sets = layer_set.layerSets; | |
src_loop_layers(layer_sets, depth++); | |
} | |
} | |
// move layer/layerset function | |
moveLayer = function(layer, toLayer) { | |
var toLayerIndex = Stdlib.getLayerIndex(docRef,toLayer) | |
var desc = new ActionDescriptor(); | |
var ref = new ActionReference(); | |
ref.putName( cTID('Lyr '), layer.name ); | |
desc.putReference( cTID('null'), ref ); | |
var ref1 = new ActionReference(); | |
ref1.putIndex( cTID('Lyr '), toLayerIndex ); | |
desc.putReference( cTID('T '), ref1 ); | |
desc.putBoolean( cTID('Adjs'), false ); | |
executeAction( cTID('move'), desc, DialogModes.NO ); | |
}; | |
// create background layer -stdlib.js bug fix | |
// var layerRefBackground = docRef.artLayers.add(); | |
// docRef.activeLayer.name = "BG"; | |
// docRef.activeLayer.isBackgroundLayer = true; | |
// move layer set "Pixel" | |
moveLayer(src, dest); | |
eos | |
puts move_js | |
retvalue = do_javascript(move_js) | |
return retvalue | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment