Selection Unit Problem

Upload photoshop scripts, download photoshop scripts, discussion and support of photoshop scripts

Moderator: PS-Moderators

Selection Unit Problem

Postby i2ib4sunshine » Tue Mar 01, 2011 6:05 pm

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 !
i2ib4sunshine
 
Posts: 2
Joined: Tue Mar 01, 2011 8:15 am

Re: Selection Unit Problem

Postby xbytor » Tue Mar 01, 2011 6:23 pm

Some/most APIs require pixels. You will have to do the unit conversions yourself in this case.
xbytor
Site Admin
 
Posts: 2277
Joined: Thu May 19, 2005 12:11 pm
Location: In Limbo

Re: Selection Unit Problem

Postby Mike Hale » Tue Mar 01, 2011 6:54 pm

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 all
var 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);
Mike Hale
Site Admin
 
Posts: 4337
Joined: Fri Sep 30, 2005 10:52 pm
Location: USA

Re: Selection Unit Problem

Postby i2ib4sunshine » Tue Mar 01, 2011 10:59 pm

So Tanx, it Work !
i2ib4sunshine
 
Posts: 2
Joined: Tue Mar 01, 2011 8:15 am

Re: Selection Unit Problem

Postby visual » Thu Dec 15, 2011 8:33 am

:D That's great help for me too indeed. As a scripting beginner, I appreciate that work!
visual
 
Posts: 5
Joined: Tue Dec 06, 2011 12:45 pm


Return to Photoshop Scripts

Who is online

Users browsing this forum: No registered users and 2 guests