7 Replies Latest reply on Oct 24, 2013 12:07 PM by Chuck Uebele

    Create new layer after active layer

    Ghoulfool Level 1

      Using scriptlistener I can create a new layer called "newlayer" after the active layer. So far so good.

       

       

        var id197 = charIDToTypeID( "Mk  " );
        var desc49 = new ActionDescriptor();
        var id198 = charIDToTypeID( "null" );
        var ref41 = new ActionReference();
        var id199 = charIDToTypeID( "Lyr " );
        ref41.putClass( id199 );
        desc49.putReference( id198, ref41 );
        var id200 = charIDToTypeID( "Usng" );
        var desc50 = new ActionDescriptor();
        var id201 = charIDToTypeID( "Nm  " );
        desc50.putString( id201, "newlayer" );
        var id202 = charIDToTypeID( "Lyr " );
        desc49.putObject( id200, id202, desc50 );
        executeAction( id197, desc49, DialogModes.NO );
      }
      

       

      However, without the script listener we have

       

        var layerRef = app.activeDocument.artLayers.add()
        layerRef.name = newlayername
        layerRef.blendMode = BlendMode.NORMAL
      
        // Move the new layer after the current layer
        layerRef.moveAfter(app.activeDocument.artLayers[layerIndex])
      

       

      The moveAfter command needs an index, which would mean looping though all the layers till to find the active layer (since we can't access that throughthe DOM). This seems a bit long winded to me. Or am I missing a trick here?