# Enumerator Error Workaround

**URL:** <https://forums.creativeclouddeveloper.com/t/enumerator-error-workaround/6629>\
**Category:** InDesign\
**Tags:** uxp\
**Created:** [August 5, 2023, 8:59pm UTC](https://forums.creativeclouddeveloper.com/t/enumerator-error-workaround/6629 "2023-08-05T20:59:22Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![salinsley](https://avatars.discourse-cdn.com/v4/letter/s/b3f665/32.png) [@salinsley](https://forums.creativeclouddeveloper.com/u/salinsley)\
**Post date:** [August 5, 2023, 8:59pm UTC](https://forums.creativeclouddeveloper.com/t/enumerator-error-workaround/6629/1 "2023-08-05T20:59:22Z")

</div>

Hi folks! I’m migrating some old ExtendScript files into UXP, and I had a lot of issues with constants defined in InDesign not being available in UXP, e.g. `MeasurementUnits.PIXELS`. I found a workaround that’s been super helpful, and I haven’t seen any public posts about it, so I thought I’d share.

If you explicitly define the objects that you need with their numeric value from [the documentation](https://developer.adobe.com/indesign/dom/api/m/MeasurementUnits/), you can use them as normal in your old ExtendScript files. For example:

```auto
// define constants
const FitOptions = {
  APPLY_FRAME_FITTING_OPTIONS: 1634100847,
  CENTER_CONTENT: 1667591779,
  CONTENT_AWARE_FIT: 1667327593,
  CONTENT_TO_FRAME: 1668575078,
  FILL_PROPORTIONALLY: 1718185072,
  FRAME_TO_CONTENT: 1718906723,
  PROPORTIONALLY: 1668247152
}
const MeasurementUnits = {
  AGATES: 2051106676,
  AMERICAN_POINTS: 1514238068,
  BAI: 2051170665,
  CENTIMETERS: 2053336435, 
  CICEROS: 2053335395,
  CUSTOM: 1131639917,
  HA: 1516790048,
  INCHES: 2053729891,
  INCHES_DECIMAL: 2053729892,
  MILLIMETERS: 2053991795,
  MILS: 2051893612,
  PICAS: 2054187363,
  PIXELS: 2054187384,
  POINTS: 2054188905,
  Q: 2054255973,
  U: 2051691808
}
const PageBindingOptions = {
  DEFAULT_VALUE: 1147563124,
  LEFT_TO_RIGHT: 1819570786,
  RIGHT_TO_LEFT: 1920232546
}
const MeasurementUnits = {
  AGATES: 2051106676,
  AMERICAN_POINTS: 1514238068,
  BAI: 2051170665,
  CENTIMETERS: 2053336435, 
  CICEROS: 2053335395,
  CUSTOM: 1131639917,
  HA: 1516790048,
  INCHES: 2053729891,
  INCHES_DECIMAL: 2053729892,
  MILLIMETERS: 2053991795,
  MILS: 2051893612,
  PICAS: 2054187363,
  PIXELS: 2054187384,
  POINTS: 2054188905,
  Q: 2054255973,
  U: 2051691808
}

// perform actions on the document
app.selection[0].fit(FitOptions.FRAME_TO_CONTENT);
app.activeDocument.documentPreferences.pageBinding = PageBindingOptions.RIGHT_TO_LEFT;
app.scriptPreferences.measurementUnit = MeasurementUnits.PIXELS;

```

It would be nice if this were included in UXP by default, but this is a decent workaround until then, especially if you dump all of them in a separate JS file. It would be trivial to remove this workaround when UXP is updated.

Hope this helps someone!

---

<div class="post-metadata">

**Author:** ![sttk3](https://avatars.discourse-cdn.com/v4/letter/s/958977/32.png) [@sttk3](https://forums.creativeclouddeveloper.com/u/sttk3)\
**Post date:** [August 5, 2023, 11:47pm UTC](https://forums.creativeclouddeveloper.com/t/enumerator-error-workaround/6629/2 "2023-08-05T23:47:36Z")

</div>

This can be found by referring to correct places, so we do not have to define it by ourselves.

For example,

```auto
const InDesign = require('indesign') ;
console.log(InDesign.MeasurementUnits.PIXELS) ;

```

or

```auto
const InDesign = require('indesign') ;
const { MeasurementUnits } = InDesign ;
console.log(MeasurementUnits.PIXELS) ;

```

Your kindness is great.

---

<div class="post-metadata">

**Author:** ![medium\_jon](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.creativeclouddeveloper.com/medium_jon/32/2371_2.png) [@medium\_jon](https://forums.creativeclouddeveloper.com/u/medium_jon)\
**Post date:** [August 6, 2023, 3:50pm UTC](https://forums.creativeclouddeveloper.com/t/enumerator-error-workaround/6629/3 "2023-08-06T15:50:23Z")

</div>

Excellent. Thanks for sharing @sttk3!

---

<div class="post-metadata">

**Author:** ![salinsley](https://avatars.discourse-cdn.com/v4/letter/s/b3f665/32.png) [@salinsley](https://forums.creativeclouddeveloper.com/u/salinsley)\
**Post date:** [August 7, 2023, 1:33pm UTC](https://forums.creativeclouddeveloper.com/t/enumerator-error-workaround/6629/4 "2023-08-07T13:33:37Z")

</div>

Thank you so much @sttk3! Do you mind sharing where you found this in the documentation? I can’t find a good explanation for how `require("indesign")` works, and the UXP code samples I can find don’t correctly explain how to use the module like you showed in your example: [https://developer.adobe.com/indesign/uxp/resources/recipes/document-changes/](https://developer.adobe.com/indesign/uxp/resources/recipes/document-changes/)

---

<div class="post-metadata">

**Author:** ![sttk3](https://avatars.discourse-cdn.com/v4/letter/s/958977/32.png) [@sttk3](https://forums.creativeclouddeveloper.com/u/sttk3)\
**Post date:** [August 7, 2023, 2:12pm UTC](https://forums.creativeclouddeveloper.com/t/enumerator-error-workaround/6629/5 "2023-08-07T14:12:15Z")

</div>

They are found here. Documentation has yet to catch up.

- [Plans for UXP in 2023. New features planned for UXP v7.0 and beyond](https://blog.developer.adobe.com/plans-for-uxp-in-2023-d06091944308)
- [InDesign DOM APIs](https://developer.adobe.com/indesign/uxp/resources/fundamentals/dom-versioning/)

---

<div class="post-metadata">

**Author:** ![Vnh68](https://avatars.discourse-cdn.com/v4/letter/v/6f9a4e/32.png) [@Vnh68](https://forums.creativeclouddeveloper.com/u/Vnh68)\
**Post date:** [August 18, 2023, 5:38am UTC](https://forums.creativeclouddeveloper.com/t/enumerator-error-workaround/6629/6 "2023-08-18T05:38:15Z")

</div>

I use the following code:

> const { app, MeasurementUnits, ParagraphStyle, CharacterStyle } = require(“indesign”);

Depending on the complexity of the code, the list is growing all the time…

---

<div class="post-metadata">

**Author:** ![vamitul](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.creativeclouddeveloper.com/vamitul/32/3075_2.png) [@vamitul](https://forums.creativeclouddeveloper.com/u/vamitul)\
**Post date:** [August 28, 2023, 5:02pm UTC](https://forums.creativeclouddeveloper.com/t/enumerator-error-workaround/6629/7 "2023-08-28T17:02:34Z")

</div>

I’m very curious why are you importing the CharacterStyle and ParagraphStyle objects.

---

<div class="post-metadata">

**Author:** ![Vnh68](https://avatars.discourse-cdn.com/v4/letter/v/6f9a4e/32.png) [@Vnh68](https://forums.creativeclouddeveloper.com/u/Vnh68)\
**Post date:** [August 29, 2023, 7:21am UTC](https://forums.creativeclouddeveloper.com/t/enumerator-error-workaround/6629/8 "2023-08-29T07:21:35Z")

</div>

Oh, I badly edited the example from the code, didn’t remove the excess…

DOM classes are sometimes convenient to extend through their prototypes, you can add properties and methods, and use them without creating processing loops. You can add properties and methods to classes through prototypes in UXP, but you must import the class to do so.

> const {app, Document } = require(‘indesign’);  
> …  
> Document.prototype.myMethod = function() {…code…}
> 
> app.documents.everyItem().myMethod(); // somewhere in a script — no loop!
