How to make a rectangle around activeDocument.selection?
Hi,everyone!
Recently I met a awful problem. I want to make a rectangle around current selection, but Not success.
Could you help me or give some clues? Thanks!
Hi,everyone!
Recently I met a awful problem. I want to make a rectangle around current selection, but Not success.
Could you help me or give some clues? Thanks!
Which AI-version?
In CS3 this works for me:
// Box4selectedPath.jsx
// for selected pathItems // CS3
// creates a green rectangle around all the selected paths (visibleBounds)
// regards pixxxelschubser
// http://forums.adobe.com/thread/1183584
var StrtPOrigin = app.activeDocument.pageOrigin;
var StrtROrigin = app.activeDocument.rulerOrigin;
app.activeDocument.pageOrigin = Array(0,0);
app.activeDocument.rulerOrigin = Array(0,0);
var aDoc = app.activeDocument;
var Sel = aDoc.selection;
var newRGBColor = new RGBColor();
newRGBColor.red = 0;
newRGBColor.green = 255;
newRGBColor.blue = 0;
if (Sel.length >0 ) {
var vBounds = Sel[0].visibleBounds;
vBounds_Li = vBounds[0];
vBounds_Ob = vBounds[1];
vBounds_Re = vBounds[2];
vBounds_Un = vBounds[3];
if (Sel.length >1 ) {
for (i=1; i<Sel.length ; i++) {
vBdsI = Sel.visibleBounds;
if( vBounds_Li > vBdsI[0] ) {vBounds_Li = vBdsI[0]};
if( vBounds_Ob < vBdsI[1] ) {vBounds_Ob = vBdsI[1]};
if( vBounds_Re < vBdsI[2] ) {vBounds_Re = vBdsI[2]};
if( vBounds_Un > vBdsI[3] ) {vBounds_Un = vBdsI[3]};
}
}
var aRectangle = aDoc.pathItems.rectangle(vBounds_Ob, vBounds_Li, vBounds_Re - vBounds_Li, vBounds_Ob - vBounds_Un);
aRectangle.strokeColor = newRGBColor;
aRectangle.strokeWidth= 2;
aRectangle.filled = false;
aRectangle.stroked = true;
aDoc.selection = null;
} else {
alert ("no selection")
}
app.activeDocument.pageOrigin = StrtPOrigin;
app.activeDocument.rulerOrigin = StrtROrigin;
Remember: only pathItems
Already have an account? Login
Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.