通过 JXA 在 Adob​​e Illustrator 中创建一个新的路径项(JavaScript 用于自动化)

Create a new path item in Adobe Illustrator via JXA (JavaScript for Automation)

我正在寻找一种使用 JXA(JavaScript 用于自动化)在 Adob​​e Illustrator 中创建路径项的方法。我在整个互联网上搜索了好几次都找不到任何东西......Apple Developer Site 上只有一个非常基本的 JXA 介绍:JavaScript for Automation Release Notes (10.10) Adobe 根本不涉及这个主题。 这是我的代码,我在其中尝试向现有文档添加椭圆:

illuApp = Application('Illustrator')
docPath = "/Users/userOne/Desktop/Document_One.ai"
illuApp.open(docPath)

currentDoc = illuApp.currentDocument
console.log(currentDoc.name())

// Ellipse constructor
newEllipse = illuApp.Ellipse({left: 512.5, top: 87.5, width: 425.0, height: 75.0, reversed: false, inscribed: true})

// This doesn't work **(Error -1700: Can't convert types.)**
currentDoc.pathItems.push(newEllipse)

任何帮助将不胜感激,谢谢! :)

不要浪费你的时间。就像之前的 ScriptingBridge 一样,JXA 不能正常工作:它会做一些简单的事情到一定程度……然后它就会让你崩溃;在这一点上你搞砸了。 Apple 从来没有为狗屎记录或支持它,而且它甚至未能建立 AS 拥有的一小部分观众,所以我不会感到惊讶,它首先出现在热门列表中 if/when Apple 推出了他们修改后的自动化战略。 (最后一位自动化项目经理被解雇是有原因的。我敢说 6 月 9 日之后我们会有更好的主意。)

如果您想使用 JavaScript 自动化 AI,请使用其内置的 JavaScript (JSX) 解释器。否则请坚持使用 AppleScript,它是唯一官方支持 知道如何正确说出 Apple 事件的选项†。这在编写重要脚本时尤为重要,因为在自动化大型、复杂、老化的可编写脚本的应用程序(如 Illustrator)时,steam/break 中较差的 AE 桥很可能 运行 出现兼容性错误,Excel , FileMaker 等


† 还有 py-appscript/SwiftAutomation,(这是我在自己的高端 Illustrator 自动化中使用的,并且也全面地踢了 AppleScript 的屁股),但经过多年 Apple 的胡闹,我不再推荐或为它提供支持,这样你就可以靠自己了。