Advertisement
Guest User

makeCoords.jsx

a guest
Nov 14th, 2012
1,634
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /* add coords to marks */
  2.  
  3. var items = selection;
  4.  
  5. // alert('selection.lenght: ' + selection.length);
  6.  
  7. if (items.length>0) {
  8.     for (i=0; i<items.length; i++) {
  9.       var x = getX(items[i]);
  10.       var y = getY(items[i]);
  11. //  alert(i + ': x' + x + ' y' + y);
  12.       markPosition (items[i]);
  13. }
  14. } else { alert('Select objects to add coordinates!');}
  15.  
  16.  
  17. function markPosition (item) {
  18.   var x = getX(item);
  19.   var y = getY(item);
  20.  
  21.   var textRef = activeDocument.textFrames.add();
  22.   textRef.position = Array (mm2pt(x+5),mm2pt(y-5));
  23.   textRef.textRange.characterAttributes.size = 50;
  24.   textRef.contents ='x' + x + " y" + y;
  25. }
  26.  
  27.  
  28. function mm2pt (number) {
  29.   return (number*2.8346);
  30. }
  31.  
  32. function pt2mm (number) {
  33.   return (number/2.8346);
  34. }
  35.  
  36. function getX(item) {
  37.   var X = pt2mm (item.position[0]);
  38.   var W = pt2mm (item.width);
  39.   return(Math.round((X + W/2)*10)/10);
  40. }
  41.  
  42. function getY(item) {
  43.   var Y = pt2mm (item.position[1]);
  44.   var H = pt2mm (item.height);
  45.   return(Math.round((Y - H/2)*10)/10);
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement