Skip to main content
Flowgun
Inspiring
July 14, 2025
Answered

Reset View (rotation) via scripting?

  • July 14, 2025
  • 1 reply
  • 311 views

Hello everyone,
I want to create a script that resets the view rotation to 0. 
I tried using ActiveDocument.rotateCanvas() but it only adds the given amount to the current rotation.
maybe there's a way to call "reset view" directly, or to read the canvas rotation angle then use that value in ActiveDocument.rotateCanvas() to cancel out the rotation?

Correct answer jazz-y

There is one workaround, but the rotation angle reset will apply to all open documents:

s2t = stringIDToTypeID;

(d1 = new ActionDescriptor()).putClass(s2t("mode"), s2t("RGBColorMode"));
d1.putUnitDouble(s2t("width"), s2t("distanceUnit"), 1);
d1.putUnitDouble(s2t("height"), s2t("distanceUnit"), 1);
d1.putUnitDouble(s2t("resolution"), s2t("densityUnit"), 72);
d1.putEnumerated(s2t("fill"), s2t("fill"), s2t("white"));
(d = new ActionDescriptor()).putObject(s2t("new"), s2t("document"), d1);

executeAction(s2t("make"), d, DialogModes.NO);

(r = new ActionReference()).putEnumerated(s2t('menuItemClass'), s2t('menuItemType'), s2t("matchRotation"));
(d = new ActionDescriptor()).putReference(s2t('null'), r);
executeAction(s2t('select'), d, DialogModes.NO);

executeAction(s2t("close"), new ActionDescriptor(), DialogModes.NO);

 

1 reply

creative explorer
Community Expert
Community Expert
July 15, 2025

@Flowgun The best and simplest way to achieve a full reset is to directly call Photoshop's built-in "Reset View" command. Maybe a script that will reset your canvas rotation to 0, just as if you went to View > Rotate View > Reset View

 

// This script resets the canvas view rotation in Adobe Photoshop to 0 degrees.

// It mimics the functionality of going to View > Rotate View > Reset View.

// Define the stringID for the "resetView" command.

// This is a direct command that tells Photoshop to reset the canvas rotation.

var idresetView = stringIDToTypeID("resetView");

// Execute the action.

// The 'undefined' parameter indicates that this action does not require any specific

// additional parameters (like an angle value).

// DialogModes.NO means the action will be executed silently without showing any dialogs.

executeAction(idresetView, undefined, DialogModes.NO);

// Optional: You can add an alert to confirm the action, useful for debugging.

// alert("Canvas view rotation has been reset to 0 degrees.");

This script directly invokes Photoshop's internal command to reset the canvas rotation, which is the most efficient and reliable method. It avoids the need to read the current angle and calculate an inverse rotation, ensuring a perfect reset without affecting other brush or tool settings.

m
Flowgun
FlowgunAuthor
Inspiring
July 15, 2025

the executeAction fails 😕😕

Legend
July 15, 2025

There are a number of problems interacting with the rotate tool parameters via scripts (for example Rotate tool does not assign angle value trough script  ). In particular, you can't get the canvas rotation angle, you can't assign a new one, you can't reset the rotation parameters. You can only click the 'Rotate All Windows' checkbox (very useful 🤣).  Unfortunately, this is a bug that hasn't been fixed for years.

If you want to change this parameter using AHK, it is easier to position the mouse cursor over the button and click it.