- 精华
- 活跃值
-
- 积分
- 775
- 违规
-
- 印币
-
- 鲜花值
-
- 在线时间
- 小时
累计签到:110 天 连续签到:1 天
|
楼主 |
发表于 2016-6-21 20:01:59
|
显示全部楼层
本帖最后由 poshuixukong 于 2016-6-21 20:04 编辑
[sell=6][mw_shl_code=javascript,true]#target Illustrator
#targetengine main
var win = new Window ("palette {margins:['10', 15, '10', 10], \
ABPnlanel {text:'尺寸标注', alignment:['fill', 'fill'], margins:[15, 20, 15, '13'], \
xlong:Button {text:'标注 X', preferredSize:[110, 25]}, \
yhigh:Button {text:'标注 Y', preferredSize:[110, 25]}, \
sp0anel { isSeparator:true, }, \
longhigh:Button {text:'标注 X/&Y', preferredSize:[110, 30]}}, \
TEXT:StaticText {text:'★★华印专版★★ ', alignment:['right', 'center']}}");
var sp0 = win.ABPnl.sp0;
if (sp0.parent.orientation == 'column') { sp0.maximumSize[1] = 1; sp0.alignment = ['fill', 'top']; } else { sp0.maximumSize[0] = 1; sp0.alignment = ['left', 'fill']; };;
var TEXT = win.TEXT;
var gfx = TEXT.graphics;
gfx.foregroundColor = gfx.newPen(gfx.PenType.SOLID_COLOR, [0, 0, 0.54509803921569, 1], 1);
win.ABPnl.xlong.onClick = function() {
var ABtwoMessage="drawSize(true,false)\n"+drawSize.toSource();
fMsg(ABtwoMessage);
}
win.ABPnl.yhigh.onClick = function() {
var ABtwoMessage="drawSize(false,true)\n"+drawSize.toSource();
fMsg(ABtwoMessage);
}
win.ABPnl.longhigh.onClick = function() {
var ABtwoMessage="drawSize(true,true)\n"+drawSize.toSource();
fMsg(ABtwoMessage);
}
win.show();
function fMsg(a) {
var b = new BridgeTalk;
b.target = "illustrator";
b.body = a;
b.send()
}
function drawSize(X, Y) {
unit = "mm";
if (unit == "mm") {
v = 72 / 25.4;
} else if (unit == "pt") {
v = 1;
}
l = 8 * v;
lineWidth = 0.3 * v;
dis1 = 0.5 * v;
dis2 = 0.1 * v;
arrSize = 4 * v;
fontSize = 6 * v;
arrScale = 1.5;
dotN = 2;
dotArr = [1, 10, 100, 1000, 10000];
dotN = dotArr[dotN];
doc = app.activeDocument;
sel = doc.selection;
var layercheck = false;
for (var i = 0; i < doc.layers.length; i++) {
if (doc.layers.name == '尺寸标注') {
mylayer = doc.layers;
layercheck = true;
}
}
if (layercheck == false) {
mylayer = doc.layers.add();
mylayer.name = '尺寸标注';
mylayer.move(doc, ElementPlacement.PLACEATBEGINNING);
}
var kValue = 0,
cValue = 100,
mValue = 0,
yValue = 0;
vColor = new CMYKColor();
vColor.black = kValue - 0;
vColor.cyan = cValue - 0;
vColor.magenta = mValue - 0;
vColor.yellow = yValue - 0;
for (var i = 0; i < sel.length; i++) {
x = sel.geometricBounds[0];
y = sel.geometricBounds[1];
w = sel.width;
h = sel.height;
wArr = [
[
[0, 0],
[0, l]
],
[
[w, 0],
[w, l]
],
[
[0, l / 2],
[w, l / 2]
],
[
[arrSize * arrScale, l / 2 - arrSize / 2],
[0, l / 2],
[arrSize * arrScale, l / 2 + arrSize / 2]
],
[
[w - arrSize * arrScale, l / 2 - arrSize / 2],
[w, l / 2],
[w - arrSize * arrScale, l / 2 + arrSize / 2]
]
];
hArr = [
[
[0, 0],
[l, 0]
],
[
[0, -h],
[l, -h]
],
[
[l / 2, 0],
[l / 2, -h]
],
[
[l / 2 + arrSize / 2, -arrSize * arrScale],
[l / 2, 0],
[l / 2 - arrSize / 2, -arrSize * arrScale]
],
[
[l / 2 + arrSize / 2, arrSize * arrScale - h],
[l / 2, -h],
[l / 2 - arrSize / 2, arrSize * arrScale - h]
]
];
wPosition = [w / 2, l / 2];
hPosition = [l / 2, -h / 2];
if (X == true) {
g = mylayer.groupItems.add();
for (var ii = 0; ii < wArr.length; ii++) {
var line = g.pathItems.add();
line.setEntirePath(wArr[ii]);
line.strokeColor = vColor;
line.filled = false;
}
var text = g.textFrames.add();
text.textRange.characterAttributes.size = fontSize;
text.textRange.characterAttributes.fillColor = vColor;
text.contents = Math.round(w / v * dotN) / dotN + unit;
text.left = wPosition[0] - text.width / 2;
text.top = wPosition[1] + text.height + dis2;
g.position = [x, y + g.height + dis1];
}
if (Y == true) {
g = mylayer.groupItems.add();
for (var ii = 0; ii < hArr.length; ii++) {
var line = g.pathItems.add();
line.setEntirePath(hArr[ii]);
line.strokeColor = vColor;
line.filled = false;
}
var text = g.textFrames.add();
text.textRange.characterAttributes.size = fontSize;
text.textRange.characterAttributes.fillColor = vColor;
text.contents = Math.round(h / v * dotN) / dotN + unit;
text.rotate(90);
text.left = hPosition[0] - text.width - dis2;
text.top = hPosition[1] + text.height / 2;
g.position = [x - g.width - dis1, y];
}
}
}
[/mw_shl_code][/sell]
|
|