首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在Adobe Illustrator中设置约束

在Adobe Illustrator中设置约束
EN

Stack Overflow用户
提问于 2013-04-11 15:23:15
回答 1查看 1.8K关注 0票数 1

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

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

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

谢谢你的帮忙!1月

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-04-11 21:55:35

你可以写一个脚本来做这件事。

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

一个简单的解决方案是使用命名约定:假设POI对象的名称中包含字符"POI“。

一旦获得了POI对象,就只需使用atan2将所有其他对象的对象转换为POI:

代码语言:javascript
复制
var dx = POI.x - obj.x;
var dy = POI.y - obj.y;
var angle = atan2(dy,dx);

下面是一个快速脚本:

代码语言:javascript
复制
/*
 *      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;  
}

您可以将其另存为类似于在正确位置查看POI.jsx (ILLUSTRATOR_INSTALL_DIR/Presets/LOCALE/Scripts)的内容,以便可以通过文件>脚本>查看POI.jsx进行访问

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

这里有一个快速预览:

请注意,三角形是符号。这使得在需要调整时可以轻松地全局调整旋转(如您在“符号”面板中看到的那样)。另一种方法是向脚本中的角度添加偏移量,但这感觉足够灵活:)

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

票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/15942916

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档