Skip to content

Instantly share code, notes, and snippets.

@Scrxtchy
Created May 24, 2016 12:21
Show Gist options
  • Save Scrxtchy/9df9c9ad16b1aace9a16702fc9b427c7 to your computer and use it in GitHub Desktop.
Save Scrxtchy/9df9c9ad16b1aace9a16702fc9b427c7 to your computer and use it in GitHub Desktop.
Photoshop region to percentageOfOne as float
str = activeDocument.selection.bounds.toString();
str = str.replace(/ px/g,""); //" px"要らないので削除
array = str.split(","); //","で分割
var w = app.activeDocument.width.toString().replace(' px', '');
var h = app.activeDocument.height.toString().replace(' px', '');
str = parseFloat(array[0] /w) + "f," + // x
parseFloat(array[1] /h) + "f," + // y
parseFloat((Number(array[2]) ).toString() /w)+ "f," + //width
parseFloat((Number(array[3]) ).toString() /h)+ "f"; //height
//クリップボードに送る処理
var txd=app.charIDToTypeID('TxtD');
var kttc = app.stringIDToTypeID( "textToClipboard" );
var ad = new ActionDescriptor();
ad.putString(txd,str);
// http://crosseaglet.blogspot.com/2015/02/photoshoprect.html
executeAction( kttc, ad, DialogModes.NO );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment