在Adobe Illustrator中设置约束

时间:2013-04-11 07:23:15

标签: constraints adobe-illustrator

有没有办法在Adobe Illustrator中对对象进行限制?

我想将多个对象放到POI中。对象本身应始终查看POI。此外,当移动POI时,应更新对象的方向。

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

感谢您的帮助! 扬

1 个答案:

答案 0 :(得分:3)

您可以编写一个脚本来执行此操作。

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

快速解决方案是使用命名约定:假设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;  
}

您可以将其保存为Look At POI.jsx,位于正确的位置(ILLUSTRATOR_INSTALL_DIR/Presets/LOCALE/Scripts),以便通过文件&gt;进行访问。脚本&gt;看看POI

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

这是一个快速预览: Illustrator preview

请注意,三角形是符号。如果需要调整,这样可以轻松地全局调整旋转(如您在Symbols面板中所见)。另一种方法是在脚本中为角度添加偏移量,但这足够灵活:)

非脚本版本可能使用符号微分工具,但这是一个缓慢且不太精确的过程:

symbol spinner tool

相关问题