Photoshop动作使每组中的1个随机图层可见

问题描述 投票:0回答:1

我正在尝试使用Photoshop动作生成随机图像,这些图像由随机的图层采样组成。我有3组图层,默认情况下都不可见。

  1. 在每个组中,我想使1个随机图层可见(总共将有3个“在”图层上)
  2. 将整个事物导出为.png文件。
  3. 重复n次

示例组/图层:

[FRUITS]
* [Apples]
* [Oranges]
* [Pears]
* [Bananas]
* [Kiwis]

[VEGGIES]
* [Asparagus]
* [Cilantro]
* [Eggplant]

[MEATS]
* [Beef]
* [Pork]

默认情况下隐藏所有图层,但是当我播放动作时,我可能会得到以下结果(可见图层):

Image1: [Apples] [Eggplant] [Pork]
Image2: [Pears] [Asparagus] [Pork]
Image3: [Kiwis] [Cilantro] [Beef]
photoshop photoshop-script
1个回答
0
投票

这是我的脚本,但在运行之前不要忘记执行以下步骤:

  1. 隐藏除背景外的所有图层和组。
  2. 保存你的PSD。
  3. 关闭然后重新打开。

现在你准备摇滚了。

特征

  • 从您的群组制作您想要的无限模式。
  • 保存所有模式作为索引单独的PNG在名为PNG的单独文件夹中。

观看GIF(下方)了解更多信息:

enter image description here

function Visible() {
  var Grps = app.activeDocument.layerSets; // loops through all groups
  for(var i = 0; i < Grps.length; i++){
    var tmp = app.activeDocument.layerSets[i].layers.length;
    app.activeDocument.layerSets[i].visible=true;
    var groupChildArr = app.activeDocument.layerSets[i].layers;
    var randLays = Math.floor(Math.random() * tmp);
    groupChildArr[randLays].visible = true;
    Save();
  }
  Revert();
}

function Save() {
  var outFolder = app.activeDocument; // psd name
  var outPath = outFolder.path;
  var fName = "PNG";   // define folder name
  var f = new Folder(outPath + "/" + fName);
  if ( ! f.exists ) {
    f.create()
  }
  var saveFile = new File(outPath + "/" + fName +"/" + "Pattern_" +  num + ".png");
  pngSaveOptions = new PNGSaveOptions();
  pngSaveOptions.interlaced = false;
  app.activeDocument.saveAs(saveFile, pngSaveOptions, true, Extension.LOWERCASE);
}

function Revert(){
  var idslct = charIDToTypeID( "slct" );
  var desc300 = new ActionDescriptor();
  var idnull = charIDToTypeID( "null" );
  var ref163 = new ActionReference();
  var idSnpS = charIDToTypeID( "SnpS" );
  ref163.putName( idSnpS, "test.psd" );
  desc300.putReference( idnull, ref163 );
  executeAction( idslct, desc300, DialogModes.NO );
}

var count = prompt("How many patterns you want","");
for (var x=0 ; x<count;x++){
  var num = x+1;
  Visible();
}
© www.soinside.com 2019 - 2024. All rights reserved.