固定文件夹中的智能对象的Photoshop脚本

时间:2016-05-19 06:15:09

标签: batch-processing photoshop-script

抱歉我的英语不太好,我希望你们能理解我的问题是什么......我不太了解编码。

我有以下代码,允许选择必须在psd文档中的智能对象中更改的文件。我想让代码从固定文件夹中选择 ../Desktop/Alldesigns 没有问我想继续哪些文件。

我希望有人可以帮助我...

#target photoshop
if (app.documents.length > 0) {
var myDocument = app.activeDocument;
var theName= myDocument.name.match(/(.*)\.[^\.]+$/)[1];
var thePath = myDocument.path;
var theLayer = myDocument.activeLayer;
// jpg options;
var jpgopts = new JPEGSaveOptions();
jpgopts.embedProfile = true;
jpgopts.formatOptions = FormatOptions.STANDARDBASELINE;
jpgopts.matte = MatteType.NONE;
jpgopts.quality = 9;
// check if layer is smart object;
if (theLayer.kind != "LayerKind.SMARTOBJECT") {alert ("selected layer is not a smart object")}
else {
// select files;
if ($.os.search(/windows/i) != -1) {var theFiles = File.openDialog ("please select files", "*.psd;*.tif;*.jpg", 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];
//save jpg;
                    myDocument.saveAs((new File(thePath+"/"+theNewName+"-"+theName+".jpg")),jpgopts,true);
                    }
          }
}
};
////// get psds, tifs and jpgs from files //////
function getFiles (theFile) {
     if (theFile.name.match(/\.(psd|tif)$/i) != null || theFile.constructor.name == "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
};

德国的祝福 olee

0 个答案:

没有答案