Copy current photoshop layer 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:

&layer_name.x = &layer_x;
&layer_name.y = &layer_y;
// &layer_name.width = &layer_width;
// &layer_name.height = &layer_height;


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

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.