Copy link to clipboard
Copied
With respect to writing a Javascript script for Illustrator 2022 v26.0 (macOS Monterey v12.0.1), what internal unit-of-measure does Illustrator use for images?
With File | Document Setup set to units of "Inches," Javascript reports that a 5" x 5" image is 36 {something} by 36 {something}.
Many thanks!
My guess is that your document is a large scale canvas document and therefore app.activeDocument.scaleFactor will be 10.
So your photo measuring 5" reports as 36 pts instead of 360 pts due to the scaleFactor, which is normally 1. The solution is to add a check for scaleFactor, and multiply the width and height by it.
- Mark
Copy link to clipboard
Copied
measurements reported through javascript are always in Points
Copy link to clipboard
Copied
Carlos,
Thanks for the response. From what I've read in Illustrator's docs, points are supposed to be Illustrator's internal units-of-measure.
HOWEVER, given a point is defined as 1/72" (0.1429"); how can (36 * 0.1429" be equal to 5")?
Yet the code snippet below states both itemWidth and itemHeight as 36 (see, screenshot below).
Any ideas as to how Illustrator determines that a 5" x 5" image (photo) is 36 {something} by 36 {something}?
Thanks,
Plane Wryter
for (var i = 0; i < number_of_items; i++){
currentItem = collection[i]
itemWidth = currentItem.width
itemHeight = currentItem.height
if (i < 2){
alert(itemWidth)
alert(itemHeight)
}
}
Copy link to clipboard
Copied
1/72 = 0.0138888888888889
Copy link to clipboard
Copied
Correction: A point is 1"/72, 0.01388".
Which does not change the question.
Why does Javascript report that 5" by 5" images are 36 {something} by 36 {something}?
What is the {something} unit-of-measure?
Copy link to clipboard
Copied
Sorry, I definitely typed more than that... Didn't mean to come off ass-holey... What I typed was...
"1/72 = 0.0138888888888889*36 = 0.5 so check the scale factor for your canvas"
Seems m1b answered you all ready though...
Copy link to clipboard
Copied
@jduncan: a BIG THANKS for catching my error!
(I hit the wrong keys on my calculator and--contrary to many, many prior lessons in life--failed to double-check my work!)
Copy link to clipboard
Copied
My guess is that your document is a large scale canvas document and therefore app.activeDocument.scaleFactor will be 10.
So your photo measuring 5" reports as 36 pts instead of 360 pts due to the scaleFactor, which is normally 1. The solution is to add a check for scaleFactor, and multiply the width and height by it.
- Mark
Copy link to clipboard
Copied
@m1b: AWESOME response. Had no idea there was a app.activeDocument.scaleFactor property.
Your help is appreciated!
Copy link to clipboard
Copied
Yeah, it's only been in a couple of major updates and feels a bit "tacked-on" in some ways. It only becomes an issue if you create a document that is above a certain size. Still, it's great when you want a 1:1 scale document. But... an extra thing to consider for scripts.
- Mark
P.S. I said "check for scaleFactor" but I assume it's fine to just always multiply coordinate values by scaleFactor (which won't change values unless the document is large).