Hi @Ben-ind, there isn't any super-handy method that I can think of to do this.
One approach could be to add an event listener (to the document, for example) that would trigger every time the selection changed. It could then add your desired info to the selected item's Script Label panel. A better UI would be to create a CEP panel to show the info, but that is quite a bit more involved unless you've made one before.
Here's a quick example implementation to give you the idea. To help manage the event listener, I've set it up to alternate between adding and then removing the listener each time you run the script.
- Mark

//@targetengine "SetLabelAsVerticalDistance"
function main() {
var listenerID = 'SetLabelAsVerticalDistance',
referenceCircleID = 'ReferenceCircle',
referenceCircleColorID = 'Red';
app.scriptPreferences.measurementUnit = MeasurementUnits.POINTS;
var doc = app.activeDocument;
// get the event listener
var listener = doc.eventListeners.itemByName(listenerID);
// if it exists already, remove it
if (listener.isValid) {
listener.remove();
alert('Event listener "' + listenerID + '" has been removed from document.');
return;
}
else {
// make the event listener
listener = doc.eventListeners.add("afterSelectionChanged", setLabelToDistanceFromVerticalDatum);
listener.name = listenerID;
alert('Event listener "' + listenerID + '" has been added to document.');
}
// the function that will be called by the event listener
function setLabelToDistanceFromVerticalDatum() {
if (doc.selection.length == 0)
return;
var page = doc.layoutWindows[0].activePage;
// get reference circle, if it exists on this page
var referenceCircle = page.pageItems.itemByName(referenceCircleID);
if (
referenceCircle == undefined
|| !referenceCircle.isValid
)
referenceCircle = makeCircle(page);
// I've used the top of the reference circle,
// but you should set this any way you want
var referenceCircleVerticalDatum = referenceCircle.geometricBounds[0];
for (var i = 0; i < doc.selection.length; i++) {
var item = doc.selection[i];
if (item == referenceCircle)
continue;
if (item.hasOwnProperty('geometricBounds'))
// add to the script label (rounded to 3 decimals)
item.label = 'Distance: ' + (Math.round((item.geometricBounds[0] - referenceCircleVerticalDatum) * 1000) / 1000);
}
};
function makeCircle(pg) {
var circle = pg.ovals.add(doc.activeLayer, undefined, undefined, { geometricBounds: [0, 10, 1, 11], strokeWeight: 1, name: referenceCircleID }),
red = doc.colors.itemByName(referenceCircleColorID);
if (!red.isValid)
red = doc.colors.add({ name: referenceCircleColorID, space: ColorSpace.RGB, colorValue: [255, 0, 0], colorModel: ColorModel.PROCESS });
circle.strokeColor = red;
return circle;
};
};
app.doScript(main, ScriptLanguage.JAVASCRIPT, undefined, UndoModes.ENTIRE_SCRIPT, 'Add event listener to set distance from datum');