I'm looking for a way to create path items in Adobe Illustrator using JXA (JavaScript for Automation). I googled the whole internet several times and couldn't find anything... There is only a very basic introduction of JXA on the Apple Developer Site: JavaScript for Automation Release Notes (10.10) Adobe doesn't cover this subject at all. Here is my code, where I tried to add an ellipse to an existing document:
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)
Any help would be appreciated, thanks! :)
Don't waste your time. Like ScriptingBridge before it, JXA doesn't work right: it'll do simple stuff up to a point…then it craps out on you; at which point you're screwed. Apple have never documented or supported it for shit, and it's failed to build even a fraction of the audience that AS has, so I wouldn't be surprised it it's first on the hit list if/when Apple roll out their revised automation strategy. (There's a reason the last Automation Project Manager got fired. I daresay we'll have a better idea after June 9th.)
If you want to automate AI using JavaScript, use its built-in JavaScript (JSX) interpreter. Otherwise stick to AppleScript it's the only officially supported option that knows how to speak Apple events right†. This is especially important when writing non-trivial scripts, as poorer AE bridges are most likely run out of steam/break on compatibility bugs when automating large, complex, aged scriptable apps like Illustrator, Excel, FileMaker, etc.
† There is also py-appscript/SwiftAutomation, (which is what I use for my own high-end Illustrator automation, and comprehensively kicks AppleScript's ass too), but after years of Apple's screwing about I no longer recommend or provide support for it, so you would be on your own.