Is posible to Set a: zoom Event?

I would like to create an Event when press Zoom in or Zoom out

I would like to program a zoom in or out to the image with values and I don’t know how to do it since that function is not captured. Thank you

It is possible but I would have to look how to write it. You should use “set” action and set zoom property in document class.

That’s exactly what I tried but it didn’t work for me. Someone wrote something similar on the forum and it didn’t work for him.

There are some View menu items in Photoshop with different zoom levels. If one of those “values” works for your intended purpose, it should be possible to convert it to batchPlay.

I used alchemist and descriptor to see if an event was fired with the views and they do not have the zoom when zoomed, the event is not fired either

You can make a Ps action out of any Ps menu item using the Actions panel fly-out menu (Insert Menu Item…)

Then you can click on the action and use the fly-out menu again to “Copy as Javascript” to get the batchPlay code. Just paste it into any text editor to see it.

I think @Jarda also has a plugin (Occulist?) that does something similar for actions. The key is making Photoshop action first and then extracting the batchPlay code from it. You can capture some things in Ps actions that Alchemist doesn’t see.

So I looked into my ExScript codes:

function setPanZoom(x, y, z) {
	var panZoomDescriptor = new ActionDescriptor();
	panZoomDescriptor.putDouble(stringIDToTypeID("x"), x);
	panZoomDescriptor.putDouble(stringIDToTypeID("y"), y);
	panZoomDescriptor.putDouble(stringIDToTypeID("z"), z); //zoom
	panZoomDescriptor.putBoolean(stringIDToTypeID("resize"), false); //resize window
	panZoomDescriptor.putBoolean(stringIDToTypeID("animate"), settings.animateZoom); //animate zoom
	executeAction(stringIDToTypeID("setPanZoom"), panZoomDescriptor);
}

Which should translate something like:

{
  _obj:"setPanZoom",
  x:0,
  y:0,
  z:2,
  resize: false,
  animate: true,
}

Don’t ask me what units are… I don’t remember :smiley: I think there is one more way to set it.

2 Likes

Thanks, I will try and see

I was trying to find the same thing a few days ago, I just wanted to add two buttons Zoom 100% and Fit to Screen. I never got an answer where I was looking but I did finally figure it out using Actions + Add Menu Items and Alchemist. Below is my code that is working for the two buttons I wanted. Hope it helps or points you in the right direction.

//////////////** ZOOM 100%

async function zoom100(){

const {app, core, action} = require(“photoshop”);
const batchPlay = action.batchPlay;

await require(“photoshop”).core.executeAsModal(async (executionControl, descriptor) => {

await batchPlay(
[
{
_obj: “select”,
_target: [
{
_ref: “menuItemClass”,
_enum: “menuItemType”,
_value: “actualPixels”
}
],
_options: {
dialogOptions: “dontDisplay”
}
}], {
modalBehavior: “wait”
});
});
}

//////////////** ZOOM FIT

async function zoomfit(){

  const {app, core, action} = require("photoshop");
  const batchPlay = action.batchPlay;
  
  await require("photoshop").core.executeAsModal(async (executionControl, descriptor) => {
  
  await batchPlay(
     [
        {
           _obj: "select",
           _target: [
              {
                 _ref: "menuItemClass",
                 _enum: "menuItemType",
                 _value: "fitOnScreen"
              }
           ],
           _options: {
              dialogOptions: "dontDisplay"
           }    
           }], {
       modalBehavior: "wait"
     });
  });

}

Glad you figured it out. This is what I was trying to convey in an earlier post as well.

So I was looking for exactly THIS today - Thanks!