【发布时间】:2018-06-23 05:12:13
【问题描述】:
我用 Javascript 为 photoshop 编写了一个脚本,它获取用户输入(桌面上的框数),然后将其转换为像素大小。问题在于调整大小,图层不会改变到那个量,它会改变那个量。例如。 microsoftbox 从 800*800 开始,然后应更改为 500*500,但将其添加到等于 1300*1300。
app.preferences.rulerUnits = Units.PIXELS;
//Get all input
var microsoftboxes = prompt("How many boxes for microsoft?");
var gamesboxesx = prompt("How many across boxes for games?");
var gamesboxesy = prompt("How many down boxes for games?");
var adobeboxes = prompt("How many boxes for adobe?");
var filesboxes = prompt("How many boxes for files?");
var toolsboxes = prompt("How many boxes for tools?");
var recycleboxes = 1;
//Add percentage on and convert to pixel num
var mb = microsoftboxes * 75;
mb = mb + (mb * 0.04);
var gbx = gamesboxesx * 75;
gbx = gbx + (gbx * 0.04);
var gby = gamesboxesy * 75;
gby = gby + (gby * 0.04);
var ab = adobeboxes * 75;
ab = ab + (ab * 0.04);
var fb = filesboxes * 75;
fb = fb + (fb * 0.04);
var tb = toolsboxes * 75;
tb = tb + (tb * 0.04);
var rb = recycleboxes * 75;
rb = rb + (rb * 0.04);
//vars for change size
var doc = app.activeDocument;
var m = doc.layers.getByName('microsoft');
var g = doc.layers.getByName('games');
var a = doc.layers.getByName('adobe');
var t = doc.layers.getByName('tools');
var f = doc.layers.getByName('files');
var r = doc.layers.getByName('recycle');
m.resize(mb, 73, AnchorPosition.MIDDLELEFT);
g.resize(gbx, gby, AnchorPosition.TOPCENTER);
a.resize(ab, 73, AnchorPosition.MIDDLELEFT);
f.resize(fb, 73, AnchorPosition.MIDDLELEFT);
t.resize(tb, 73, AnchorPosition.MIDDLELEFT);
r.resize(rb, 73, AnchorPosition.MIDDLELEFT);
---更新--- 我设法弄清楚它尽管被设置为像素,但按百分比变化。例如。 files 应该设置为 78,但它被设置为
250 (the current value) * 0.78(78 as a percentage) = 195
文件被设置为 195 像素。有什么办法可以解决这个问题?
代码现在是:
var startru = app.preferences.rulerUnits;
var starttu = app.preferences.typeUnits;
app.preferences.rulerUnits = Units.PIXELS;
app.preferences.typeUnits = TypeUnits.PIXELS;
//Get all input
var microsoftboxes = prompt("How many boxes for microsoft?");
var gamesboxesx = prompt("How many across boxes for games?");
var gamesboxesy = prompt("How many down boxes for games?");
var adobeboxes = prompt("How many boxes for adobe?");
var filesboxes = prompt("How many boxes for files?");
var toolsboxes = prompt("How many boxes for tools?");
var recycleboxes = 1;
//Add percentage on and convert to pixel num
var mb = microsoftboxes * 75;
mb = mb + (mb * 0.04);
var gbx = gamesboxesx * 75;
gbx = gbx + (gbx * 0.04);
var gby = gamesboxesy * 75;
gby = gby + (gby * 0.04);
var ab = adobeboxes * 75;
ab = ab + (ab * 0.04);
var fb = filesboxes * 75;
fb = fb + (fb * 0.04);
var tb = toolsboxes * 75;
tb = tb + (tb * 0.04);
var rb = recycleboxes * 75;
rb = rb + (rb * 0.04);
//vars for change size
var doc = app.activeDocument;
var m = doc.layers.getByName('microsoft');
var g = doc.layers.getByName('games');
var a = doc.layers.getByName('adobe');
var t = doc.layers.getByName('tools');
var f = doc.layers.getByName('files');
var r = doc.layers.getByName('recycle');
m.resize(mb, 85, AnchorPosition.MIDDLELEFT);
g.resize(gbx, gby, AnchorPosition.TOPCENTER);
a.resize(ab, 85, AnchorPosition.MIDDLELEFT);
f.resize(fb, 85, AnchorPosition.MIDDLELEFT);
t.resize(tb, 85, AnchorPosition.MIDDLELEFT);
r.resize(rb, 85, AnchorPosition.MIDDLELEFT);
app.preferences.rulerUnits = startru;
app.preferences.typeUnits = starttu;
【问题讨论】:
-
猜这太难了!
-
我已经很长时间没有这样做了 - 但我很确定调整大小需要增量。所以尝试给它-300(例如,想从 800 中取 300 到 500)
-
所以把我的代码改成
m.resize(-mb, -73, AnchorPosition.MIDDLELEFT);我现在就试试。如果它可以作为答案写出来,我会接受。 -
抱歉没用。我已经更新了帖子。
-
我可以将原始值用作 100,因此百分比将等于原始值,但我正在寻找我的代码的问题。除非有人先这样做,否则我会尝试添加作为答案。
标签: javascript scripting photoshop photoshop-script