Created
September 28, 2011 17:33
-
-
Save mirka/1248592 to your computer and use it in GitHub Desktop.
Randomize/reset measurementUnit settings
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#target indesign | |
var sp = app.scriptPreferences; | |
var vp = app.documents[0].isValid ? | |
document.viewPreferences : app.viewPreferences; | |
function randomizeSettings() { | |
var unitArray = [ | |
MeasurementUnits.POINTS, | |
MeasurementUnits.PICAS, | |
MeasurementUnits.INCHES, | |
MeasurementUnits.INCHES_DECIMAL, | |
MeasurementUnits.MILLIMETERS, | |
MeasurementUnits.CENTIMETERS, | |
MeasurementUnits.CICEROS, | |
MeasurementUnits.CUSTOM, | |
MeasurementUnits.AGATES, | |
MeasurementUnits.U, | |
MeasurementUnits.BAI, | |
MeasurementUnits.MILS, | |
MeasurementUnits.PIXELS, | |
MeasurementUnits.HA, | |
MeasurementUnits.AMERICAN_POINTS, | |
]; | |
var scriptUnitArray = unitArray.concat(AutoEnum.AUTO_VALUE); | |
var strokeUnitArray = [ | |
MeasurementUnits.POINTS, | |
MeasurementUnits.MILLIMETERS, | |
MeasurementUnits.PIXELS, | |
]; | |
var textUnitArray = [ | |
MeasurementUnits.POINTS, | |
MeasurementUnits.PIXELS, | |
MeasurementUnits.Q, | |
MeasurementUnits.AMERICAN_POINTS, | |
]; | |
var typoUnitArray = [ | |
MeasurementUnits.POINTS, | |
MeasurementUnits.PIXELS, | |
MeasurementUnits.HA, | |
MeasurementUnits.AMERICAN_POINTS, | |
MeasurementUnits.U, | |
MeasurementUnits.BAI, | |
MeasurementUnits.MILS, | |
]; | |
var rulerOriginArray = [ | |
RulerOrigin.SPREAD_ORIGIN, | |
RulerOrigin.PAGE_ORIGIN, | |
RulerOrigin.SPINE_ORIGIN, | |
]; | |
function getRandomItem(myArray) { | |
var myIndex = Math.floor(Math.random() * myArray.length); | |
return myArray[myIndex]; | |
} | |
// Set random values to the preferences | |
sp.measurementUnit = getRandomItem(scriptUnitArray); | |
vp.horizontalMeasurementUnits = getRandomItem(unitArray); | |
vp.verticalMeasurementUnits = getRandomItem(unitArray); | |
vp.strokeMeasurementUnits = getRandomItem(strokeUnitArray); | |
vp.textSizeMeasurementUnits = getRandomItem(textUnitArray); | |
vp.typographicMeasurementUnits = getRandomItem(typoUnitArray); | |
vp.rulerOrigin = getRandomItem(rulerOriginArray); | |
showCurrentSettings(); | |
} | |
function resetSettings() { | |
var defaultUnits = MeasurementUnits.MILLIMETERS; | |
sp.measurementUnit = AutoEnum.AUTO_VALUE; | |
vp.horizontalMeasurementUnits = defaultUnits; | |
vp.strokeMeasurementUnits = defaultUnits; | |
vp.verticalMeasurementUnits = defaultUnits; | |
vp.rulerOrigin = RulerOrigin.SPINE_ORIGIN; | |
vp.textSizeMeasurementUnits = MeasurementUnits.Q; | |
vp.typographicMeasurementUnits = MeasurementUnits.HA; | |
showCurrentSettings(); | |
} | |
function showCurrentSettings() { | |
alert( | |
"Current settings:\n" + | |
"Script: " + sp.measurementUnit.toString() + "\n\n" + | |
"Horizontal: " + vp.horizontalMeasurementUnits.toString() + "\n" + | |
"Vertical: " + vp.verticalMeasurementUnits.toString() + "\n" + | |
"Stroke: " + vp.strokeMeasurementUnits.toString() + "\n\n" + | |
"Text: " + vp.textSizeMeasurementUnits.toString() + "\n" + | |
"Typo: " + vp.typographicMeasurementUnits.toString() + "\n\n" + | |
"Ruler: " + vp.rulerOrigin.toString() | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment