Shape Punchout Script

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

mycort

Shape Punchout Script

Post by mycort »

I am trying to create a script using script listener and whhen I select 2 layers, i want to script to do this:
- Put them in a folder
- Select top layer of folder
- Right click blending options and choose blending option "Shallow" for the knockout dropdown
- Then decrease the fill transparency to 0%

I just need help so that I can use this script for any 2 selected shapes, right now the script is tied to a specific psd file and specific layer names. I tried removing these myself but have no luck, get errors.

Here's the script listener code:
Code: Select all// =======================================================
var idOpn = charIDToTypeID( "Opn " );
    var desc1 = new ActionDescriptor();
    var idnull = charIDToTypeID( "null" );
    desc1.putPath( idnull, new File( "/Users/emuyco/Desktop/Untitled-1.psd" ) );
executeAction( idOpn, desc1, DialogModes.NO );

// =======================================================
var idslct = charIDToTypeID( "slct" );
    var desc2 = new ActionDescriptor();
    var idnull = charIDToTypeID( "null" );
        var ref1 = new ActionReference();

    var idselectionModifier = stringIDToTypeID( "selectionModifier" );
    var idselectionModifierType = stringIDToTypeID( "selectionModifierType" );
    var idaddToSelection = stringIDToTypeID( "addToSelection" );
    desc2.putEnumerated( idselectionModifier, idselectionModifierType, idaddToSelection );
    var idMkVs = charIDToTypeID( "MkVs" );
    desc2.putBoolean( idMkVs, false );
executeAction( idslct, desc2, DialogModes.NO );

// =======================================================
var idMk = charIDToTypeID( "Mk  " );
    var desc3 = new ActionDescriptor();
    var idnull = charIDToTypeID( "null" );
        var ref2 = new ActionReference();
        var idlayerSection = stringIDToTypeID( "layerSection" );
        ref2.putClass( idlayerSection );
    desc3.putReference( idnull, ref2 );
    var idFrom = charIDToTypeID( "From" );
        var ref3 = new ActionReference();
        var idLyr = charIDToTypeID( "Lyr " );
        var idOrdn = charIDToTypeID( "Ordn" );
        var idTrgt = charIDToTypeID( "Trgt" );
        ref3.putEnumerated( idLyr, idOrdn, idTrgt );
    desc3.putReference( idFrom, ref3 );
executeAction( idMk, desc3, DialogModes.NO );

// =======================================================
var idslct = charIDToTypeID( "slct" );
    var desc4 = new ActionDescriptor();
    var idnull = charIDToTypeID( "null" );
        var ref4 = new ActionReference();
        var idLyr = charIDToTypeID( "Lyr " );
        ref4.putName( idLyr, "green" );
    desc4.putReference( idnull, ref4 );
    var idMkVs = charIDToTypeID( "MkVs" );
    desc4.putBoolean( idMkVs, false );
executeAction( idslct, desc4, DialogModes.NO );

// =======================================================
var idsetd = charIDToTypeID( "setd" );
    var desc5 = new ActionDescriptor();
    var idnull = charIDToTypeID( "null" );
        var ref5 = new ActionReference();
        var idLyr = charIDToTypeID( "Lyr " );
        var idOrdn = charIDToTypeID( "Ordn" );
        var idTrgt = charIDToTypeID( "Trgt" );
        ref5.putEnumerated( idLyr, idOrdn, idTrgt );
    desc5.putReference( idnull, ref5 );
    var idT = charIDToTypeID( "T   " );
        var desc6 = new ActionDescriptor();
        var idknockout = stringIDToTypeID( "knockout" );
        var idknockout = stringIDToTypeID( "knockout" );
        var idshallow = stringIDToTypeID( "shallow" );
        desc6.putEnumerated( idknockout, idknockout, idshallow );
        var idLefx = charIDToTypeID( "Lefx" );
            var desc7 = new ActionDescriptor();
            var idScl = charIDToTypeID( "Scl " );
            var idPrc = charIDToTypeID( "#Prc" );
            desc7.putUnitDouble( idScl, idPrc, 100.000000 );
        var idLefx = charIDToTypeID( "Lefx" );
        desc6.putObject( idLefx, idLefx, desc7 );
    var idLyr = charIDToTypeID( "Lyr " );
    desc5.putObject( idT, idLyr, desc6 );
executeAction( idsetd, desc5, DialogModes.NO );

// =======================================================
var idsetd = charIDToTypeID( "setd" );
    var desc8 = new ActionDescriptor();
    var idnull = charIDToTypeID( "null" );
        var ref6 = new ActionReference();
        var idLyr = charIDToTypeID( "Lyr " );
        var idOrdn = charIDToTypeID( "Ordn" );
        var idTrgt = charIDToTypeID( "Trgt" );
        ref6.putEnumerated( idLyr, idOrdn, idTrgt );
    desc8.putReference( idnull, ref6 );
    var idT = charIDToTypeID( "T   " );
        var desc9 = new ActionDescriptor();
        var idfillOpacity = stringIDToTypeID( "fillOpacity" );
        var idPrc = charIDToTypeID( "#Prc" );
        desc9.putUnitDouble( idfillOpacity, idPrc, 0.000000 );
    var idLyr = charIDToTypeID( "Lyr " );
    desc8.putObject( idT, idLyr, desc9 );
executeAction( idsetd, desc8, DialogModes.NO );

// =======================================================
var idslct = charIDToTypeID( "slct" );
    var desc10 = new ActionDescriptor();
    var idnull = charIDToTypeID( "null" );
        var ref7 = new ActionReference();
        var idLyr = charIDToTypeID( "Lyr " );
        ref7.putName( idLyr, "Group 1" );
    desc10.putReference( idnull, ref7 );
    var idMkVs = charIDToTypeID( "MkVs" );
    desc10.putBoolean( idMkVs, false );
executeAction( idslct, desc10, DialogModes.NO );

// =======================================================
var idOpn = charIDToTypeID( "Opn " );
    var desc1 = new ActionDescriptor();
    var idnull = charIDToTypeID( "null" );
    desc1.putPath( idnull, new File( "/Users/emuyco/Desktop/Untitled-1.psd" ) );
executeAction( idOpn, desc1, DialogModes.NO );

 

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

pfaffenbichler

Shape Punchout Script

Post by pfaffenbichler »

I think
Code: Select all// =======================================================
var idMk = charIDToTypeID( "Mk  " );
    var desc3 = new ActionDescriptor();
    var idnull = charIDToTypeID( "null" );
        var ref2 = new ActionReference();
        var idlayerSection = stringIDToTypeID( "layerSection" );
        ref2.putClass( idlayerSection );
    desc3.putReference( idnull, ref2 );
    var idFrom = charIDToTypeID( "From" );
        var ref3 = new ActionReference();
        var idLyr = charIDToTypeID( "Lyr " );
        var idOrdn = charIDToTypeID( "Ordn" );
        var idTrgt = charIDToTypeID( "Trgt" );
        ref3.putEnumerated( idLyr, idOrdn, idTrgt );
    desc3.putReference( idFrom, ref3 );
executeAction( idMk, desc3, DialogModes.NO );
should work for any selected Layers, so why the parts before it?

And instead of
Code: Select all// =======================================================
var idslct = charIDToTypeID( "slct" );
    var desc4 = new ActionDescriptor();
    var idnull = charIDToTypeID( "null" );
        var ref4 = new ActionReference();
        var idLyr = charIDToTypeID( "Lyr " );
        ref4.putName( idLyr, "green" );
    desc4.putReference( idnull, ref4 );
    var idMkVs = charIDToTypeID( "MkVs" );
    desc4.putBoolean( idMkVs, false );
I’d just use the DOM code
Code: Select allapp.activeDocument.activeLayer = app.activeDocument.activeLayer.layers[0];
to select the topmost Layer in the Group.
mycort

Shape Punchout Script

Post by mycort »

awesome, was able to use your code and suggestion, works great! thx.