◆- Adobe插件与脚本区 主要讨论Adobe插件开发与软件脚本撰写

发表新主题 关闭主题
 
只看楼主 主题工具
旧 2018-10-24, 15:54     #1
rym rym 当前离线
正式会员
等级: 小兄弟
级别:6 | 在线时长:72小时 | 升级还需:5小时级别:6 | 在线时长:72小时 | 升级还需:5小时级别:6 | 在线时长:72小时 | 升级还需:5小时
 
Uid: 285067
注册日期: 2012-03-04, 19:03
帖子: 17
感谢: 0
1 个帖子获得 1 次感谢
现金: 0金币
资产: 130金币
声望: 10 rym 向着好的方向发展
rym rym 当前离线
正式会员
等级: 小兄弟
级别:6 | 在线时长:72小时 | 升级还需:5小时级别:6 | 在线时长:72小时 | 升级还需:5小时级别:6 | 在线时长:72小时 | 升级还需:5小时
 
Uid: 285067
注册日期: 2012-03-04, 19:03
帖子: 17
感谢: 0
1 个帖子获得 1 次感谢
现金: 0金币
资产: 130金币
声望: 10 rym 向着好的方向发展
默认 请大神帮我修改个标注间距的脚本   



/*
* Description: An Adobe Illustrator script that automates measurements of objects. This is an early version that has not been sufficiently tested. Use at your own risks.
* Usage: Select 1 to 2 page items in Adobe Illustrator, then run this script by selecting File > Script > Other Scripts > (choose file)
* License: GNU General Public License Version 3. (http://www.gnu.org/licenses/gpl-3.0-standalone.html)
*
* Copyright (c) 2009. William Ngan.
* http://www.metaphorical.net
*/

// Create an empty dialog window near the upper left of the screen
var dlg = new Window('dialog', 'Spec');
dlg.frameLocation = [100,100];
dlg.size = [250,250];

dlg.intro = dlg.add('statictext', [20,20,150,40] );
dlg.intro.text = 'First select 1 or 2 items';

dlg.where = dlg.add('dropdownlist', [20,40,150,60] );
dlg.where.selection = dlg.where.add('item', 'top');
dlg.where.add('item', 'bottom');
dlg.where.add('item', 'left');
dlg.where.add('item', 'right');

dlg.btn = dlg.add('button', [20,70,150,90], 'Specify', 'spec');



// document
var doc = activeDocument;

// spec layer
try {
var speclayer =doc.layers['spec'];
} catch(err) {
var speclayer = doc.layers.add();
speclayer.name = 'spec';
}

// measurement line color
var color = new RGBColor;
color.red = 255;
color.green = 0;
color.blue = 0;

// gap between measurement lines and object
var gap = 2;

// size of measurement lines.
var size = 10;

// number of decimal places
var decimals = 0;

// pixels per inch
var dpi = 72;

/**
Start the spec
*/
function startSpec() {

if (doc.selection.length==1) {
specSingle( doc.selection[0].geometricBounds, dlg.where.selection.text );
} else if (doc.selection.length==2) {
specDouble( doc.selection[0], doc.selection[1], dlg.where.selection.text );
} else {
alert('please select 1 or 2 items');
}

dlg.close ();
}




/**
Spec the gap between 2 elements
*/
function specDouble( item1, item2, where ) {

var bound = new Array(0,0,0,0);

var a = item1.geometricBounds;
var b = item2.geometricBounds;

if (where=='top' || where=='bottom') {

if (b[0]>a[0]) { // item 2 on right,

if (b[0]>a[2]) { // no overlap
bound[0] =a[2];
bound[2] = b[0];
} else { // overlap
bound[0] =b[0];
bound[2] = a[2];
}
} else if (a[0]>=b[0]){ // item 1 on right

if (a[0]>b[2]) { // no overlap
bound[0] =b[2];
bound[2] = a[0];
} else { // overlap
bound[0] =a[0];
bound[2] = b[2];
}
}

bound[1] = Math.max (a[1], b[1]);
bound[3] = Math.min (a[3], b[3]);

} else {

if (b[3]>a[3]) { // item 2 on top
if (b[3]>a[1]) { // no overlap
bound[3] =a[1];
bound[1] = b[3];
} else { // overlap
bound[3] =b[3];
bound[1] = a[1];
}
} else if (a[3]>=b[3]){ // item 1 on top

if (a[3]>b[1]) { // no overlap
bound[3] =b[1];
bound[1] = a[3];
} else { // overlap
bound[3] =a[3];
bound[1] = b[1];
}
}

bound[0] = Math.min(a[0], b[0]);
bound[2] = Math.max (a[2], b[2]);
}
specSingle(bound, where );
}


/**
spec a single object
[MENTION=343005]para[/MENTION]m bound item.geometricBound
[MENTION=343005]para[/MENTION]m where 'left,' 'top', 'bottom', 'right'
*/
function specSingle( bound, where ) {


// width and height
var w = bound[2]-bound[0];
var h = bound[1]-bound[3];

// a & b are the horizontal or vertical positions that change
// c is the horizontal or vertical position that doesn't change
var a = bound[0];
var b = bound[2];
var c = bound[1];

// xy='x' (horizontal measurement), xy='y' (vertical measurement)
var xy = 'x';

// a direction flag for placing the measurement lines.
var dir = 1;

switch( where ) {

case 'top':
a = bound[0];
b = bound[2];
c = bound[1];
xy = 'x';
dir = 1;
break;

case 'bottom':
a = bound[0];
b = bound[2];
c = bound[3];
xy = 'x';
dir = -1;
break;

case 'left':
a = bound[1];
b = bound[3];
c = bound[0];
xy = 'y';
dir = -1;
break;

case 'right':
a = bound[1];
b = bound[3];
c = bound[2];
xy = 'y';
dir = 1;
break;

}

// create the measurement lines
var lines = new Array();

// horizontal measurement
if (xy=='x') {

// 2 vertical lines
lines[0]= new Array( new Array(a, c+(gap)*dir) );
lines[0].push ( new Array(a, c+(gap+size)*dir) );
lines[1]= new Array( new Array(b, c+(gap)*dir) );
lines[1].push( new Array(b, c+(gap+size)*dir) );

// 1 horizontal line
lines[2]= new Array( new Array(a, c+(gap+size/2)*dir ) );
lines[2].push( new Array(b, c+(gap+size/2)*dir ) );

// create text label
if (where=='top') {
var t = specLabel( w, (a+b)/2, lines[0][1][1] );
t.top += t.height;
} else {
var t = specLabel( w, (a+b)/2, lines[0][0][1] );
t.top -= t.height;
}
t.left -= t.width/2;

// vertical measurement
} else {

// 2 horizontal lines
lines[0]= new Array( new Array( c+(gap)*dir, a) );
lines[0].push ( new Array( c+(gap+size)*dir, a) );
lines[1]= new Array( new Array( c+(gap)*dir, b) );
lines[1].push( new Array( c+(gap+size)*dir, b) );

//1 vertical line
lines[2]= new Array( new Array(c+(gap+size/2)*dir, a) );
lines[2].push( new Array(c+(gap+size/2)*dir, b) );

// create text label
if (where=='left') {
var t = specLabel( h, lines[0][1][0], (a+b)/2 );
t.left -= t.width;
} else {
var t = specLabel( h, lines[0][0][0], (a+b)/2 );
t.left += size;
}
t.top += t.height/2;
}

// draw the lines
var specgroup = new Array(t);

for (var i=0; i<lines.length; i++) {
var p = doc.pathItems.add();
p.setEntirePath ( lines[i] );
setLineStyle( p, color );
specgroup.push( p );
}

group(speclayer, specgroup );

}


/**
Create a text label that specify the dimension
*/
function specLabel( val, x, y) {

var t = doc.textFrames.add();
t.textRange.characterAttributes.size = 12;
t.textRange.characterAttributes.alignment = StyleRunAlignmentType.center;

var v = val;
switch (doc.rulerUnits) {
case RulerUnits.Inches:
v = val/dpi;
v = v.toFixed (decimals);
break;

case RulerUnits.Centimeters:
v = val/(dpi/2.54);
v = v.toFixed (decimals);
break;

case RulerUnits.Millimeters:
v = val/(dpi/25.4);
v = v.toFixed (decimals);
break;

case RulerUnits.Picas:
v = val/(dpi/6);
var vd = v - Math.floor (v);
vd = 12*vd;
v = Math.floor(v)+'p'+vd.toFixed (decimals);
break;

default:
v = v.toFixed (decimals);
}

t.contents = v;
t.top = y;
t.left = x;

return t;

}

function setLineStyle(path, color) {
path.filled = false;
path.stroked = true;
path.strokeColor = color;
path.strokeWidth = 0.5;

return path;
}


/**
* Group items in a layer
*/
function group( layer, items, isDuplicate) {

// create new group
var gg = layer.groupItems.add();

// add to group
// reverse count, because items length is reduced as items are moved to new group
for(var i=items.length-1; i>=0; i--) {

if (items[i]!=gg) { // don't group the group itself
if (isDuplicate) {
newItem = items[i].duplicate (gg, ElementPlacement.PLACEATBEGINNING);
} else {
items[i].move( gg, ElementPlacement.PLACEATBEGINNING );
}
}
}

return gg;
}




// ----------------------------------------------------------------------------------------------------------------------------------------

dlg.btn.addEventListener ('click', startSpec );
dlg.show();
上传的图像
文件类型: png QQ图片20181024155101.png (25.9 KB, 2 次查看)
rym 当前离线  
旧 2018-10-25, 02:42   只看该作者   #2
luck2004 luck2004 当前离线
正式会员
等级: 六袋长老
级别:110 | 在线时长:12715小时 | 升级还需:50小时级别:110 | 在线时长:12715小时 | 升级还需:50小时级别:110 | 在线时长:12715小时 | 升级还需:50小时级别:110 | 在线时长:12715小时 | 升级还需:50小时级别:110 | 在线时长:12715小时 | 升级还需:50小时级别:110 | 在线时长:12715小时 | 升级还需:50小时级别:110 | 在线时长:12715小时 | 升级还需:50小时级别:110 | 在线时长:12715小时 | 升级还需:50小时级别:110 | 在线时长:12715小时 | 升级还需:50小时级别:110 | 在线时长:12715小时 | 升级还需:50小时级别:110 | 在线时长:12715小时 | 升级还需:50小时
 
Uid: 1330
注册日期: 2004-12-01, 10:26
帖子: 1215
感谢: 20
88 个帖子获得 238 次感谢
现金: 199金币
资产: 419金币
声望: 11 luck2004 向着好的方向发展
luck2004 luck2004 当前离线
正式会员
等级: 六袋长老
级别:110 | 在线时长:12715小时 | 升级还需:50小时级别:110 | 在线时长:12715小时 | 升级还需:50小时级别:110 | 在线时长:12715小时 | 升级还需:50小时级别:110 | 在线时长:12715小时 | 升级还需:50小时级别:110 | 在线时长:12715小时 | 升级还需:50小时级别:110 | 在线时长:12715小时 | 升级还需:50小时级别:110 | 在线时长:12715小时 | 升级还需:50小时级别:110 | 在线时长:12715小时 | 升级还需:50小时级别:110 | 在线时长:12715小时 | 升级还需:50小时级别:110 | 在线时长:12715小时 | 升级还需:50小时级别:110 | 在线时长:12715小时 | 升级还需:50小时
 
Uid: 1330
注册日期: 2004-12-01, 10:26
帖子: 1215
感谢: 20
88 个帖子获得 238 次感谢
现金: 199金币
资产: 419金币
声望: 11 luck2004 向着好的方向发展
默认

// Create an empty dialog window near the upper left of the screen
var dlg = new Window('dialog', 'Spec');
dlg.frameLocation = [100,100];
dlg.size = [250,250];

dlg.intro = dlg.add('statictext', [20,20,150,40] );
dlg.intro.text = 'First select 1 or 2 items';

dlg.where = dlg.add('dropdownlist', [20,40,150,60] );
dlg.where.selection = dlg.where.add('item', 'top');
dlg.where.add('item', 'bottom');
dlg.where.add('item', 'left');
dlg.where.add('item', 'right');

dlg.btn = dlg.add('button', [20,70,150,90], 'Specify', 'spec');



// document
var doc = activeDocument;

// spec layer
try {
var speclayer =doc.layers['spec'];
} catch(err) {
var speclayer = doc.layers.add();
speclayer.name = 'spec';
}

// measurement line color
var color = new RGBColor;
color.red = 255;
color.green = 0;
color.blue = 0;

// gap between measurement lines and object
var gap = 2;

// size of measurement lines.
var size = 10;

// number of decimal places
var decimals = 0;

// pixels per inch
var dpi = 72;

/**
Start the spec
*/
function startSpec() {

if (doc.selection.length==1) {
specSingle( doc.selection[0].geometricBounds, dlg.where.selection.text );
} else if (doc.selection.length==2) {
specDouble( doc.selection[0], doc.selection[1], dlg.where.selection.text );
} else {
alert('please select 1 or 2 items');
}

dlg.close ();
}




/**
Spec the gap between 2 elements
*/
function specDouble( item1, item2, where ) {

var bound = new Array(0,0,0,0);

var a = item1.geometricBounds;
var b = item2.geometricBounds;

if (where=='top' || where=='bottom') {

if (b[0]>a[0]) { // item 2 on right,

if (b[0]>a[2]) { // no overlap
bound[0] =a[2];
bound[2] = b[0];
} else { // overlap
bound[0] =b[0];
bound[2] = a[2];
}
} else if (a[0]>=b[0]){ // item 1 on right

if (a[0]>b[2]) { // no overlap
bound[0] =b[2];
bound[2] = a[0];
} else { // overlap
bound[0] =a[0];
bound[2] = b[2];
}
}

bound[1] = Math.max (a[1], b[1]);
bound[3] = Math.min (a[3], b[3]);

} else {

if (b[3]>a[3]) { // item 2 on top
if (b[3]>a[1]) { // no overlap
bound[3] =a[1];
bound[1] = b[3];
} else { // overlap
bound[3] =b[3];
bound[1] = a[1];
}
} else if (a[3]>=b[3]){ // item 1 on top

if (a[3]>b[1]) { // no overlap
bound[3] =b[1];
bound[1] = a[3];
} else { // overlap
bound[3] =a[3];
bound[1] = b[1];
}
}

bound[0] = Math.min(a[0], b[0]);
bound[2] = Math.max (a[2], b[2]);
}
specSingle(bound, where );
}


/**
spec a single object
[MENTION=343005]para[/MENTION] m bound item.geometricBound
[MENTION=343005]para[/MENTION] m where 'left,' 'top', 'bottom', 'right'
*/
function specSingle( bound, where ) {


// width and height
var w = bound[2]-bound[0];
var h = bound[1]-bound[3];

// a & b are the horizontal or vertical positions that change
// c is the horizontal or vertical position that doesn't change
var a = bound[0];
var b = bound[2];
var c = bound[1];

// xy='x' (horizontal measurement), xy='y' (vertical measurement)
var xy = 'x';

// a direction flag for placing the measurement lines.
var dir = 1;

switch( where ) {

case 'top':
a = bound[0];
b = bound[2];
c = bound[1];
xy = 'x';
dir = 1;
break;

case 'bottom':
a = bound[0];
b = bound[2];
c = bound[3];
xy = 'x';
dir = -1;
break;

case 'left':
a = bound[1];
b = bound[3];
c = bound[0];
xy = 'y';
dir = -1;
break;

case 'right':
a = bound[1];
b = bound[3];
c = bound[2];
xy = 'y';
dir = 1;
break;

}

// create the measurement lines
var lines = new Array();

// horizontal measurement
if (xy=='x') {

// 2 vertical lines
lines[0]= new Array( new Array(a, c+(gap)*dir) );
lines[0].push ( new Array(a, c+(gap+size)*dir) );
lines[1]= new Array( new Array(b, c+(gap)*dir) );
lines[1].push( new Array(b, c+(gap+size)*dir) );

// 1 horizontal line
lines[2]= new Array( new Array(a, c+(gap+size/2)*dir ) );
lines[2].push( new Array(b, c+(gap+size/2)*dir ) );

// create text label
if (where=='top') {
var t = specLabel( w, (a+b)/2, lines[0][1][1] );
t.top += t.height;
} else {
var t = specLabel( w, (a+b)/2, lines[0][0][1] );
t.top -= t.height;
}
t.left -= t.width/2;

// vertical measurement
} else {

// 2 horizontal lines
lines[0]= new Array( new Array( c+(gap)*dir, a) );
lines[0].push ( new Array( c+(gap+size)*dir, a) );
lines[1]= new Array( new Array( c+(gap)*dir, b) );
lines[1].push( new Array( c+(gap+size)*dir, b) );

//1 vertical line
lines[2]= new Array( new Array(c+(gap+size/2)*dir, a) );
lines[2].push( new Array(c+(gap+size/2)*dir, b) );

// create text label
if (where=='left') {
var t = specLabel( h, lines[0][1][0], (a+b)/2 );
t.left -= t.width;
} else {
var t = specLabel( h, lines[0][0][0], (a+b)/2 );
t.left += size;
}
t.top += t.height/2;
}

// draw the lines
var specgroup = new Array(t);

for (var i=0; i<lines.length; i++) {
var p = doc.pathItems.add();
p.setEntirePath ( lines[i] );
setLineStyle( p, color );
specgroup.push( p );
}

group(speclayer, specgroup );

}


/**
Create a text label that specify the dimension
*/
function specLabel( val, x, y) {

var t = doc.textFrames.add();
t.textRange.characterAttributes.size = 12;
t.textRange.characterAttributes.alignment = StyleRunAlignmentType.center;
t.textRange.characterAttributes.fillColor = color
var v = val;
switch (doc.rulerUnits) {
case RulerUnits.Inches:
v = val/dpi;
v = v.toFixed (decimals)+'in.';
break;

case RulerUnits.Centimeters:
v = val/(dpi/2.54);
v = v.toFixed (decimals)+"cm";
break;

case RulerUnits.Millimeters:
v = val/(dpi/25.4);
v = v.toFixed (decimals)+"mm";
break;

case RulerUnits.Picas:
v = val/(dpi/6);
var vd = v - Math.floor (v);
vd = 12*vd;
v = Math.floor(v)+'p'+vd.toFixed (decimals) ;
break;

default:
v = v.toFixed (decimals) +"pt";
}

t.contents = v;
t.top = y;
t.left = x;

return t;

}

function setLineStyle(path, color) {
path.filled = false;
path.stroked = true;
path.strokeColor = color;
path.strokeWidth = 0.5;

return path;
}


/**
* Group items in a layer
*/
function group( layer, items, isDuplicate) {

// create new group
var gg = layer.groupItems.add();

// add to group
// reverse count, because items length is reduced as items are moved to new group
for(var i=items.length-1; i>=0; i--) {

if (items[i]!=gg) { // don't group the group itself
if (isDuplicate) {
newItem = items[i].duplicate (gg, ElementPlacement.PLACEATBEGINNING);
} else {
items[i].move( gg, ElementPlacement.PLACEATBEGINNING );
}
}
}

return gg;
}




// ----------------------------------------------------------------------------------------------------------------------------------------

dlg.btn.addEventListener ('click', startSpec );
dlg.show();
luck2004 当前离线  
旧 2018-11-01, 08:55   只看该作者   #3
牛XX 的头像
牛XX 牛XX 当前离线
正式会员
等级: 四袋长老
级别:37 | 在线时长:1595小时 | 升级还需:1小时级别:37 | 在线时长:1595小时 | 升级还需:1小时级别:37 | 在线时长:1595小时 | 升级还需:1小时级别:37 | 在线时长:1595小时 | 升级还需:1小时
 
Uid: 456309
注册日期: 2015-05-04, 20:15
来自: QQ 1739441407
帖子: 201
感谢: 16
15 个帖子获得 35 次感谢
现金: 2252金币
资产: 2252金币
声望: 11 牛XX 向着好的方向发展
牛XX 牛XX 当前离线
正式会员
等级: 四袋长老
级别:37 | 在线时长:1595小时 | 升级还需:1小时级别:37 | 在线时长:1595小时 | 升级还需:1小时级别:37 | 在线时长:1595小时 | 升级还需:1小时级别:37 | 在线时长:1595小时 | 升级还需:1小时
牛XX 的头像
 
Uid: 456309
注册日期: 2015-05-04, 20:15
来自: QQ 1739441407
帖子: 201
感谢: 16
15 个帖子获得 35 次感谢
现金: 2252金币
资产: 2252金币
声望: 11 牛XX 向着好的方向发展
默认

标的好像不够精确啊。要不要来个小数点后面搞两位
牛XX 当前离线  
旧 2018-11-01, 10:06   只看该作者   #4
QQ33161288 的头像
QQ33161288 QQ33161288 当前离线
论坛版主
等级: 九袋长老
级别:220 | 在线时长:49563小时 | 升级还需:162小时级别:220 | 在线时长:49563小时 | 升级还需:162小时级别:220 | 在线时长:49563小时 | 升级还需:162小时级别:220 | 在线时长:49563小时 | 升级还需:162小时级别:220 | 在线时长:49563小时 | 升级还需:162小时级别:220 | 在线时长:49563小时 | 升级还需:162小时级别:220 | 在线时长:49563小时 | 升级还需:162小时级别:220 | 在线时长:49563小时 | 升级还需:162小时级别:220 | 在线时长:49563小时 | 升级还需:162小时级别:220 | 在线时长:49563小时 | 升级还需:162小时
 
Uid: 20342
注册日期: 2006-08-08, 09:54
帖子: 13294
感谢: 3439
1412 个帖子获得 2985 次感谢
精华: 10
现金: 283金币
资产: 6952金币
声望: 20 QQ33161288 向着好的方向发展
QQ33161288 QQ33161288 当前离线
论坛版主
等级: 九袋长老
级别:220 | 在线时长:49563小时 | 升级还需:162小时级别:220 | 在线时长:49563小时 | 升级还需:162小时级别:220 | 在线时长:49563小时 | 升级还需:162小时级别:220 | 在线时长:49563小时 | 升级还需:162小时级别:220 | 在线时长:49563小时 | 升级还需:162小时级别:220 | 在线时长:49563小时 | 升级还需:162小时级别:220 | 在线时长:49563小时 | 升级还需:162小时级别:220 | 在线时长:49563小时 | 升级还需:162小时级别:220 | 在线时长:49563小时 | 升级还需:162小时级别:220 | 在线时长:49563小时 | 升级还需:162小时
QQ33161288 的头像
 
Uid: 20342
注册日期: 2006-08-08, 09:54
帖子: 13294
感谢: 3439
1412 个帖子获得 2985 次感谢
精华: 10
现金: 283金币
资产: 6952金币
声望: 20 QQ33161288 向着好的方向发展
默认

这个不好用,只能选择两个物件,多一个都不行
__________________
印前(软件)教学
印前(流程)教学
印前(色彩)教学
印能捷&印能捷EVO、HQRIP和海德堡Prinect,esko流程、GMG & CGS & EFI数码打样类软件,印能捷数据库修复,超强专业印前系统!
更多介绍 http://33161288.lofter.com/
出售金币(100RMB=160金币,最低100起售,量大从优)
印前脚本及插件订制 联系[QQ:33161288]

-----------------------------------------------------------
承接:文件制作,文件修改,文件拼版,输出最终1 bit tiff
QQ33161288 当前离线  
发表新主题 关闭主题


发帖规则
不可以发表主题
不可以回复帖子
不可以上传附件
不可以编辑自己的帖子

论坛启用 vB 代码
论坛启用 表情图标
论坛启用 [IMG] 代码
论坛禁用 HTML 代码


律师声明:本站内容,均具有版权,未经书面授权,禁止转载,严禁镜像,违者承担一切后果!
论坛广告报价   广告联系及办理企业会员服务QQ:57880388 站务管理QQ:35529388


所有时间均为 +8, 现在的时间是 2025-01-04 15:25.

Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions, Inc.
 
Copyright © 2004-2022