gpt4 book ai didi

javascript - 在 Photoshop cc 20.0.0 中通过批量智能对象中的脚本替换内容(替换图层)

转载 作者:行者123 更新时间:2023-12-02 23:49:30 24 4
gpt4 key购买 nike

因此,我将这 28 个 *.tif 图像文件作为 28 个图层(智能对象)排列在 .psd 文件中,并希望用另一个 .tif 文件替换每个图层。我希望运行一些带有循环的脚本(jsx),如下所示:

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;
}}}

2020 年 7 月更新:抱歉这么晚了,我找到了一个解决方案,就像这样,你首先应该下载 json2.js :

// 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;
}

}
}
};

最佳答案

尝试此代码

它将循环遍历所有图层,并将其替换为您选择的 .tiff 文件

var doc = app.activeDocument;

function editContent() {

cTID = function(s) { return app.charIDToTypeID(s); };
sTID = function(s) { return app.stringIDToTypeID(s); };

function Rename() {
// Edit Contents
function step1(enabled, withDialog) {
if (enabled != undefined && !enabled)
return;
var dialogMode = (withDialog ? DialogModes.ALL : DialogModes.NO);
var desc1 = new ActionDescriptor();
executeAction(sTID('placedLayerEditContents'), desc1, dialogMode);
};

step1(); // Edit Contents
};

Rename.main = function () {
Rename();
};

Rename.main();

}

function merge() {
var fileRef = File.openDialog ('Choose File', ['*.tif;*tiff'], true);
app.open( new File( fileRef ) );
if(app.activeDocument.activeLayer.isBackgroundLayer ) app.activeDocument.activeLayer.name = 'From Background';
app.activeDocument.selection.selectAll();
app.activeDocument.selection.copy();
app.activeDocument.selection.deselect();


var idMk = charIDToTypeID( "Mk " );
var desc8946 = new ActionDescriptor();
var idnull = charIDToTypeID( "null" );
var ref1324 = new ActionReference();
var idBckL = charIDToTypeID( "BckL" );
ref1324.putClass( idBckL );
desc8946.putReference( idnull, ref1324 );
var idUsng = charIDToTypeID( "Usng" );
var ref1325 = new ActionReference();
var idLyr = charIDToTypeID( "Lyr " );
var idOrdn = charIDToTypeID( "Ordn" );
var idTrgt = charIDToTypeID( "Trgt" );
ref1325.putEnumerated( idLyr, idOrdn, idTrgt );
desc8946.putReference( idUsng, ref1325 );
executeAction( idMk, desc8946, DialogModes.NO );



app.activeDocument.close(SaveOptions.SAVECHANGES);
app.activeDocument.artLayers.add();
app.activeDocument.paste();
app.activeDocument.flatten();
app.activeDocument.close(SaveOptions.SAVECHANGES);
}

for (var i=0;i<doc.layers.length;i++){
doc.activeLayer=doc.layers[i];
editContent();
merge();
}

关于javascript - 在 Photoshop cc 20.0.0 中通过批量智能对象中的脚本替换内容(替换图层),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55701159/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com