0

I am here because I did not find solution.

Problem:

  • I have 3 artboards.
  • I need a script (or action) to "fit artboard on screen" or zoom in specific artboard.
  • There is a option in top menu panel/View/Fit artboard on screen. It works well when I use it with mouse click.

But:

  1. When I try to record the Action:
    • Click on use Insert Menu Item: Fit artboard on screen, press OK
    • Nothing is recorded in the action
  2. I also tried to click the menu item at View > Fit artboard on screen, but there is still nothing added to action panel during recording.
  3. The last thing I tried was to use the Scripting listener plugin but it didn't output working code for this action.
  4. I can record View > Fit on screen as an Action, which fots all 3 artboards on screen and I need to focus/zoom in/fit on screen just one artboard.

This is code for action "Fit on screen". How could it be edited for "Fit artboard on screen"? Or is there another way to get my problem solved? Thank you all!

    var desc12 = new ActionDescriptor();
    var idnull = charIDToTypeID( "null" );
        var ref3 = new ActionReference();
        var idMn = charIDToTypeID( "Mn  " );
        var idMnIt = charIDToTypeID( "MnIt" );
        var idFtOn = charIDToTypeID( "FtOn" );
        ref3.putEnumerated( idMn, idMnIt, idFtOn );
    desc12.putReference( idnull, ref3 );
executeAction( idslct, desc12, DialogModes.NO );
2
  • Char ID's are those 4 character strings in that code you posted and you can convert them to string ID's, which might give you a better idea of what they do. These are in the javascript reference PDF, but you got methods: stringIDToTypeID(), charIDToTypeID(), typeIDToCharID(), typeIDToStringID(), Unfortunately, you first need to convert to type id before you can convert to a string id: alert( typeIDToStringID(charIDToTypeID('FtOn')) );, which would return fitOnScreen. If I'm not totally wrong, that code is basically saying Action: Select From: menu > menuitem > fit on screen. – Joonas Jan 25 at 12:16
  • And you don't necessarily have to use character ID's in Action Manager code. Here's basically the same code you posted with the string id fitArtboardOnScreen. – Joonas Jan 25 at 12:28
1

You can record it as an Action in PS 2020 and later. Though you have to use Insert menu item... from the Action panel's flyout menu (corner menu).

I don't know the details, like if there's been bug reports or anything public, but I tested PS 2019, PS 2020, and PS 2021 and 2019 was the only version where that didn't work, so I'm assuming all earlier versions have this issue. My best guess is that it was fixed when View > Fit layer(s) on screen was added around PS 2020.

In a script (PS 2020+) you can simplify that code a bit and do:

app.runMenuItem( stringIDToTypeID('fitArtboardOnScreen') );

If this is a productivity thing, and not like an automated workflow thing, you can also Alt + left click the artboard name in the Layers panel to fit the artboard on the screen.

Layers Panel:

  1. Alt + left click on the artboard layer (artboard name) → will fit the artboard on the screen
  2. Alt + left click on an empty layer or Layer 0 → will fit all artboards on the screen (PS 2020+)
  3. Alt + left click on any other layer → will fit that layer on the screen (PS 2020+)
    • The action itself works on multiple layers, but you can only do one layer at a time this way

As a final thing, the Fit on screen javascript code can be shortened to the same runMenuItem command:

app.runMenuItem( stringIDToTypeID('fitOnScreen') );

Same goes for Fit layers on screen (PS 2020+)

app.runMenuItem( stringIDToTypeID('fitLayersOnScreen') );

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.