Selection Unit Problem

Upload Photoshop Scripts, download Photoshop Scripts, Discussion and Support of Photoshop Scripts

Moderators: Tom, Kukurykus

i2ib4sunshine

Selection Unit Problem

Post by i2ib4sunshine »

Hello to all!
I am new to this forum and to have a simple Problem.
sorry for my bad english

i want select picture as a unit other than Pixel, but i can't

my code is :

var docRef = app.activeDocument;

app.preferences.rulerUnits = Units.CM;
app.preferences.Units = Units.CM;

var x = docRef.height ;
var x = new UnitValue( docRef.height,'CM');

docRef.selection.select(new Array (new Array(0,0),new Array(50,0), new Array(50,x), new Array(0,x)),
SelectionType.REPLACE, 0.0, false);

x value & type is CM But Selection is base of Pixel values
what is wrong !
xbytor

Selection Unit Problem

Post by xbytor »

Some/most APIs require pixels. You will have to do the unit conversions yourself in this case.
Mike Hale

Selection Unit Problem

Post by Mike Hale »

Yes unitValues don't work everywhere. Selection still expects Number as pixels. You could do something like this if you want to work with cm.

Code: Select allvar docRef = app.activeDocument;

app.preferences.rulerUnits = Units.CM;
app.preferences.Units = Units.CM;

var x = docRef.height ;// already a unitValue
var zero = new UnitValue( 0,'CM');
var fifty = new UnitValue(50,'cm');

docRef.selection.select([[zero.as('px'),zero.as('px')],[fifty.as('px'),zero], [fifty.as('px'),x.as('px')], [zero,x.as('px')]],SelectionType.REPLACE, 0.0, false);
i2ib4sunshine

Selection Unit Problem

Post by i2ib4sunshine »

So Tanx, it Work !