有没有办法在Adobe Illustrator中对对象进行限制?
我要将多个对象放置到一个POI中。对象本身应始终查看POI。此外,当POI移动时,应更新对象的方向。
有没有办法在Adobe Illustrator中定义这种类型的逻辑?
谢谢你的帮忙!1月
发布于 2013-04-11 21:55:35
你可以写一个脚本来做这件事。
一个问题是如何确定哪个对象是正确的。
一个简单的解决方案是使用命名约定:假设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;
}您可以将其另存为类似于在正确位置查看POI.jsx (ILLUSTRATOR_INSTALL_DIR/Presets/LOCALE/Scripts)的内容,以便可以通过文件>脚本>查看POI.jsx进行访问
要使用它,请选择至少2个对象,确保其中一个名称中包含POI。
这里有一个快速预览:

请注意,三角形是符号。这使得在需要调整时可以轻松地全局调整旋转(如您在“符号”面板中看到的那样)。另一种方法是向脚本中的角度添加偏移量,但这感觉足够灵活:)
非脚本版本可能会使用符号微调工具,但这是一个缓慢且不太精确的过程:

https://stackoverflow.com/questions/15942916
复制相似问题