InDesign script help - Units from selections and units in input boxes
Hello,
There is a script below which changes the value of the width and height of many objects at the same time.
Two issues with it
One: I want a user to be able to leave a field blank and the script then uses the left out field as the value for the object size. Importantly, this could run into issues if there are many selected items which each have differerent sizes.... so maybe this i a concept that is impractical?
Two: This is a comment issue I run into, dialogue boxes in ID usally display the unit that document is set up in, best seen in the screenshots below


However in this script below, there is a horrible pt

The pt is not important - this is becuase no matter what the user has their document unit preferance set in the input value becomes the size of whatever thing they want to resize - thus the pt is not important
How can I either remove the pt or have the pt change to show the unit which the document is set. importantly the in the latter as ID converts inputs to points, also dont want a sitution where 40mm becomes xxxxxpt as it converts it..... perhaps I have this issue wrong
// Wrap the script in app.doScript for a single undoable step
app.doScript(function() {
// Define the dialog
var myDialog = app.dialogs.add({name: "Change Object Size"});
with (myDialog.dialogColumns.add()) {
with (dialogRows.add()) {
with (dialogColumns.add()) {
staticTexts.add({staticLabel: "Width:"});
staticTexts.add({staticLabel: "Height:"});
}
with (dialogColumns.add()) {
var widthEditbox = measurementEditboxes.add();
var heightEditbox = measurementEditboxes.add();
}
}
}
// Show the dialog
if (myDialog.show() == true) {
// Get the user input values
var newHeight = widthEditbox.editValue;
var newWidth = heightEditbox.editValue;
// Close the dialog
myDialog.destroy();
// Get the selected objects
var selectedObjects = app.activeDocument.selection;
// Loop through selected objects and change their size from the center
for (var i = 0; i < selectedObjects.length; i++) {
var currentObject = selectedObjects[i];
// Check if the selected object is a valid page item
if (currentObject.hasOwnProperty("geometricBounds")) {
// Get the current geometric bounds
var currentBounds = currentObject.geometricBounds;
// Calculate the center of the current bounds
var centerX = (currentBounds[0] + currentBounds[2]) / 2;
var centerY = (currentBounds[1] + currentBounds[3]) / 2;
// Calculate the new bounds
var newBounds = [
centerX - newWidth / 2,
centerY - newHeight / 2,
centerX + newWidth / 2,
centerY + newHeight / 2
];
// Apply the new geometric bounds
currentObject.geometricBounds = newBounds;
}
}
} else {
// Dialog was canceled
myDialog.destroy();
}
}, ScriptLanguage.JAVASCRIPT, undefined, UndoModes.ENTIRE_SCRIPT, "Change Object Size");
