Copy link to clipboard
Copied
How do I use script or code to modify the display units in the current document in Illustrator? My current units are millimeters (or centimeters) but I want to change it to pixels using a script because I have other scripts running in an environment that require fixed units to be pixels. I need to have the document environment in pixels before running it. I checked a lot of information but couldn't find a solution, is there a way to use code completion?
Copy link to clipboard
Copied
That is: "Edit" > "Preferences" > "Units" > "Pixels", the display unit here
Copy link to clipboard
Copied
I achieved it by opening that menu and keystroke manipulation by AppleScript; for Windows, AutoHotkey is available.
Copy link to clipboard
Copied
Sorry, I'm not very familiar with script code. My code is all from ChatGPT. Can this function be accomplished with javascript? Because I need to insert this function into my own script
Copy link to clipboard
Copied
If JavaScript means ExtendScript, it can only be realized halfway. Changing the units of a document that is already open does not apply to the Illustrator UI.
For a perfect solution, use AppleScript/JXA/AutoHotkey, etc.
Copy link to clipboard
Copied
If you have Windows OS (PC), you can add a piece of VisualBasic code to the JS script that will simulate a keystroke to change the units in the document setup to pixels.
Copy link to clipboard
Copied
Sorry, can VisualBasic code be inserted directly into my JavaScript script code? Because I'm not very familiar with these
Copy link to clipboard
Copied
On PC it is possible to create a VBS file and run it while the JS script is running. For Mac OS, this solution does not work.