The following script will scale each object based on the maxed width and height entered in the desired unit of measurement. You must have objects selected before running the script.
// Check if there are selected objects if (app.activeDocument.selection.length > 0) { // Prompt user for the unit of measurement var unit = prompt('Enter the unit of measurement (px, in, cm, mm, m):', 'px'); // Prompt user for maximum width and height var maxWidth = prompt('Enter the maximum width (' + unit + '):', ''); var maxHeight = prompt('Enter the maximum height (' + unit + '):', ''); // Convert input to numbers maxWidth = parseFloat(maxWidth); maxHeight = parseFloat(maxHeight); // Convert units to pixels for internal processing switch (unit) { case 'in': maxWidth *= 72; // 1 inch = 72 pixels maxHeight *= 72; break; case 'cm': maxWidth *= 28.35; // 1 cm = 28.35 pixels maxHeight *= 28.35; break; case 'mm': maxWidth *= 2.835; // 1 mm = 2.835 pixels maxHeight *= 2.835; break; case 'm': maxWidth *= 2835; // 1 m = 2835 pixels maxHeight *= 2835; break; case 'px': default: // No conversion needed break; } // Loop through each selected object for (var i = 0; i < app.activeDocument.selection.length; i++) { var selectedItem = app.activeDocument.selection[i]; // Get the current width and height var currentWidth = selectedItem.width; var currentHeight = selectedItem.height; // Calculate the scale ratio var widthRatio = maxWidth / currentWidth; var heightRatio = maxHeight / currentHeight; var scaleRatio = Math.min(widthRatio, heightRatio); // Scale the object selectedItem.resize(scaleRatio * 100, scaleRatio * 100, true, true, true, true, scaleRatio); // Scale the strokes selectedItem.strokeWidth *= scaleRatio; } } else { alert('Please select one or more objects.'); }