Quantcast
Channel: Adobe Community: Message List - Photoshop Scripting
Viewing all articles
Browse latest Browse all 27456

Re: Batch replace smart objects

$
0
0

You’d have to foregoe the replacing and instead open the SO, then place the file.

Something like this – if you have the Preference set to scale placed SOs (»Resize Image During Place«) this might suffice, otherwise you may have to scale the newly placed SO in the SO.

////// open smart object //////

function placeSmartObjectInSmartObject (theLayer, thisFile) {

if (theLayer.kind == "LayerKind.SMARTOBJECT") {

// =======================================================

var idplacedLayerEditContents = stringIDToTypeID( "placedLayerEditContents" );

    var desc2 = new ActionDescriptor();

executeAction( idplacedLayerEditContents, desc2, DialogModes.NO );

// place so;

// =======================================================

var idPlc = charIDToTypeID( "Plc " );

    var desc4 = new ActionDescriptor();

    var idAs = charIDToTypeID( "As  " );

        var desc5 = new ActionDescriptor();

        var idfsel = charIDToTypeID( "fsel" );

        var idpdfSelection = stringIDToTypeID( "pdfSelection" );

        var idpage = stringIDToTypeID( "page" );

        desc5.putEnumerated( idfsel, idpdfSelection, idpage );

        var idPgNm = charIDToTypeID( "PgNm" );

        desc5.putInteger( idPgNm, 1 );

        var idCrop = charIDToTypeID( "Crop" );

        var idcropTo = stringIDToTypeID( "cropTo" );

        var idtrimBox = stringIDToTypeID( "trimBox" );

        desc5.putEnumerated( idCrop, idcropTo, idtrimBox );

    var idPDFG = charIDToTypeID( "PDFG" );

    desc4.putObject( idAs, idPDFG, desc5 );

    var idnull = charIDToTypeID( "null" );

    desc4.putPath( idnull, new File( thisFile ) );

    var idFTcs = charIDToTypeID( "FTcs" );

    var idQCSt = charIDToTypeID( "QCSt" );

    var idQcsa = charIDToTypeID( "Qcsa" );

    desc4.putEnumerated( idFTcs, idQCSt, idQcsa );

    var idOfst = charIDToTypeID( "Ofst" );

        var desc6 = new ActionDescriptor();

        var idHrzn = charIDToTypeID( "Hrzn" );

        var idRlt = charIDToTypeID( "#Rlt" );

        desc6.putUnitDouble( idHrzn, idRlt, 0.000000 );

        var idVrtc = charIDToTypeID( "Vrtc" );

        var idRlt = charIDToTypeID( "#Rlt" );

        desc6.putUnitDouble( idVrtc, idRlt, 0.000000 );

    var idOfst = charIDToTypeID( "Ofst" );

    desc4.putObject( idOfst, idOfst, desc6 );

    var idAntA = charIDToTypeID( "AntA" );

    desc4.putBoolean( idAntA, true );

executeAction( idPlc, desc4, DialogModes.NO );

// toggle visibility of others;

// =======================================================

var idShw = charIDToTypeID( "Shw " );

    var desc10 = new ActionDescriptor();

    var idnull = charIDToTypeID( "null" );

        var list4 = new ActionList();

            var ref7 = new ActionReference();

            var idLyr = charIDToTypeID( "Lyr " );

            var idOrdn = charIDToTypeID( "Ordn" );

            var idTrgt = charIDToTypeID( "Trgt" );

            ref7.putEnumerated( idLyr, idOrdn, idTrgt );

        list4.putReference( ref7 );

    desc10.putList( idnull, list4 );

    var idTglO = charIDToTypeID( "TglO" );

    desc10.putBoolean( idTglO, true );

executeAction( idShw, desc10, DialogModes.NO );

// close;

app.activeDocument.close(SaveOptions.SAVECHANGES)

};

};

edited


Viewing all articles
Browse latest Browse all 27456

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>