Carlos, that was a thought but I think it may be too slow for what I had in mind… only wanted a little snap shot as png. A layer has 'dimPlacedImages' but that is images only… Changing all the possible layers opacity and restoring could turn out to be a big ask… depending on the art in question… Here is what I have at the moment the XY stuff is correct in CS5 I don't have CS4 to test with…? It should get you the co-ords relative to the active artboard. These are in edit boxes so you could cut and paste from them. The measures at present are based on the open doc's and it needs to be saved… I may change this to just script preference. Was also going to give an option on snapping the selected object or its parent artboard… Needs a bit more tinkering with yet… #target illustrator
#targetengine main
/*////////////////////////////////////////////////
*/////////////////////////////////////////////////
selectionCoOrds();
function selectionCoOrds() {
if (app.documents.length > 0) {
var doc = app.activeDocument;
var sel = doc.selection;
if (sel.length == 1) {
var aiFile = doc.fullName;
var units = aiRulerUnits(aiFile);
var ab = doc.artboards.getActiveArtboardIndex();
ab++;
sel = sel[0];
//sel.isIsolated = true; No bloody working…
var xy = doc.convertCoordinate(sel.position,
CoordinateSystem.DOCUMENTCOORDINATESYSTEM,
CoordinateSystem.ARTBOARDCOORDINATESYSTEM);
if (parseFloat(app.version) == 15) {xy[1] = -xy[1];}
var x,y,w,h;
switch (units) {
case 'cm' :
x = roundToDP(xy[0]/28.346,4) + ' cm';
y = roundToDP(xy[1]/28.346,4) + ' cm';
w = roundToDP(sel.width/28.346,4) + ' cm';
h = roundToDP(sel.height/28.346,4) + ' cm';
break;
case 'mm' :
x = roundToDP(xy[0]/2.834645,3) + ' mm';
y = roundToDP(xy[1]/2.834645,3) + ' mm';
w = roundToDP(sel.width/2.834645,3) + ' mm';
h = roundToDP(sel.height/2.834645,3) + ' mm';
break;
case 'in' :
x = roundToDP(xy[0]/72,4) + ' in';
y = roundToDP(xy[1]/72,4) + ' in';
w = roundToDP(sel.width/72,4) + ' in';
h = roundToDP(sel.height/72,4) + ' in';
break;
case 'pi' :
// Need to fix these strings yet…
x = roundToDP(xy[0]/12,3) + ' pi';
y = roundToDP(xy[1]/12,3) + ' pi';
w = roundToDP(sel.width/12,3) + ' pi';
h = roundToDP(sel.height/12,3) + ' pi';
break;
case 'pt' :
x = roundToDP(xy[0],4) + ' pt';
y = roundToDP(xy[1],4) + ' pt';
w = roundToDP(sel.width,4) + ' pt';
h = roundToDP(sel.height,4) + ' pt';
break;
case 'px' :
x = roundToDP(xy[0],3) + ' px';
y = roundToDP(xy[1],3) + ' px';
w = roundToDP(sel.width,3) + ' px';
h = roundToDP(sel.height,3) + ' px';
break;
}
var pic = File('~/Desktop/aiSelection.png');
doc.imageCapture(pic,sel.visibleBounds,undefined);
paletteCoOrds(pic,ab,x,y,w,h);
}
}
};
function roundToDP(n,dP) {
return Math.round(n*Math.pow(10,dP))/Math.pow(10,dP);
};
// Find ruler units in file data
function aiRulerUnits(f) {
var rulerUnits = undefined;
f.open('r');
while (!f.eof) {
var line = f.readln();
if (/^%AI\d_RulerUnits:/.test(line)) {
var d = line.match(/\d$/);
switch (Number(d)) {
case 0 : rulerUnits = 'in'; break; // Inches
case 1 : rulerUnits = 'mm'; break; // MM
case 2 : rulerUnits = 'pt'; break; // Points
case 3 : rulerUnits = 'pi'; break; // Picas
case 4 : rulerUnits = 'cm'; break; // CM
case 6 : rulerUnits = 'px'; // Pixels
}
f.close();
return rulerUnits;
}
} // EOF
f.close();
return rulerUnits;
};
// The palette
function paletteCoOrds(selPng,selab,selX,selY,selW,selH) {
var palWin = new Window('palette');
palWin.preferredSize = [150,200];
palWin.opacity = 0.9;
var red = (1/256)*204, green = (1/256)*102, blue = 0;
palWin.graphics.backgroundColor = palWin.graphics.newBrush
(palWin.graphics.BrushType.SOLID_COLOR,[red, green, blue]);
var header = palWin.add('statictext');
header.text = 'Selection Info…';
header.graphics.font = ScriptUI.newFont('Helvetica', 'Bold', 14);
header.graphics.foregroundColor = header.graphics.newPen
(header.graphics.PenType.SOLID_COLOR, [1.0, 1.0, 1.0], 1);
// Written by Marc Autret
Image.prototype.onDraw = function() {
if( !this.image ) return;
var WH = this.size,
wh = this.image.size,
k = Math.min(WH[0]/wh[0], WH[1]/wh[1]),
xy;
wh = [k*wh[0],k*wh[1]];
xy = [ (WH[0]-wh[0])/2, (WH[1]-wh[1])/2 ];
this.graphics.drawImage(this.image,xy[0],xy[1],wh[0],wh[1]);
WH = wh = xy = null;
}
var pic = palWin.add('image', undefined, selPng);
pic.size = [100,100]; // How big you want the image here…
selPng.remove(); // Dump the image we've used it…
var abText = palWin.add('statictext');
abText.text = 'Artboard: ' + selab;
abText.graphics.font = ScriptUI.newFont('Helvetica', 'Bold', 12);
var xGroup = palWin.add('group');
var x = xGroup.add('statictext');
x.graphics.font = ScriptUI.newFont('Helvetica', 'Bold', 12);
x.text = 'X:';
var xEdit = xGroup.add('edittext');
xEdit.characters = 10;
xEdit.text = selX;
var yGroup = palWin.add('group');
var y = yGroup.add('statictext');
y.graphics.font = ScriptUI.newFont('Helvetica', 'Bold', 12);
y.text = 'Y:';
var yEdit = yGroup.add('edittext');
yEdit.characters = 10;
yEdit.text = selY;
var wGroup = palWin.add('group');
var w = wGroup.add('statictext');
w.graphics.font = ScriptUI.newFont('Helvetica', 'Bold', 12);
w.text = 'W:';
var wEdit = wGroup.add('edittext');
wEdit.characters = 10;
wEdit.text = selW;
var hGroup = palWin.add('group');
var h = hGroup.add('statictext');
h.graphics.font = ScriptUI.newFont('Helvetica', 'Bold', 12);
h.text = 'H:';
var hEdit = hGroup.add('edittext');
hEdit.characters = 10;
hEdit.text = selH;
var beGone = palWin.add('button',undefined,'Be Gone…');
palWin.center();
palWin.show();
beGone.onClick = function() {
// Fadeout locks focus for a short while…
for (var i = 90; i > 10; i--) {
$.sleep(10);
palWin.opacity = i/100;
}
palWin.close(); // Be gone…
};
};
... View more