Changing RulerUnits via BatchPlay not working

I’m trying to change the rulerUnits via BatchPlay but nothing is happeninig, this is the code I’m using:

require('photoshop').core.executeAsModal(function () {
  try {
    batchPlay(
      [
        {
          _obj: "set",
          _target: [
            {
              _ref: "property",
              _property: "unitsPrefs"
            },
            {
              _ref: "application",
              _enum: "ordinal",
              _value: "targetEnum"
            }
          ],
          to: {
            _obj: "unitsPrefs",
            rulerUnits: {
              _enum: "rulerUnits",
              _value: "rulerPixels"
            }
          },
          _options: {
            dialogOptions: "dontDisplay"
          }
        }
      ], {
      synchronousExecution: false,
      modalBehavior: "fail"
    });
  } catch (e) {
    console.log(e);
  }
});

This doesn’t even logs an error, so I don’t know what is happening. I saw that the RulerUnits constant is not available on the DOM yet so I tried with Batchplay to change it but nothing is happeninig.

Am I doing something wrong?

I appreciate your help.

Hi,
it’s in the DOM now, see the Changelog.

Try this:

const photoshop = require('photoshop');
const app = require('photoshop').app; 
const executeAsModal = photoshop.core.executeAsModal;
const constants = require('photoshop').constants; 

// You need a modal state to change the rulers
await executeAsModal(async () => {
    app.preferences.unitsAndRulers.rulerUnits = constants.RulerUnits.MILLIMETERS
}, { commandName: "Changing ruler units" })

HTH,
Davide

1 Like

Hello Davide!

Thank you very much for your answer it works now!

I’m very happy it has been updated!

I don’t explain myself how in my VS Code doesn’t updates this specific constant colors as “constants.BitsPerChannelType” or “constants.ElementPlacement” does. I actually went to the folder:

C:/Users/USER/AppData/Local/Microsoft/TypeScript/4.8/node_modules/@types/photoshop/dom/Constants

and opened the “constants.ts” file but it was not updated there but some how it works, how is it possible?

Kind regards,

The process of updating types for Photoshop is slower than it should be. Check frequently the changelog and the API reference, which is always up-to-date with the latest additions.

Davide

1 Like