[FIXED] Ersetzen Sie den Inhalt durch Scripting in Stapel von intelligenten Objekten (Ersetzen Sie Ebenen) in Photoshop CC 20.0.0

Ausgabe

Ich habe also diese 28 *.tif-Bilddateien als 28 Ebenen (intelligente Objekte), die ich in einer .psd-Datei angeordnet habe, und möchte jede Ebene durch eine andere .tif-Datei ersetzen. Ich möchte ein Skript (jsx) mit einer Schleife wie folgt ausführen:

for (i=1;i<=28;i++) {
  for j in (start,end) {
     for k in (a,b,c,d,e,f) {
            file = 'chr' + $i + '_' + $j + '_' + $k;
                     }}}

Update Juli2020: Entschuldigung für diese Verspätung, ich hatte eine Lösung gefunden und war so, Sie sollten zuerst json2.js herunterladen:

// replace smart object’s content and save psd;
#target photoshop
#include json2.js
if (app.documents.length > 0) {
  var myDocument = app.activeDocument;
  var theName = myDocument.name.match(/(.*)\.[^\.]+$/)[1];
  var thePath = myDocument.path;

  psdOpts = new PhotoshopSaveOptions();
  psdOpts.embedColorProfile = true;
  psdOpts.alphaChannels = true;
  psdOpts.layers = true;
  psdOpts.spotColors = true;

//lists for desired filename input 
    var ppath = "c:/here/goes/file/path/for/taking/input/file";
// (you can implement using json too)
       var num = [
      "2",
      "3",
      "4",
      "5",
      "6",
      "7",
      "8",
      "9",
      "10",
      "11",
      "12",
      "13",
      "14",
      "15",
      "16",
      "17",
      "18",
      "19",
      "20",
      "21",
      "22",
      "X",
      "Y"
    ];
    var nnum = [
      "1",
      "2",
      "3",
      "4",
      "5",
      "6",
      "7",
      "8",
      "9",
      "10",
      "11",
      "12",
      "13",
      "14",
      "15",
      "16",
      "17",
      "18",
      "19",
      "20",
      "21",
      "22",
      "X"
    ];
    var lletter = [
      "q",
      "p",
      "o",
      "n",
      "m",
      "l",
      "u",
      "t",
      "k",
      "j",
      "i",
      "h",
      "g",
      "f",
      "d",
      "c",
      "b",
      "ae",
      "ad",
      "ac",
      "ab",
      "aa",
      "a",
      "z",
      "y",
      "x",
      "w",
      "v"
    ];
    var letter = [
      "q",
      "p",
      "o",
      "n",
      "m",
      "l",
      "u",
      "t",
      "k",
      "j",
      "i",
      "h",
      "g",
      "f",
      "d",
      "c",
      "b",
      "ae",
      "ad",
      "ac",
      "ab",
      "aa",
      "a",
      "z",
      "y",
      "x",
      "w",
      "v"
    ];
  
// main code starts here : 

      for (var i in num) {
        saveJPEG(thNamer);
        alert("saved Jpeg");
        myDocument.saveAs((new File("D:\\thesis-bioinformatics" + '/vol-ID/' + thNamer + "_" +".psd")),psdOpts,true);
        alert("saved psd");
        
          for (var k in letter) {
            var TitleGroup = myDocument.layerSets.getByName('chr_place_plot_');
            var TitleGroup2 = myDocument.layerSets.getByName('chr_text');
           
            var thNamer = 'chr' + num[i] + '_start' + '_plot_';
            var thNames = 'chr' + num[i] + '_start' + '_plot_' + letter[k];
            var thprevNames = 'chr' + nnum[i] + '_start' + '_plot_' + letter[k];
            VolLayer = TitleGroup.artLayers.getByName(thprevNames);
            VolLayer2 = TitleGroup2.artLayers.getByName('Chr1');
           
            myDocument.activeLayer = VolLayer;
            var theFiles = ppath + thNames + '.tif';
          
          if (theFiles && thprevNames != thNames) 
          {         
            VolLayer = replaceContents(theFiles);
            VolLayer2.textItem.contents = thNamer;
            }

      }
    }
};  

Lösung

Dies nimmt Eingaben in JSON entgegen und ersetzt Text und kann auf ähnliche Weise gemacht werden, um Bilder zu ersetzen, die den Dateipfad angeben.

Suchen Sie einfach nach der Ebenengruppe und ersetzen Sie den Inhalt durch den Text oder die Datei Ihrer Wahl. Speichern Sie dann die JPG- und PSD-Datei in einem Ausgabeordner.

Sie können den Code hier sehen: https://github.com/avialxee/photoshop-jsx


#target photoshop
#include json2.js // json to js parser


if (app.documents.length > 0) {
    var myDocument = app.activeDocument;
    var theName = myDocument.name.match(/(.*)\.[^\.]+$/)[1];
    var thePath = myDocument.path;
    var outpath = thePath+'/output/';
    
    psdOpts = new PhotoshopSaveOptions();
    psdOpts.embedColorProfile = true;
    psdOpts.alphaChannels = true;
    psdOpts.layers = true;
    psdOpts.spotColors = true;


    var obj = loadInput('inputs.json')

    function loadInput(relpath){
        var input = new File($.fileName);
        var jsoninput = new File(input.path + '/' + relpath);

        jsoninput.open('r');
        var name = jsoninput.read();
        jsoninput.close();

        return JSON.parse(name);
    }


    
    for (var i in obj.name) {
        
        var TitleGroup = myDocument.layerSets.getByName('baseImage');
        var TitleGroup2 = myDocument.layerSets.getByName('text');
        var thNamer = obj.name[i];
        VolLayer = TitleGroup2.artLayers.getByName('participantName');
        myDocument.activeLayer = VolLayer;
        //var theFiles = ppath + thNamer + '.tif';
        
        if (thNamer) {
            //VolLayer = replaceContents(theFiles);
            VolLayer.textItem.contents = thNamer;
            saveJPEG(thNamer);
            alert("saved Jpeg");
            myDocument.saveAs((new File(outpath+ thNamer + "_" + ".psd")), psdOpts, true);
            
        }      
    }
};




function getFiles(theFile) {
    if (theFile.name.match(/\.(psd|tif)$/i)) {
        return true
    };
};

function replaceContents(newFile) {
    var idplacedLayerReplaceContents = stringIDToTypeID("placedLayerReplaceContents");
    var desc3 = new ActionDescriptor();
    var idnull = charIDToTypeID("null");
    desc3.putPath(idnull, new File(theFiles));
    var idPgNm = charIDToTypeID("PgNm");
    desc3.putInteger(idPgNm, 1);
    executeAction(idplacedLayerReplaceContents, desc3, DialogModes.NO);
};

function saveJPEG(name) {
    var doc = app.activeDocument;
    var file = new File(outpath + name + '.Jpg');
    var opts = new JPEGSaveOptions();
    opts.quality = 10;
    doc.saveAs(file, opts, true);
}


Beantwortet von –
Avi Alxee


Antwort geprüft von –
Cary Denson (FixError Admin)

0 Shares:
Leave a Reply

Your email address will not be published. Required fields are marked *

You May Also Like