Layer Properties

Anyone, especially newbies, asking for help with Photoshop Scripting and Photoshop Automation - as opposed to those contributing to discussion about an aspect of Photoshop Scripting

Moderators: Tom, Kukurykus

acidelic

Layer Properties

Post by acidelic »

hi. i'm trying to get layer properties like width, height, x, y but i got stuck.

Code: Select allvar doc = activeDocument;
bounds = doc.activeLayer.bounds;
top = bounds[0];
right = bounds[1];
bottom = bounds[2];
left = bounds[3];
alert(left);


but it does NOT give me the subpixel value. i mean if an object has a width like 13,46 px , bounds[0] results as 14 px.

when i transform an object with a subpixel value and then view the script log, i see

Code: Select allvar idTrnf = charIDToTypeID( "Trnf" );
    var desc777 = new ActionDescriptor();
    var idnull = charIDToTypeID( "null" );
        var ref472 = new ActionReference();
        var idPath = charIDToTypeID( "Path" );
        var idOrdn = charIDToTypeID( "Ordn" );
        var idTrgt = charIDToTypeID( "Trgt" );
        ref472.putEnumerated( idPath, idOrdn, idTrgt );
    desc777.putReference( idnull, ref472 );
    var idFTcs = charIDToTypeID( "FTcs" );
    var idQCSt = charIDToTypeID( "QCSt" );
    var idQcszero = charIDToTypeID( "Qcs0" );
    desc777.putEnumerated( idFTcs, idQCSt, idQcszero );
    var idOfst = charIDToTypeID( "Ofst" );
        var desc778 = new ActionDescriptor();
        var idHrzn = charIDToTypeID( "Hrzn" );
        var idPxl = charIDToTypeID( "#Pxl" );
        desc778.putUnitDouble( idHrzn, idPxl, 0.000000 );
        var idVrtc = charIDToTypeID( "Vrtc" );
        var idPxl = charIDToTypeID( "#Pxl" );
        desc778.putUnitDouble( idVrtc, idPxl, 0.000000 );
    var idOfst = charIDToTypeID( "Ofst" );
    desc777.putObject( idOfst, idOfst, desc778 );
    var idWdth = charIDToTypeID( "Wdth" );
    var idPrc = charIDToTypeID( "#Prc" );
    desc777.putUnitDouble( idWdth, idPrc, 98.760000 );
executeAction( idTrnf, desc777, DialogModes.NO );

i tried getUnitDoubleValue but could not make it work.

any help ?

Professional AI Audio Generation within Adobe Premiere Pro - Download Free Plugin here

Mike Hale

Layer Properties

Post by Mike Hale »

Apples and oranges. The scriptlistener code you posted transforms a path. A path point can have sub pixel values. A selection can not. Even a path loaded as a selection only selects whole pixels.
acidelic

Layer Properties

Post by acidelic »

so is there a way to get exact sub-pixel values of any layer (path, etc.) ? or do i have to calculate it from anchorpoints ?
Mike Hale

Layer Properties

Post by Mike Hale »

You have to check the path points. Channels and pixel layers will not have sub pixel values.
acidelic

Layer Properties

Post by acidelic »

i could not find the path specific code in actiondescriptor in the scriptlog, when i free transform a path. am i missing a point here ?
Mike Hale

Layer Properties

Post by Mike Hale »

You can get the pathPoints by either using the DOM. activeDocument.pathItems[0].subPathItems[0].pathPoints[0].anchor etc

Or by getting the descriptor for the path.
Paul MR

Layer Properties

Post by Paul MR »

Just like to mention you have your bounds incorrect.
Code: Select allvar doc = activeDocument;
bounds = doc.activeLayer.bounds;
top = bounds[0];
right = bounds[1];
bottom = bounds[2];
left = bounds[3];
alert(left);

should be...
Code: Select allvar doc = activeDocument;
bounds = doc.activeLayer.bounds;
top = bounds[1];
right = bounds[2];
bottom = bounds[3];
left = bounds[0];
alert(left);