// Roger Breton / October 18 2024
// Get the active document
var myDocument = app.activeDocument;
var DocName = app.activeDocument.name;
// Retrieve current Measurement units
var CurrentXUnits = myDocument.viewPreferences.horizontalMeasurementUnits;
var CurrentYUnits = myDocument.viewPreferences.verticalMeasurementUnits;
// Convert to string to see the unit name
var CurrentXUnitsString = CurrentXUnits.toString();
var CurrentYUnitsString = CurrentYUnits.toString();
// Create a new window
var myWindow = new Window("dialog", "Unités de Mesure");
// Add a panel to the window
var myPanel = myWindow.add("panel", undefined, "Choisir Unité:");
myPanel.alignChildren = "left";
// Add some space between the panel title and the radio button group
myPanel.margins = [10, 20, 10, 10]; // [left, top, right, bottom] margins
// Add a group to the panel
var radioGroup = myPanel.add("group");
radioGroup.orientation = "column";
radioGroup.alignment = "left"
// Add radio buttons to the group
var option1 = radioGroup.add("radiobutton", undefined, "Pouces");
var option2 = radioGroup.add("radiobutton", undefined, "Points");
var option3 = radioGroup.add("radiobutton", undefined, "Picas");
var option4 = radioGroup.add("radiobutton", undefined, "Centimètres");
var selectedOption;
// Add an OK button to the panel
var okButton = myPanel.add("button", undefined, "OK");
okButton.onClick = function() {
// Get the selected radio button value
if (option1.value) {
selectedOption = "Pouces";
} else if (option2.value) {
selectedOption = "Points";
} else if (option3.value) {
selectedOption = "Picas";
} else if (option4.value) {
selectedOption = "Centimètres";
}
// Change settings based on the user's selection
// alert("You selected " + selectedOption);
// Close the dialog
myWindow.close();
};
// Pre-select a radio button based on a condition
var condition = CurrentXUnitsString; // Example condition
// Manually set the radio button value
if (condition === "INCHES") option1.value = true;
else if (condition === "POINTS") option2.value = true;
else if (condition === "PICAS") option3.value = true;
else if (condition === "CENTIMETERS") option4.value = true;
// Show the window
myWindow.show();
// Change settings based on the user's selection
if (selectedOption === "Pouces") {
myDocument.viewPreferences.horizontalMeasurementUnits = MeasurementUnits.INCHES;
myDocument.viewPreferences.verticalMeasurementUnits = MeasurementUnits.INCHES;
} else if (selectedOption === "Points") {
myDocument.viewPreferences.horizontalMeasurementUnits = MeasurementUnits.POINTS;
myDocument.viewPreferences.verticalMeasurementUnits = MeasurementUnits.POINTS;
} else if (selectedOption === "Picas") {
myDocument.viewPreferences.horizontalMeasurementUnits = MeasurementUnits.PICAS;
myDocument.viewPreferences.verticalMeasurementUnits = MeasurementUnits.PICAS;
} else if (selectedOption === "Centimètres") {
myDocument.viewPreferences.horizontalMeasurementUnits = MeasurementUnits.CENTIMETERS;
myDocument.viewPreferences.verticalMeasurementUnits = MeasurementUnits.CENTIMETERS;
}