Copy link to clipboard
Copied
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
I think you can just do pageItem.top = Math.round(pageItem.top); , same with left. And same with pageItem.width & height.
Copy link to clipboard
Copied
I think you can just do pageItem.top = Math.round(pageItem.top); , same with left. And same with pageItem.width & height.
Find more inspiration, events, and resources on the new Adobe Community
Explore Now