Skip to main content
photogyulai
Inspiring
May 27, 2016
Answered

How to get or set units?!

  • May 27, 2016
  • 5 replies
  • 1509 views

Hey Guys!

I have some extensions that measure the width and height...

but if the

Edit menu>> preferences >> units are in centimeter

the result of the measurement will be faaaarrr different than in pixels

like:

43 in cm

500000 in pixels...

is there any option for getting the units type or setting it permanently or temporarly?!?

I found this one but it didnt do anything:

app.scriptPreference.measurementUnit = app.MeasurementUnits.PIXELS;

any help would be appreciated!!

Thanks!!

Ben

This topic has been closed for replies.
Correct answer Chuck Uebele

app.preferences.rulerUnits = Units.PIXELS;//sets the units to pixels

var whatUnits = app.preferences.rulerUnits;//gets whatever the current units are.

5 replies

photogyulai
Inspiring
May 28, 2016

okay one ore question!!!

how do you get info like this ?!? :-)

i tried to search in the js reference guide ... but didnt find anything...

"we simply know" is not an answer!!! :-D

Chuck Uebele
Community Expert
Community Expert
May 28, 2016

Info like what?

photogyulai
Inspiring
May 28, 2016

info like how do you get or set the units etc. :-)   (the purpose is>> if you can point to a source, method... my life would be easier :-)

(as i see. Many things that You know here, not represent in the script ref guides (i have more than one)
Just wondering where/how do You know than! ?

photogyulai
Inspiring
May 27, 2016

Dominique, Chuck, Xbytor2 Many thanks... after this it was a piece of cake!

Ben

Participating Frequently
May 27, 2016

Bonjour

Try this :

#target photoshop

var startRulerUnits = app.preferences.rulerUnits
var startTypeUnits = app.preferences.typeUnits
var startDisplayDialogs = app.displayDialogs
app.preferences.rulerUnits = Units.PIXELS
app.preferences.typeUnits = TypeUnits.PIXELS

//Passage en mm
app.preferences.typeUnits = TypeUnits.MM //MM et non CM
app.preferences.rulerUnits = Units.CM //ou MM
app.displayDialogs = DialogModes.NO

alert( app.activeDocument.width )

//Retour aux reglages d origine
app.preferences.rulerUnits = startRulerUnits
app.preferences.typeUnits = startTypeUnits

Chuck Uebele
Community Expert
Chuck UebeleCommunity ExpertCorrect answer
Community Expert
May 27, 2016

app.preferences.rulerUnits = Units.PIXELS;//sets the units to pixels

var whatUnits = app.preferences.rulerUnits;//gets whatever the current units are.

Inspiring
May 27, 2016

app.preferences.rulerUnits

photogyulai
Inspiring
May 27, 2016

Thanks Xbytor2!

Could You please provide some additional info >> this code is get or set?!?

how to set to pixel or how to get it into a variable or smthg..

please add 1-2 example. many thanks!

Ben