Skip to main content
Known Participant
June 9, 2021
Answered

Layer Comps / Layers to Files: Refer to document title when used as an action

  • June 9, 2021
  • 2 replies
  • 1163 views

Hi all,

 

I'm trying to use the Layer Comps to Files or Layers to Files tools as part of an action. I want the final output to be formatted as:

 

[DocumentTitle]_[LayerComp/LayerTitle].jpg

 

At present, the second part of the formatting works fine, but the action records the first part as it is manually entered. Is there any way to amend the .jsx script/s to fix this?

 

Hope this makes sense! Any help would be greatly appreciated 🙂

This topic has been closed for replies.
Correct answer Multifarious

is this what you are looking for?

//some useful settings, edit where appropriate
var destenationFolder = "E:\\LAPS\\TestFiles";      //where to safe the file
var fileName = null;                                  //empty as we're generating these, if you want to specify a single name, do it here
var slctdonly = false;                              //set to true of you only want the selected layercomps exported
 


//list active documents
var documentList = app.documents;

for( var i = 0; i<documentList.length; i++ ){
        app.activeDocument = documentList[i];
        theName = (fileName == null)? app.activeDocument.name.replace('.psd',''):fileName;
        execLC2F( theName, destenationFolder, slctdonly );
}

function execLC2F( theFileName, theDestenationFolder, onlySelected ){
    var LC2F = stringIDToTypeID( "cf34b502-2013-4d07-8431-1dfd634ee0cd" );
        var desc324 = new ActionDescriptor();
        var idMsge = charIDToTypeID( "Msge" );
        desc324.putString( idMsge, """Layer Comps To Files action settings""" );
        var iddestination = stringIDToTypeID( "destination" );
        desc324.putString( iddestination, theDestenationFolder );
        var idfileNamePrefix = stringIDToTypeID( "fileNamePrefix" );
        desc324.putString( idfileNamePrefix, theFileName );
        var idselectionOnly = stringIDToTypeID( "selectionOnly" );
        desc324.putBoolean( idselectionOnly, onlySelected );  //<----

    executeAction( LC2F, desc324, DialogModes.NO );
}

2 replies

Multifarious
Inspiring
June 9, 2021

But maybe this helps:

var theNewFilename = app.activeDocument.name + "_" + app.activeDocument.activeLayer.name;
theNewFilename = theNewFilename.replace('.psd',''); 
alert( theNewFilename );
Multifarious
Inspiring
June 9, 2021

I'm not sure you want to do that with actions, preferably you'd do that with a complete script. 
Are you creating a new doc with that name and save as jpg or do you use the "safe for web"  function?

Known Participant
June 9, 2021

Hi Patrick,

 

Thanks for the reply. 

 

Basically, we have PSDs which come in with different filenames ("FILE_A" today, "FILE_B" tomorrow). A common requirement is to add 6 colour overlays and export as 6 images.

 

At the moment I run a script to add the overlays and create layer comps ("-Black", "-Blue", etc...) then use Layer Comps to Files and manually insert the filename. Fine for small batches but on large batches it can be tedious and imprecise. 

 

It doesn't really matter whether they're saved as JPG or Save for Web. If there's a workaround using SfW we could easily go with that...?

 

Thanks again.

Multifarious
Inspiring
June 9, 2021

getting back to you on this. just so you know - looking into this triggered more then I was expecting 😉