1 Reply Latest reply on Sep 19, 2014 6:49 AM by Silly-V

    How round PageItem position (and hopefully dimensions) in Illustrator using JSX ?

    orgicus Level 1

      Hi,

       

      I'm trying to put together a simple script that rounds x,y,w,h properties of each selected PageItem.

      Here are my attempts so far, just with position for now:

      Test 1:

       

      #target illustrator
      
      
      var d = app.activeDocument;
      var s = d.selection;
      
      
      if(s.length > 0){
           $.writeln("before: ",s[i].position);
          s[i].position[0] = Math.round(s[i].position[0]);
          s[i].position[1] = Math.round(s[i].position[1]);  
          $.writeln("after: ",s[i].position);
      }else alert("Please select objects first! :)");
      app.redraw();
      

       

      Test 2:

       

      #target illustrator
      
      
      var d = app.activeDocument;
      var s = d.selection;
      
      
      if(s.length > 0){
           $.writeln("before: ",s[i].position[0]);
          var x = s[i].position[0];
          var y = s[i].position[1];
          var dx = Math.round(x)-x;
          var dy = Math.round(y)-y;
          
          $.writeln(dx,",",dy);
          
          s[i].translate(-dx,-dy);
          
          $.writeln("after: ",s[i].position[0]);
      }else alert("Please select objects first! :)");
      app.redraw();
      

       

      None of the above work however and I'm not sure I'm using the API correctly

       

      How can I round the position of a selected element in Illustrator JSX ?

      I would like to achieve the same for W,H as well.

       

      Any hints/tips are appreciated!

       

      Thanks,

      George