首页 > 编程语言 >Illustrator JavaScript 出血

Illustrator JavaScript 出血

时间:2023-02-01 12:04:17浏览次数:39  
标签:index abBounds Illustrator top JavaScript 出血 shape var left


Illustrator JavaScript 出血

var doc = app.activeDocument;
var pt = 72/25.4;
var rc = 1*pt;
var ls = 6*pt;
for(var i =0;i<doc.selection.length;i++){

var shape = doc.selection[i];
var art = Artboard();

var left = isRC(art.left,shape.left,rc,'left');
var bottom = isRC(art.bottom,shape.top-shape.height,rc,'bottom');
var right = isRC(art.right,shape.left+shape.width,rc,'right');
var top = isRC(art.top,shape.top,rc,'top');

if(left){
shape.width = shape.width+ls;
shape.left =shape.left -ls;
}
if(right){
shape.width = shape.width+ls;
}
if(bottom){
shape.height = shape.height+ls;
}
if(top){
shape.height = shape.height+ls;
shape.top =shape.top +ls;
}
}

function isRC(a,b,rc,index){
if(index=='left')return a>b||Math.abs(a-b)<=rc;
if(index=='top')return a<b||Math.abs(a-b)<=rc;
if(index=='right')return a<b||Math.abs(a-b)<=rc;
if(index=='bottom')return a>b||Math.abs(a-b)<=rc;
return Math.abs(a-b)<=rc;
}


function Artboard(index) {
var doc = app.activeDocument;
/**
* index 下标 (非必填 默认当前画板)
* 画板类用于获取画板的属性
* 宽度,高度,坐标(上下左右垂直中,水平中),简单的信息
*
* 例子
* artboard = Artboard()
* artboard = Artboard(0)
* 打印信息
* alert(artboard.info)
*/
index = index == undefined ? doc.artboards.getActiveArtboardIndex() : index
var abBounds = doc.artboards[index].artboardRect;
this.width = abBounds[2] - abBounds[0];
this.height = abBounds[1] - abBounds[3];
this.left = abBounds[0];
this.top = abBounds[1];
this.bottom = abBounds[3];
this.right = abBounds[2];
this.centerX = this.left + this.width / 2;
this.centerY = this.bottom + this.height / 2;
this.artboard = doc.artboards[index];
this.abBounds = abBounds;
this.index = index;
this.info = '当前是第' + index + '个页面\n页面尺寸为' + this.width / pt + 'x' + this.height / pt + ' mm'
return this;
}


标签:index,abBounds,Illustrator,top,JavaScript,出血,shape,var,left
From: https://blog.51cto.com/u_10780206/6031176

相关文章

  • JavaScript奇技淫巧:操控URL
    JavaScript奇技淫巧:操控URL本文展示两种不常见的JS编程技巧:实现操控浏览器窗口,更改父窗口和子窗口的URL地址。修改父窗口URL当使用window.open()打开一个窗口,可以用window.......
  • 面试官:你说说 JavaScript 中类型的转换机制
    前言面试官:“你说说JavaScript中类型的转换机制”紧张的萌新:“字符串跟其他类型拼接会变成字符串...”面试官:“...”······大家好,我是CoderBin。又来到了面试官......
  • JavaScript 中更安全的 URL 读写
    前言URL对于我们开发人员来讲,应该是非常熟悉了。在对URL进行参数拼接时,我们一般都会直接进行字符串拼接或使用模版字符串,因为这样非常方便,但是我们这样其实会在不知不觉中......
  • JavaScript学习笔记—DOM:事件
    事件(event)事件就是用户和页面之间发生的交互行为比如:点击按钮,鼠标移动,双击按钮,敲击键盘,松开按键...可以通过为事件绑定响应函数(回调函数),来完成和用户之间的交互绑定响......
  • JavaScript之void
    void是什么void是JavaScript重要的关键字,该操作符指定要计算一个表达式但不返回。语法格式:voidfunc()javascript:voidfunc()或void(func())javascript:void(func......
  • JavaScript学习笔记—DOM:属性节点
    属性也是一个节点对象(Attr),和文本一样,通常我们不会去直接获取节点对象,而是通过元素来完成对属性的操作:方式一:读取:元素.属性名(注意,class属性需要使用className来读取)读......
  • 关于IDEA运行时报内存溢出FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - Jav
    IDEA运行时,经常会碰到内存溢出问题:FATALERROR:CALL_AND_RETRY_LASTAllocationfailed-JavaScriptheapoutofmemory,非常讨厌,浪费时间,现记录解决方案如下:1、全......
  • javascript:js 读写 style属性(DOM模型)
    javascript:js读写style属性(DOM模型)    一、说明: 1、js读取style属性,需要去掉css格式中的“-”,“-”后面的第一个字母大写。js中的减号(“-”),与css中属性......
  • 痛恨 JavaScript 每一天(缺少指针)
    背景二叉搜索树,插入节点JavaScript解法functioninsertNode(root,newNode){if(newNode.key<root.key){if(root.left){insertNode(r......
  • JavaScript JSON
    什么是JSONJSON的作用:JSON是用于存储和传输数据的格式;JSON通常用于服务端向网页传输数据;什么是JSON:JSON全称为:JavaScriptObjectNotation是一种轻量级的数据交......