2013-04-11 94 views
1

有没有在Adobe Illustrator中对对象设置限制的方法?在Adobe Illustrator中设置约束条件

我想将多个对象放置到一个兴趣点。对象本身应该总是看着POI。另外,当POI移动时,对象的方向应该更新。

有没有办法在Adobe Illustrator中定义这种类型的逻辑?

感谢您的帮助! Jan

回答

1

你可以写一个脚本来做到这一点。

一个问题是如何确定哪些对象是正确的。

作为一个快速的黑客解决方案是使用命名约定:假设POI对象在其名称中包含字符“POI”。

一旦你得到的POI对象,它只是一个使用ATAN2得到的事情的,从每一个其他对象的POI:

var dx = POI.x - obj.x; 
var dy = POI.y - obj.y; 
var angle = atan2(dy,dx); 

下面是一个简单的脚本:

/* 
*  Rotates a bunch of selected items towards a chosen target 
*  
*  Usage: select at least 2 objects and mark the "look at" target by having POI in the name of the item 
*/ 
#target illustrator 

var d = app.activeDocument;//current document 
var s = d.selection;//current selection 
var hasDocCoords = app.coordinateSystem == CoordinateSystem.DOCUMENTCOORDINATESYSTEM; 

var poi = getPOI(s);//get an object that contains 'poi'/'POI' in the name 
if(s.length > 1 && poi != undefined){//if there are at least 2 objects and one's a POI 
    var lookAt = getPos(poi);//get the position to look at 
    for(var i = 0 ; i < s.length; i++){//for each object 
     if(s[i] != poi){//that isn't the poi 
      var pos = getPos(s[i]);//get the position 
      //get the angle using atan2 and the difference vector between the two positions(current object and poi) 
      var angle = Math.atan2(pos[1]-lookAt[1],pos[0]-lookAt[0]); 
      //check if there's a rotation applied, if so, remove it first 
      if(s[i].tags.length > 0){ 
       if(s[i].tags[0].name == "BBAccumRotation"){ 
        s[i].rotate(s[i].tags[0].value* -57.2957795);//reverse rotate 
        s[i].tags[0].remove(); 
       } 
      } 
      //if it doesn't have a rotation tag, add one so it can be removed when the script is reapplied 
      if(s[i].tags.length == 0){ 
       var t = s[i].tags.add(); 
       t.name = "BBAccumRotation"; 
       t.value = angle; 
      } 
      s[i].rotate(angle * 57.2957795);//finally convert radians to degrees and apply the rotation 
     } 
    } 
    app.redraw(); 
} 
function getPOI(s){//find POI in selection 
    for(var i = 0 ; i < s.length; i++) 
     if (s[i].name.toUpperCase().indexOf("POI") >= 0) return s[i]; 
} 
function getPos(o){ 
    var pos = hasDocCoords ? d.convertCoordinate (o.position, CoordinateSystem.DOCUMENTCOORDINATESYSTEM, CoordinateSystem.ARTBOARDCOORDINATESYSTEM) : o.position; 
    pos[0] += o.width;//offset to centre of object 
    pos[1] -= o.height; 
    return pos; 
} 

你可以将它保存为正确位置(ILLUSTRATOR_INSTALL_DIR/Presets/LOCALE/Scripts)中的POI.jsx文件,以便通过访问文件>脚本>查看POI

要使用它,请至少选择2个对象,确保名称中包含POI

这里有一个快速预览: Illustrator preview

注意,三角形的符号。如果需要调整,可以很容易地调整旋转(如您在符号面板中看到的那样)。另一种方法是加一个偏移量在剧本的角度,但这种感觉不够灵活:)

非脚本版本可能使用符号旋转工具,但它是一个缓慢的,不是很精确的过程:

symbol spinner tool