Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Forums Adobe Photoshop tweaking the existing script

  • tweaking the existing script

  • Jovan Strel

    July 10, 2014 at 11:04 am

    i have this script, its great and its job is to replace existing smart object with a batch of other photos and incrementally save the variations. It works except everytime i run it, it gives me this message

    “The object “current fill layer” is not currently available”
    and i have to pres ok everytime, the problem is i have to to this for the rest of 9500 photos, im not kidding.

    So please if anyone has a bit of time and some knowledge around scripting in photoshop, please take a look and tell me whats missing in the script or if there is something extra

    the following script is this

    // replace smart object’s content and save psd;
    // 2011, use it at your own risk;
    #target photoshop
    if (app.documents.length > 0) {
    var myDocument = app.activeDocument;
    var theName=*)\.[^\.]+$/)[1];
    var thePath = myDocument.path;
    var theLayer = myDocument.activeLayer;
    // psd options;
    psdOpts = new PhotoshopSaveOptions();
    psdOpts.embedColorProfile = true;
    psdOpts.alphaChannels = true;
    psdOpts.layers = true;
    psdOpts.spotColors = true;
    // check if layer is smart object;
    if (theLayer.kind != “LayerKind.SMARTOBJECT”) {alert (“selected layer is not a smart object”)}
    else {
    // select files;
    if ($ != -1) {var theFiles = File.openDialog (“please select files”, “*.psd;*.tif”, true)}
    else {var theFiles = File.openDialog (“please select files”, getFiles, true)};
    if (theFiles) {
    // work through the array;
    for (var m = 0; m < theFiles.length; m++) {
    // replace smart object;
    theLayer = replaceContents (theFiles[m], theLayer);
    var theNewName = theFiles[m].name.match(/(.*)\.[^\.]+$/)[1];
    //Raise color picker for Back cover;
    try {
    app.activeDocument.activeLayer = app.activeDocument.layers[app.activeDocument.layers.length – 1];
    // =======================================================
    var idsetd = charIDToTypeID( “setd” );
    var desc7 = new ActionDescriptor();
    var idnull = charIDToTypeID( “null” );
    var ref2 = new ActionReference();
    var idcontentLayer = stringIDToTypeID( “contentLayer” );
    var idOrdn = charIDToTypeID( “Ordn” );
    var idTrgt = charIDToTypeID( “Trgt” );
    ref2.putEnumerated( idcontentLayer, idOrdn, idTrgt );
    desc7.putReference( idnull, ref2 );
    var idT = charIDToTypeID( “T ” );
    var desc8 = new ActionDescriptor();
    var idClr = charIDToTypeID( “Clr ” );
    var idsolidColorLayer = stringIDToTypeID( “solidColorLayer” );
    desc7.putObject( idT, idsolidColorLayer, desc8 );
    executeAction( idsetd, desc7, DialogModes.ALL );
    } catch (e) {};
    //save jpg;
    myDocument.saveAs((new File(thePath+”/”+theName+”_”+theNewName+”.psd”)),psdOpts,true);
    ////// get psds, tifs and jpgs from files //////
    function getFiles (theFile) {
    if (\.(psd|tif)$/i) != null || == “Folder”) {
    return true
    ////// replace contents //////
    function replaceContents (newFile, theSO) {
    app.activeDocument.activeLayer = theSO;
    // =======================================================
    var idplacedLayerReplaceContents = stringIDToTypeID( “placedLayerReplaceContents” );
    var desc3 = new ActionDescriptor();
    var idnull = charIDToTypeID( “null” );
    desc3.putPath( idnull, new File( newFile ) );
    var idPgNm = charIDToTypeID( “PgNm” );
    desc3.putInteger( idPgNm, 1 );
    executeAction( idplacedLayerReplaceContents, desc3, DialogModes.NO );
    return app.activeDocument.activeLayer

  • Jonathan Ziegler

    July 11, 2014 at 6:04 pm

    I would step through it one step at a time to find the culprit. I suspect lines 5-8 (line 8 being the most likely). May have to add in some error handling to either prevent the error or to prevent the error from showing. It may be trying to access the current layer which may not be available as a particular data type. I’m completely guessing here – not at my machine right now. 🙁

    What version of Photoshop?
    How are you launching the script?

    Save early. Save often.

    Jonathan Ziegler

  • Jovan Strel

    July 11, 2014 at 7:44 pm

    i have a file with several instanced smart object. On one of these smart objects i have applied warp transform>warp
    all of the layers are unlocked, and some of them are grouped

    i am using this script in Photoshop CS3 because CS6 limits me to .psd only files when activating this script. Cs3 allows .png which is what i need. I have loaded the script into the plugins folder as a jsx

    i am hoping that if there is no apparent solutions to this problem, then maybe there is a some line of code that forces photoshop to force ok, or something like that.

  • Jonathan Ziegler

    July 14, 2014 at 5:19 pm

    The problem is it is requesting a non-existent object (likely mis-named). Unfortunately, without the files to work on, I’m only guessing. Can you just save the files as PSD and open in a later version? Might be a bug with CS3.

    Save early. Save often.

    Jonathan Ziegler

Viewing 1 - 4 of 4 posts

Log in to reply.

We use anonymous cookies to give you the best experience we can. Our Privacy policy | GDPR Policy