- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有脚本
“3.Working 文件夹
中的 PSD (activeDocument) 将 jpg
保存在目录“../UserNameJobName/4.WIP/”的草稿文件夹中
问题是一切正常,直到我想创建第三个草稿文件夹(draft003)。
然后它再次将 activeDocument 保存在 Draft002 中的同一个 jpg 文件中,而不是创建新文件夹 Draft003 并分别保存在那里。
这表明 var DraftCounter
不能高于 2 值。我不确定哪里有错误。据我所知,在 Photoshop CC 中它可以正常工作,没有任何问题。
[文件夹结构 zip 链接]
https://www.dropbox.com/s/kbalzsubs2477jy/191130_WARGAMES_LUKKAR.zip?dl=0
Main file directory pic
Draft directory pic
代码
#target photoshop;
var wipCounter = 1;
var fileNotFound = true;
main();
function main(){
//Get file information
var doc = app.activeDocument;
var docName = doc.name;
var docPath = doc.path;
//Get the percentage to scale by
var scaleValue = prompt("Enter the WIP JPEG scale percentage", "100");
//Figure out the location of the WIP folder
var savePath = docPath.toString();
savePath = savePath.slice(0,-10);
savePath = savePath + "/4.WIP/";
var currDoc = docName.toString();
currDoc = currDoc.slice(0,-4);
//global variables are defined here
//Look at the WIP folder and run a search for anything containing the word "draft"
//Define the location of the WIP folder
var inWIPFolder = new Folder(savePath);
//Look in each folder and create an array containing all of the information
var fileList = inWIPFolder.getFiles();
// Look at each array and sort the info out
for(var a=0; a<fileList.length; a++) {
//Exclude anything that is not a folder
if(fileList[a] instanceof Folder) {
//convert each foldername to string for editing
var fileName = fileList[a].toString();
var draftSearch = fileName.search("draft");
if(draftSearch > -1) {
var draftCounter = fileName.slice(draftSearch);
if(fileNotFound == true) {
searchDraftFolder(draftCounter, savePath, currDoc);
}
}
}
}
//Formatting the numbers
if(wipCounter < 10){
wipCounter = "00" + wipCounter.toString();
}else if(wipCounter >= 10 && wipCounter < 100) {
wipCounter = "0" + wipCounter.toString();
}
//Define the path of the draft folders
savePath = Folder(savePath +"/draft" + wipCounter);
//Check to see if the draft folders exists. If not, make one
if(!savePath.exists){
savePath.create();
}
//Define the WIP file name with the incremental counter
var wipFileName =savePath + "/" + currDoc + "_WIP" + wipCounter + ".jpg";
//Resize the file
doc.selection.selectAll();
var blankLayer = doc.artLayers.add();
blankLayer.name = "blankLayer";
doc.selection.copy(true);
doc.layers.getByName("blankLayer").remove();
//Make new doc to paste into
app.preferences.rulerUnits = Units.PIXELS;
//arguments are: Width, Height, resolution, filename, colourspce, documentfill
app.documents.add(UnitValue(doc.width, "PX"), UnitValue(doc.height, "PX"), doc.resolution, wipFileName, NewDocumentMode.RGB, DocumentFill.TRANSPARENT,1);
app.activeDocument.paste();
app.activeDocument.resizeImage(UnitValue(scaleValue, "PERCENT"), null, null, ResampleMethod.BICUBICSHARPER);
//Save a RGBJpeg
jpegFileSaver(app.activeDocument, new File(wipFileName), 10);
//Close the new document down
app.activeDocument.close(SaveOptions.DONOTSAVECHANGES);
//Deselect
doc.selection.deselect();
alert(currDoc + "WIP" + wipCounter + " saved.");
}
function searchDraftFolder(draftCounter, savePath, currDoc){
var fileSearch = -1;
//Define the location of each draft folder
var internalFolder = new Folder(savePath + "/" + draftCounter);
//Look in each folder and create an array containing all of the information
var internalFileList = internalFolder.getFiles();
// Look at each array and sort the info out
for(var a=0; a<internalFileList.length; a++) {
//Exclude anything that is not a file
if(internalFileList[a] instanceof File) {
// convert each filename to string for editing
var fileName = internalFileList[a].toString();
//Searching the current document name and replacing spaces with %20
var currDocStripped = currDoc.replace(/ /g, '%20');
//Checking files until a result greater than 0 appears
if(fileSearch === -1){
//search for the current file name
fileSearch = fileName.search(currDocStripped);
}
}
}
//if the filesearch does not return a result:
if(fileSearch === -1){
fileNotFound = true;
//if it does return a result:
} else {
//Slice the number off the draft folder
draftCounter = draftCounter.slice(-3);
//convert the string into an integer
draftCounter = parseInt(Number(draftCounter));
//increment the number up
wipCounter++;
//terminate the main loop
fileNotFound = false;
}
}
//A resuable JPEG save script
function jpegFileSaver(doc, saveFile, quality){
//define the save options
var saveOptions = new JPEGSaveOptions();
saveOptions.embedColorProfile = true;
saveOptions.formatOptions = FormatOptions.STANDARDBASELINE;
saveOptions.quality = quality;
//save the files
doc.saveAs(saveFile, saveOptions, true);
}
提前致谢。
代码作者的额外积分 http://jamesmcdonald3d.com/
最佳答案
问题出在 searchDraftFolder()
上。当它在 draft001
中找到已保存的 Great Map_wip
时,fileNotFound
将设置为 false
并且第 39 行的循环终止。这就是 wipCounter
卡在 2 上的原因:它递增 1,仅此而已。
这里我稍微重写了这个函数,试图使其更简单:所有必要的循环都在函数内部,我认为它更容易理解。
附:至少在 CC 上还存在一个问题:app.documents.add()
显示界面。这是因为您使用完整路径作为新文档名称,并且不能在其中使用 \
符号,因此 Photoshop 建议使用不同的名称并显示它。我为文档名称添加了一个单独的变量,没有路径(第 49 行)以在 .add()
main();
function main()
{
//Get file information
var doc = app.activeDocument;
var docName = doc.name;
var docPath = doc.path;
var wipCounter;
//Get the percentage to scale by
var scaleValue = prompt("Enter the WIP JPEG scale percentage", "100");
//Figure out the location of the WIP folder
var savePath = docPath.toString();
savePath = savePath.slice(0, -10);
savePath = savePath + "/4.WIP/";
var currDoc = docName.toString();
currDoc = currDoc.slice(0, -4);
//global variables are defined here
//Look at the WIP folder and run a search for anything containing the word "draft"
//Define the location of the WIP folder
var inWIPFolder = new Folder(savePath);
// !! modifications
wipCounter = searchDraftFolder(inWIPFolder, currDoc)
//Formatting the numbers
if (wipCounter < 10)
{
wipCounter = "00" + wipCounter.toString();
}
else if (wipCounter >= 10 && wipCounter < 100)
{
wipCounter = "0" + wipCounter.toString();
}
//Define the path of the draft folders
savePath = Folder(savePath + "/draft" + wipCounter);
//Check to see if the draft folders exists. If not, make one
if (!savePath.exists)
{
savePath.create();
}
//Define the WIP file name with the incremental counter
var wipFileName = currDoc + "_WIP" + wipCounter + ".jpg";
var wipFilePath = savePath + "/" + wipFileName;
//Resize the file
doc.selection.selectAll();
var blankLayer = doc.artLayers.add();
blankLayer.name = "blankLayer";
doc.selection.copy(true);
doc.layers.getByName("blankLayer").remove();
//Make new doc to paste into
app.preferences.rulerUnits = Units.PIXELS;
//arguments are: Width, Height, resolution, filename, colourspce, documentfill
app.documents.add(UnitValue(doc.width, "PX"), UnitValue(doc.height, "PX"), doc.resolution, wipFileName, NewDocumentMode.RGB, DocumentFill.TRANSPARENT, 1);
app.activeDocument.paste();
app.activeDocument.resizeImage(UnitValue(scaleValue, "PERCENT"), null, null, ResampleMethod.BICUBICSHARPER);
//Save a RGBJpeg
jpegFileSaver(app.activeDocument, new File(wipFilePath), 10);
//Close the new document down
app.activeDocument.close(SaveOptions.DONOTSAVECHANGES);
//Deselect
doc.selection.deselect();
alert(currDoc + "_WIP" + wipCounter + " saved.");
}
// p is WIP path
// n is a name of the active doc without extension
function searchDraftFolder(p, n)
{
var fileList = p.getFiles(); // folders in wip folder
var counter = 1;
var drafts, fileName, i, k;
// for all the files found..
for (i = 0; i < fileList.length; i++)
{
//if a folder is found and its name has 'draft' in it
if (fileList[i] instanceof Folder && fileList[i].name.indexOf('draft') != -1)
{
//get files inside this draft folder
drafts = fileList[i].getFiles();
// for all files inside
for (k = 0; k < drafts.length; k++)
{
//'.name' gives us a URI-name, so replacing %20 with ' '. Probably should add more special symbols here if you use them
fileName = drafts[k].name.replace(/%20/g, ' ');
// if there's a file that starts with active doc name counter is incremented
if (fileName.indexOf(n) != -1)
{
counter++
}
}
}
}
return counter;
}
//A resuable JPEG save script
function jpegFileSaver(doc, saveFile, quality)
{
//define the save options
var saveOptions = new JPEGSaveOptions();
saveOptions.embedColorProfile = true;
saveOptions.formatOptions = FormatOptions.STANDARDBASELINE;
saveOptions.quality = quality;
//save the files
doc.saveAs(saveFile, saveOptions, true);
}
关于javascript - 脚本 Photoshop CS6 版本 13 64 位中的计数器问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59212976/
我在leetcode上看到这段代码,是一道求众数的题,下面是题目描述: 给定一个大小为 n 的数组,找到多数元素。众数元素是出现次数超过 ⌊ n/2 ⌋ 次的元素。 你可以假设数组是非空的并且多数元素
每次在 JavaScript 中执行特定操作时,例如: $(function() { $('#typing').keyup(function () { switch($(this)
我一直在为网页设计一个计数器,但我一直被这个我无法解决的功能所困扰。 我有一个 4 个 div 的计数器,因为其中两个是小数字,另外两个是大数字,所以第一个运行得很快,我看不到它们的功能。 有人知道如
我已经在文档中进行了一些搜索,并在网上花了一段时间,但找不到解决方案!我希望警报告诉我单击 .thumb 时它处于each() 的哪一次迭代。 EG:有六个.thumb,我点击数字3,浏览器弹出3!
在 Handlebars 中,假设我有 names 的集合.我能怎么做 {{#each names}} {{position}} {{name}} {{/each}} 在哪里 {{position}}
这个问题在这里已经有了答案: Numbering rows within groups in a data frame (9 个回答) 4年前关闭。 我们如何在数据帧的每组中生成唯一的 ID 号?以下
我正在努力解决以下问题。我希望为给定的“一”序列创建一个计数器。例如,我有以下内容: 1 1 1 1 0 0 1 1 1 0 0 1 1 1 1 鉴于该序列,我希望为 1 的每个序列设置一个计数器直到
我正在努力解决以下问题。我希望为给定的“一”序列创建一个计数器。例如,我有以下内容: 1 1 1 1 0 0 1 1 1 0 0 1 1 1 1 鉴于该序列,我希望为 1 的每个序列设置一个计数器直到
我有一个jsfiddle here 这是一个简单的 JavaScript 函数,可以计算出设定的数字。 是否可以进行这种计数,但也保留一位小数 所以它算 1.1、1.2、1.3 等。 func
我正在构建一个计数器,当我按下鼠标时,它应该增加到 maxValue 并且减少不超过 0。我还可以选择将计数器重置为其初始值:0。另外,如果 maxValue 是偶数,它应该计数到该数字。但是,如果
所以我成功地为字母和单词构建了其他计数器,但现在我只能用这个来计算句子。我的代码如下,当我运行它时,它会返回很多错误消息: #include #include #include int main
Closed. This question is off-topic。它当前不接受答案。
我需要一个计数器,它会随着某些任务的完成而递增。我们只需要最后一小时的值,即窗口将移动而不是静态时间。 解决此问题的最佳方法是什么?我能想到的一种方法是拥有一个大小为 60 的数组,每分钟一个,并更新
我希望使用计数器来为我提供独特的引用系统。我想单击一个按钮,然后检查一个字段/文件中的最后一个数字,然后简单地向其添加 1,然后将其插入到屏幕上的字段中? 不确定执行此操作的最佳方法或具体如何执行此操
我有一个用 php 制作的表格,在该表格内我显示了数据库中的一些内容。我在每个 td 中创建了一个简单的按钮(类似于 Like),我希望每次点击它都会增加 1。这是带有按钮的行: echo "
如何将数据库中的值转换为可用于 if else 函数的 int 值? 例如:在我的数据库“armnumber = 3”中,如何在 if else 函数中使用它? 代码 string myConnect
我需要生成唯一的“ids”,问题是,它只能在 1 - 99999 之间。 “好”的是,它仅在与另一列组合时必须是唯一的。 我们有组,每个组都有自己的“group_id”,每个组都需要类似 unique
有这个简单的代码: UPDATE counter SET c= c +1 where id = 1; 并且它在开头的 c 字段中为 null 的情况下不起作用。它只有在已经输入了一些数字时才有效,也就
我正在尝试在 python 中构建一个具有闭包属性的计数器。以下工作中的代码: def generate_counter(): CNT = [0] def add_one():
我使用 CSS 来计算 HTML 文档中的部分: body {counter-reset: sect;} section:before { counter-increment: sect;
我是一名优秀的程序员,十分优秀!