Photoshop Python - Layer managment


I have a function that runs and works for me however I would love to be able to read it a bit easier and edit bit more…

Could any1 have a look at this messy code and suggest/rewrite how to tackle this problem ?

def moveLayerSet(fromLayer, toLayer ):
    DialogModes =3
    desc = ct.CreateObject( "Photoshop.ActionDescriptor" )
    sourceRef = ct.CreateObject( "Photoshop.ActionReference") 
    sourceRef.putName( ps.charIDToTypeID( "Lyr " ), fromLayer );
    desc.putReference( ps.charIDToTypeID( "null" ), sourceRef );
    indexRef = ct.CreateObject( "Photoshop.ActionReference" )
    indexRef.putName( ps.charIDToTypeID("Lyr "), toLayer );
    layerIndex = ps.executeActionGet(indexRef).getInteger(ps.stringIDToTypeID('itemIndex'));
    destinationRef = ct.CreateObject( "Photoshop.ActionReference" )
    destinationRef.putIndex( ps.charIDToTypeID( "Lyr " ), layerIndex-1 );
    desc.putReference( ps.charIDToTypeID( "T   " ), destinationRef );  
    desc.putBoolean( ps.charIDToTypeID( "Adjs" ), False );
    desc.putInteger( ps.charIDToTypeID( "Vrsn" ), 5 );
    ps.executeAction( ps.charIDToTypeID( "move" ), desc, DialogModes );

In basics it simply move artLayers from group to group. But in this case it finds the group anywhere in photoshop as opposed to having to track it down like steps.

For example here :

sets = doc.layerSets
for layers in sets:
    for lay in layers.layerSets:
        for art in lay.artLayers:
            n =
            s = "IBL"
            if s in str(n):
               art.Visible = False

This is what I mean - I have to go up each group set to find the file I want. It cant just find it by name has to be layered… Not the best way to work.

If any1 could suggest a better work around I would be forever gratefull.



Did you find a solution already? You could implement your own ‘search_layer_by_name’ function on Python and then use it recursively :slight_smile: