Getting the "real" visibleBounds with javascript...
hi all,
i'm have great deal of trouble this.
i can visible bounds of simple item or group of items.
the script is:
//get size selected items/groups
doc = app.activedocument;
sel = doc.selection;
tomm = 2.83466796875;
dim(sel);
function dim(objs) {
(i=objs.length-1;i>=0;i--) { // loop through collection of objects
var bounds = objs[i].visiblebounds; // visibal bounds, visable bounds in cases...
var b1 = bounds[0] /tomm;
var b2 = bounds[1] /tomm;
var b3 = bounds[2] /tomm;
var b4 = bounds[3] /tomm;
var w = math.abs(b3-b1).tofixed(1);
var h = math.abs(b4-b2).tofixed(1);
txt = doc.textframes.add(); // create text frame
txt.contents = "size: "+ h + " x " +w + " mm w"; // adds contents frame
txt.position = [objs[i].left,objs[i].top - objs[i].height - 20]; // positions frame
}; };
i can correct size simple clipgroups.
script below:
//get size selected "simple" clipgroups
doc = app.activedocument;
grp = doc.groupitems;
tomm = 2.83466796875;
dim(grp);
function dim(objs) {
(i=objs.length-1;i>=0;i--) { // loop through total collection of groupitems
if (objs[i].selected) { // test if groupitem selected
if(objs[i].pathitems[0].clipping==true){
var bounds = objs[i].pathitems[0].visiblebounds; // visibal bounds, visable bounds in cases...
var b1 = bounds[0] /tomm;
var b2 = bounds[1] /tomm;
var b3 = bounds[2] /tomm;
var b4 = bounds[3] /tomm;
var w = math.abs(b3-b1).tofixed(1);
var h = math.abs(b4-b2).tofixed(1);
txt = doc.textframes.add(); // create text frame
txt.contents = "size: "+ h + " x " +w + " mm w"; // adds contents frame
txt.position = [objs[i].left,objs[i].top - objs[i].height - 20]; // positions frame
}; }; }; };
i don't think merging these 1 script hard.
if clip groups clipping path not first item can loop path items find it.
its more complex items can't handle on.
questions:-
how deal multiple cilp groups within clip groups?
here link zip file containing above 2 scripts.
and test file shapes in it.
http://qwertyfly.com/files/size.zip
top 2 rows of shapes work fine size.jsx
first item on bottom row works clipsize.jsx
second item on bottom row work clipsize.jsx, if added loop through "pathitems".
last item on bottom row has me stumped...
does not matter clip group measured, both wrong.
and still quite simple shape...
any great.
thanks guys...
you have use recursive method , check last parent item in group.
i nickname, haha.
More discussions in Illustrator Scripting
adobe
Comments
Post a Comment