简体   繁体   中英

How to use JavaScript move layer in Photoshop using the relative coordinates

I'm just starting to work with JS to Photoshop. I need to align 2 or more layers between as? for example- on top. Each layer has a mask that is smaller than the image. Using Photoshop menu I can aligns only images, without their masks.I want to align images on their masks - visible through the mask to the image on the same level. Thanks !

mmIf you want to transform layers (or layer masks) use these three functions. You didn't mention what version of PS you are using.

  • selectmask - selects the layer mask in the layer as active
  • linkUnlinkLayermask - will link or unlink the layer mask to it's layer
  • transformLayerLayer - offset layer (or layermask) by a number of pixels

You should be able to manipulate the layers and align them as you need them.

//pref pixels
app.preferences.rulerUnits = Units.PIXELS;

var deltaX = 0
var deltaY = 20

selectMask("Layer 1")
linkUnlinkLayermask(false)
transformLayer(deltaX, deltaY)

function transformLayer(moveX, moveY)
{
    var id442 = charIDToTypeID( "Trnf" );
    var desc93 = new ActionDescriptor();
    var id443 = charIDToTypeID( "null" );
    var ref64 = new ActionReference();
    var id444 = charIDToTypeID( "Lyr " );
    var id445 = charIDToTypeID( "Ordn" );
    var id446 = charIDToTypeID( "Trgt" );
    ref64.putEnumerated( id444, id445, id446 );
    desc93.putReference( id443, ref64 );
    var id447 = charIDToTypeID( "FTcs" );
    var id448 = charIDToTypeID( "QCSt" );
    var id449 = charIDToTypeID( "Qcsa" );
    desc93.putEnumerated( id447, id448, id449 );
    var id450 = charIDToTypeID( "Ofst" );
    var desc94 = new ActionDescriptor();
    var id451 = charIDToTypeID( "Hrzn" );
    var id452 = charIDToTypeID( "#Pxl" );
    desc94.putUnitDouble( id451, id452, deltaX );
    var id453 = charIDToTypeID( "Vrtc" );
    var id454 = charIDToTypeID( "#Pxl" );
    desc94.putUnitDouble( id453, id454, deltaY );
    var id455 = charIDToTypeID( "Ofst" );
    desc93.putObject( id450, id455, desc94 );
    executeAction( id442, desc93, DialogModes.NO );
}

function selectMask(LayerName)
{
    var id2380 = charIDToTypeID( "slct" );
    var desc475 = new ActionDescriptor();
    var id2381 = charIDToTypeID( "null" );
    var ref352 = new ActionReference();
    var id2382 = charIDToTypeID( "Chnl" );
    var id2383 = charIDToTypeID( "Chnl" );
    var id2384 = charIDToTypeID( "Msk " );
    ref352.putEnumerated( id2382, id2383, id2384 );
    var id2385 = charIDToTypeID( "Lyr " );
    ref352.putName( id2385, LayerName );
    desc475.putReference( id2381, ref352 );
    var id2386 = charIDToTypeID( "MkVs" );
    desc475.putBoolean( id2386, false );
    executeAction( id2380, desc475, DialogModes.NO );
}

    function linkUnlinkLayermask(bool)
{
    var id2415 = charIDToTypeID( "setd" );
    var desc483 = new ActionDescriptor();
    var id2416 = charIDToTypeID( "null" );
    var ref359 = new ActionReference();
    var id2417 = charIDToTypeID( "Lyr " );
    var id2418 = charIDToTypeID( "Ordn" );
    var id2419 = charIDToTypeID( "Trgt" );
    ref359.putEnumerated( id2417, id2418, id2419 );
    desc483.putReference( id2416, ref359 );
    var id2420 = charIDToTypeID( "T   " );
    var desc484 = new ActionDescriptor();
    var id2421 = charIDToTypeID( "Usrs" );
    desc484.putBoolean( id2421, bool );
    var id2422 = charIDToTypeID( "Lyr " );
    desc483.putObject( id2420, id2422, desc484 );
    executeAction( id2415, desc483, DialogModes.NO );
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM