Copy current photoshop selection bounds to x,y,width,height to As3 code


/ Published in: ActionScript 3
Save to your folder(s)

This script allow you copy to the clipboard current layer properties in format:

&selectionBounds.x = &layerx; &selectionBounds.y = &layery; // &selectionBounds.width = &layerwidth; // &selectionBounds.height = &layerheight;


Copy this code and paste it in your HTML
  1. /*
  2. How to use:
  3.  
  4. 1) Save this script as SelectionBoundsToAS3.jsx
  5. 2) Open Photoshop
  6. 3) Select layer in PSD
  7. 4) Go to File > Scripts > Browse > Select this file (SelectionBoundsToAS3)
  8.  
  9. 5) Go to AS3 editor and press CTRL+V
  10.  
  11. You can put this script to hotkey:
  12.  
  13. 1) Go to Window > Actions
  14. 2) Create new folder in the Actions panel
  15. 3) Press Create new action
  16. 4) Put name and choice hotkey
  17. 5) Than press Record
  18. 6) Iterate once "How to use" so action will save script launching parameters
  19. 7) In the Actions panel press Stop button
  20.  
  21. Now you can automatically call this script by button :)
  22.  
  23. */
  24.  
  25. if ( app.documents.length > 0 ) {
  26.  
  27. preferences.rulerUnits = Units.PIXELS;
  28. var layerRef = app.activeDocument.selection;
  29. var layerName = "selectionBounds";
  30.  
  31. var x = layerRef.bounds[0].value;
  32. var y = layerRef.bounds[1].value;
  33. var width = layerRef.bounds[2].value - x;
  34. var height = layerRef.bounds[3].value - y;
  35.  
  36. var clp = "";
  37. clp += "\t\t" + layerName + ".x = " + x +";\r";
  38. clp += "\t\t" + layerName + ".y = " + y +";\r";
  39. clp += "\t\t// " + layerName + ".width = " + width +";\r";
  40. clp += "\t\t// " + layerName + ".height = " + height +";\r";
  41.  
  42. copyTextToClipboard(clp);
  43. } else {
  44. alert("You must have one opened document at least!");
  45. }
  46.  
  47.  
  48. function copyTextToClipboard(txt){
  49. const keyTextData = app.charIDToTypeID('TxtD');
  50. const ktextToClipboardStr = app.stringIDToTypeID( "textToClipboard" );
  51. var textStrDesc = new ActionDescriptor();
  52. textStrDesc.putString( keyTextData, txt );
  53. executeAction( ktextToClipboardStr, textStrDesc, DialogModes.NO );
  54. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.