• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Seeking Scripts to Change Measurement Units in InDesign and Display Current Units

Enthusiast ,
Oct 18, 2024 Oct 18, 2024

Copy link to clipboard

Copied

I use the Ctrl + Shift + Alt + U keyboard shortcut but it does not work all the time.
Like, once I'm in the New document dialog box, it won't work. At least with my Canadian Multilingual keyboard mapping in Windows. I always thought it would be "nice" to see the current units being displayed somewhere in the interface? I understand that I can, to some extent, "read" the current units out of the appearance of the Rufers but it's far from ideal. 

Maybe a scipt that show the current units and give a choice of units to switch to in the form of a series of vertical radio buttons? Don't even need an OK button, to speed things up. 

 

Any help is appreciated

 

 

<Title renamed by MOD>

TOPICS
Performance , Scripting

Views

128

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Enthusiast , Oct 18, 2024 Oct 18, 2024

Here is a script that works for me :

// 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();


// Cr
...

Votes

Translate

Translate
Enthusiast ,
Oct 18, 2024 Oct 18, 2024

Copy link to clipboard

Copied

Here is a script that works for me :

// 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;
 }









Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 18, 2024 Oct 18, 2024

Copy link to clipboard

Copied

show the current units and give a choice of units to switch to in the form of a series of vertical radio buttons?

 

Hi @Roger Breton , You can also Control or Right-Click the Rulers and get a full list and change units

 

Screen Shot 14.png

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Oct 18, 2024 Oct 18, 2024

Copy link to clipboard

Copied

LATEST

Thank you for the suggestion. That's one of the first technique I show students.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines