如何获取所选 Illustrator PathItem 的位置(以像素为单位)?
我有一个简单的问题,但似乎无法找到解决方法: 我有 PathItem,Illustrator 指出它位于 (781px,250px) 位置。
如何在 jsx 中获取这些值?
我注意到 PathItem 继承了 PageItem 的position属性,并且position 是一个点,但是当我尝试打印这些值时,我得到未定义:
$.writeln(app.activeDocument.selection[0].position.x);
如果我从上面的行中省略 .x,我会在控制台中打印:
521,510
什么这些是值吗?它们是 x,y 坐标吗?在什么单位?如何转换为像素?
为什么我无法访问 x,y/top,left 属性?
我正在使用 Illustrator CS5。
I have a simple problem, but can't seem to find my way around it:
I have PathItem and Illustrator points out that it is at position (781px,250px).
How can I get those values in jsx ?
I've noticed that the PathItem inherits the position property from PageItem, and position
is a Point, but when I try to print the values, I get undefined:
$.writeln(app.activeDocument.selection[0].position.x);
If I leave out .x from the line above I get this printed in the console:
521,510
What are these values ? Are they x,y coordinates ? In what unit ? How can I convert to pixels ?
Why can I not access x,y/top,left properties ?
I'm using Illustrator CS5.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
@bradido 的答案很有帮助,但不完整。
Illustrator 似乎有不同的坐标系:一个是整体文档坐标系,另一个是基于当前活动画板的坐标系(您可能定义了多个,但一次只有一个是“活动”的。)其中一个坐标系的原点位于画板的中心文档,而另一个文档的原点位于左上角。而且它的 Y 值向上增加。
明智的做法是首先使用
app.cooperativeSystem
属性检查坐标系,如果需要,可以使用一个转换函数 (doc.convertCooperative
) 来处理从中心。下面的代码片段演示了如何在 Illustrator 中检索符号的 x,y 值,稍后可以在 ActionScript 中使用该值(使用坐标系转换):
有关更多详细信息,请参阅此 Adobe 论坛上的帖子。
@bradido's answer is helpful, it is incomplete.
It seems Illustrator has different coordinate systems: an overall document coordinate system and a second based on the currently-active artboard (you may have several defined but only one is 'active' at a time.) One has the origin at the centre of the document while the other has the origin at top-left. Also it's Y values increase upwards.
It is wise to first check for the coordinate system using the
app.coordinateSystem
property, and if needed, there is a conversion function (doc.convertCoordinate
) which handles the offset from the centre.Here's an snippet which demonstrates how to retrieve x,y values for symbols in Illustrator, which can later be used in actionscript (using the coordinate system conversion):
For more details, see this thread on the Adobe Forums.
Point 是位置数组。所以要获取坐标:
The Point is an array of the positions. So to get the coordinates:
上面的示例很好,但适用于非常具体的任务。这是一个函数,它将执行正确的坐标转换并返回中心:
您必须传递 ITEM 而不是点。而且我必须发泄:需要这样做并不是一个好主意。
The example above is good but is for a very specific task. Here is a function that will do the correct coordinate conversion and return the center:
You must pass the ITEM not the point. And I must vent: the need to do this is not a good idea.