Skip to main content
Plane Wryter
Known Participant
November 4, 2021
Answered

What is Illustrator's Internal Unit-of-Measure via Javascript?

  • November 4, 2021
  • 2 replies
  • 1082 views

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}.

  • What is the {something} (unit-of-measure)?

Many thanks!

 

This topic has been closed for replies.
Correct answer m1b

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

2 replies

m1b
Community Expert
m1bCommunity ExpertCorrect answer
Community Expert
November 4, 2021

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

Plane Wryter
Known Participant
November 5, 2021

@m1b: AWESOME response. Had no idea there was a app.activeDocument.scaleFactor property.

Your help is appreciated!

m1b
Community Expert
Community Expert
November 5, 2021

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).

CarlosCanto
Community Expert
Community Expert
November 4, 2021

measurements reported through javascript are always in Points

Plane Wryter
Known Participant
November 4, 2021

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")?

  • The images Placed in my Illustrator file are 5" by 5".

Yet the code snippet below states both itemWidth and itemHeight as 36 (see, screenshot below).

  • Something else must be going on with respect to the way Illustrator manages and reports on dimensional units-of-measure.

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)
    }
}

 

 

 

jduncan
Community Expert
Community Expert
November 4, 2021

1/72 = 0.0138888888888889