Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

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

Community Beginner ,
Sep 19, 2014 Sep 19, 2014

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.position);

    s.position[0] = Math.round(s.position[0]);

    s.position[1] = Math.round(s.position[1]); 

    $.writeln("after: ",s.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.position[0]);

    var x = s.position[0];

    var y = s.position[1];

    var dx = Math.round(x)-x;

    var dy = Math.round(y)-y;

   

    $.writeln(dx,",",dy);

   

    s.translate(-dx,-dy);

   

    $.writeln("after: ",s.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

TOPICS
Scripting
376
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Valorous Hero , Sep 19, 2014 Sep 19, 2014

I think you can just do pageItem.top = Math.round(pageItem.top);  , same with left.  And same with pageItem.width & height.

Translate
Adobe
Valorous Hero ,
Sep 19, 2014 Sep 19, 2014
LATEST

I think you can just do pageItem.top = Math.round(pageItem.top);  , same with left.  And same with pageItem.width & height.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines