Name of an Adobe InDesign Enumeration

In ExtendScript you could get the name of an Enumeration. I used something that was based on this:

	allPropertiesOfClass = EnumerationClass.reflect.properties;

	//-- loop through all of these different properties
	for (enumerationIndex_i = allPropertiesOfClass.length - 1; enumerationIndex_i >= 0; enumerationIndex_i--) {

		//-- see if the properthy name
		if (EnumerationClass[ allPropertiesOfClass[ enumerationIndex_i ].name ] == EnumerationValue) {

blah, blah, blah…

but in UXP, if you look at an EnumerationClass or an Enumerator, I don’t see anyway to even see the old numbers of the enumerations or the name that I actually want.

My goal, is just get a user understandable value. For example, if the user has a missing link, I want to be able to display the LinkStatus => LINK_MISSING. If the MeasurementUnits is POINTS, I want to be able to see that.

Any ideas?

1 Like

Hi,
one level below in the prototype chain, try this:

Object.getOwnPropertyNames(Object.getPrototypeOf(indesign.MeasurementUnits))
[
    "constructor",
    "points",
    "POINTS",
    "picas",
    "PICAS",
    "inches",
    "INCHES",
    "inchesDecimal",
    "inchesdecimal",
    "INCHES_DECIMAL",
    "millimeters",
    "MILLIMETERS",
    "centimeters",
    "CENTIMETERS",
    "ciceros",
    "CICEROS",
    "q",
    "Q",
    "ha",
    "HA",
    "americanPoints",
    "americanpoints",
    "AMERICAN_POINTS",
    "u",
    "U",
    "bai",
    "BAI",
    "mils",
    "MILS",
    "pixels",
    "PIXELS",
    "custom",
    "CUSTOM",
    "agates",
    "AGATES",
    "constructorName",
    "equals"
]

Roland

Thanks @Roland_Dreger, I’ll be giving that a try in the morning!

This turned out to be much easier than I expected!
You can use .toString() on the value to get the readable enumeration name. For example if you have a app object representing Adobe InDesign, you can get the current UserInteractionLevels via:

app.scriptPreferences.userInteractionLevel.toString();
//-- returns one of these "NEVER_INTERACT", "INTERACT_WITH_ALL", or "INTERACT_WITH_ALERTS"

I didn’t see that as an option in UDT :person_shrugging:

But, on the plus side I know know about Object.getOwnPropertyNames(Object.getPrototypeOf(o))
that @Roland_Dreger suggested. That worked to show me all of them.

	const allEnumerationClassPropertyNames_a = Object.getOwnPropertyNames(Object.getPrototypeOf(EnumerationClass_c));
	//-- That will contain some properties that causes problems. In addition,
	//--	I only want to use the ones that match the legacy versions from
	//--	ExtendScript that were always in ALL_CAPS and could contain an
	//--	optional underscore. Filter out all others:
	const allCaps_re = /^([A-Z]_?)*$/;
	const allUpperCaseEnumerationClassPropertyNames_a = allEnumerationClassPropertyNames_a.filter(enumerationPropertyName_s => allCaps_re.test(enumerationPropertyName_s));

Jon