使 1 个随机图层在每个组中可见的脚本 [Photoshop cc2018]
Script to make 1 random layer visible within each group [Photoshop cc2018]
我正在尝试制作一个脚本,该脚本会随机 select 并在 Photoshop 上显示来自所有组的单个图层并将结果导出为 png。
我在这里找到了这个似乎有效的脚本:
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();
}
Share
除了它给我一个错误 8800:发生一般 Photoshop 错误。此功能可能在此版本的 Photoshop 中不可用。
线路:36
-> executeAction( idslct, desc300, DialogModes.NO );
我可以做些什么来让它工作,因为这将极大地帮助加快我的工作进程。
谢谢。
没有看到你的 PSD 是什么样子,很难说。但是,我认为代码在恢复功能上失败了。
试试这个:
function Revert()
{
// =======================================================
var idRvrt = charIDToTypeID( "Rvrt" );
executeAction( idRvrt, undefined, DialogModes.NO );
}
我正在尝试制作一个脚本,该脚本会随机 select 并在 Photoshop 上显示来自所有组的单个图层并将结果导出为 png。
我在这里找到了这个似乎有效的脚本:
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();
}
Share
除了它给我一个错误 8800:发生一般 Photoshop 错误。此功能可能在此版本的 Photoshop 中不可用。 线路:36 -> executeAction( idslct, desc300, DialogModes.NO );
我可以做些什么来让它工作,因为这将极大地帮助加快我的工作进程。 谢谢。
没有看到你的 PSD 是什么样子,很难说。但是,我认为代码在恢复功能上失败了。
试试这个:
function Revert()
{
// =======================================================
var idRvrt = charIDToTypeID( "Rvrt" );
executeAction( idRvrt, undefined, DialogModes.NO );
}