"NaN px" Return When Get Document Size

Anyone, especially newbies, asking for help with Photoshop Scripting and Photoshop Automation - as opposed to those contributing to discussion about an aspect of Photoshop Scripting

Moderators: Tom, Kukurykus

vungocduchd
Posts: 3
Joined: Sun Jun 12, 2022 11:29 am

"NaN px" Return When Get Document Size

Post by vungocduchd »

I got the problem when trying to get width and height of active document. And change Unit to Pixel doesn't work

I just open 1 png image into photoshop then run the script. Alert width and height and got "NaN px"

Here is my simple code:

var startRulerUnits = app.preferences.rulerUnits;
app.preferences.rulerUnits = Units.PIXELS;

try{
var doc = app.activeDocument;
var currentWidth = doc.width;
var currentHeight = doc.height;
alert(currentWidth);
alert(currentHeight);
}catch(e){
alert(e);
}
app.preferences.rulerUnits = startRulerUnits;

I tried this script with 2 png image file: "spark_1" and "spark_1_resize"
- "spark_1": 1024x1024 px => script showing "NaN px" with it
- "spark_1_resize": 512x512 px => script works and showing "512px"

I have no idea why is that

I really appreciate with any help ❤
Thank you
Attachments
spark_1_resize.png
spark_1_resize.png (17.13 KiB) Viewed 1167 times
spark_1.png
spark_1.png (40.76 KiB) Viewed 1167 times
User avatar
Kukurykus
Posts: 528
Joined: Mon Jul 25, 2016 12:36 pm

Re: "NaN px" Return When Get Document Size

Post by Kukurykus »

Compress spark_1.png and attach to your next post, so I can run myself your script on that file.
vungocduchd
Posts: 3
Joined: Sun Jun 12, 2022 11:29 am

Re: "NaN px" Return When Get Document Size

Post by vungocduchd »

Sorry , here is the image
Attachments
spark_1.rar
(36.71 KiB) Downloaded 99 times
User avatar
Kukurykus
Posts: 528
Joined: Mon Jul 25, 2016 12:36 pm

Re: "NaN px" Return When Get Document Size

Post by Kukurykus »

I'm twice alerted by 1024 px, so I guess something changed in file when transfering, or it's something different on your side.

Maybe try on the file you uploaded to your post? I have Photoshop CS6 and CC 2022, what is yours?

The only difference is in CS6 the resolution is 72, while in CC 2022 it's 1.
vungocduchd
Posts: 3
Joined: Sun Jun 12, 2022 11:29 am

Re: "NaN px" Return When Get Document Size

Post by vungocduchd »

Hi, i just found a solution :D

These images had problem with resolution. I changed resolution from 1 to 72 Pixels/Inch

Scripts works!

Thank you ❤
User avatar
Kukurykus
Posts: 528
Joined: Mon Jul 25, 2016 12:36 pm

Re: "NaN px" Return When Get Document Size

Post by Kukurykus »

As I say the script alerted numeric values on my side, so I wonder what exact Ps version you use that you couldn't have same result?