‘require’ keyword to import modules in Illustrator JavaScript ?
Hi, I’ve written a JavaScript for Adobe Illustrator to automatically add text labels to shapes. The problem is that the shapes have sometimes odd forms (like U f.e.) it’s therefore hard to find the visual center of the shapes lying inside the shape to place the text label. I found this algorithm: A new algorithm for finding a visual center of a polygon | by Mapbox | maps for developers which seems to do the job so I tried to use it in my Illustrator JavaScript. The problem is that using this algo I need to import a module called ‘tinyqueue’.
I’m not experienced in writing JavaScript. I’ve installed node.js on my Window10 PC and installed ‘tinyqueue’ module in the directory where my Illustrator script resides (npm init -y; npm install tinyqueue). This has created a package.json file locally (+ a node_modules/ directory) . Then, as a starting point, I just added the following line at top of my script:
var Queue = require('tinyqueue');When trying to execute my script in Illustrator I get the following Illustrator error message:
Error 24: require is not a function. Line: 3 -> var Queue = require('tinyqueue');I wonder if there is a problem with my package.json file? Is the ‘require’ (and f.e. ‘class’) keyword supported at all for Illustrator scripting? Do I need to add a #include line to my script to read the package.json file?
I would be grateful if someone could instruct me in solving this error!
