【发布时间】:2013-04-20 09:40:52
【问题描述】:
有没有办法限制 Adobe Illustrator 中的对象?
我想将多个对象放置到一个 POI。对象本身应始终查看 POI。此外,当 POI 移动时,对象的方向也会更新。
有没有办法在 Adobe Illustrator 中定义这种类型的逻辑?
感谢您的帮助! 一月
【问题讨论】:
标签: constraints adobe-illustrator
有没有办法限制 Adobe Illustrator 中的对象?
我想将多个对象放置到一个 POI。对象本身应始终查看 POI。此外,当 POI 移动时,对象的方向也会更新。
有没有办法在 Adobe Illustrator 中定义这种类型的逻辑?
感谢您的帮助! 一月
【问题讨论】:
标签: constraints adobe-illustrator
您可以编写一个脚本来执行此操作。
一个问题是如何确定哪些对象是正确的。
一个快速的解决方案是使用命名约定:假设 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) 将其另存为 Look At POI.jsx,以便通过 File > Scripts > Look At POI
要使用它,请选择至少 2 个对象,确保其中一个对象的名称中包含 POI。
这是一个快速预览:
请注意,三角形是符号。如果需要调整,这使得全局调整旋转(如您在符号面板中看到的)变得容易。另一种方法是在脚本中为角度添加偏移量,但这感觉足够灵活:)
非脚本版本可能会使用 Symbol Spinner Tool,但这是一个缓慢且不太精确的过程:
【讨论】: