CS2 bug?

Discussion of Photoshop Scripting, Photoshop Actions and Photoshop Automation in General

Moderators: Tom, Kukurykus

Mike Hale

CS2 bug?

Post by Mike Hale »

I don't understand, why would PS be unable to convert a percent to pixels? It's a simple conversion if you know the total size of the document and the resolution.
Yes it is an easy conversion but when you create a percent unitValue you set the baseUnit to whatever value is 100%. Photoshop has no way of knowing that the value used to set the baseUnit is the document's width or height.

You can also do something like this to get around the limitation.
Code: Select allvar pixValUV = UnitValue(pctVal.as("in"), "in");// set the value and unitType
pixValUV.baseUnit = UnitValue(1/app.activeDocument.resolution,'in');// set the pixel size in a distanceUnit
var pixVal = pixValUV.as("px");

Or you can work in a distanceUnit like inches and do the math without unitValues when you a percentage. i.e. (5/10)*100