Welcome Dialog

Welcome to the Community!

We have a brand new look! Take a tour with us and explore the latest updates on Adobe Support Community.


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

Community Beginner ,
Nov 04, 2021 Nov 04, 2021

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

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

Many thanks!

 

TOPICS
Scripting

Views

118

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Enthusiast , Nov 04, 2021 Nov 04, 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

Likes

Translate

Translate
Adobe Community Professional ,
Nov 04, 2021 Nov 04, 2021

Copy link to clipboard

Copied

measurements reported through javascript are always in Points

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Nov 04, 2021 Nov 04, 2021

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

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

 

 

Illustrator-36.jpg

 

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Nov 04, 2021 Nov 04, 2021

Copy link to clipboard

Copied

1/72 = 0.0138888888888889

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Nov 04, 2021 Nov 04, 2021

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?

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Nov 04, 2021 Nov 04, 2021

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

 

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Nov 04, 2021 Nov 04, 2021

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

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Nov 04, 2021 Nov 04, 2021

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

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Nov 04, 2021 Nov 04, 2021

Copy link to clipboard

Copied

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

Your help is appreciated!

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Nov 05, 2021 Nov 05, 2021

Copy link to clipboard

Copied

LATEST

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

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines