【发布时间】:2019-09-06 03:25:19
【问题描述】:
所以我将这 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;
}
}
}
};
【问题讨论】:
-
文件名按以下顺序排列:
chr$i_$k_$k示例:chr1_start_a、chr1_end_q、chr22_start_b 等 -
仅供参考,通常最好edit your question 来添加信息。究竟是什么问题?
标签: javascript json jsx photoshop