Zoom on a layer in Photoshop with a button using CEP/JavaScript

143 views Asked by At

I'm developing an extension in Photoshop and I need to zoom in on a layer when the user clicks on a button.

To do this manually in Photoshop, I have to hold the Alt+Option keys and click on the layer in the Photoshop layer panelI want to zoom in on. (Crédits: https://www.youtube.com/watch?v=v7XkxH3aleM)

So I used the Script Listener plugin (https://helpx.adobe.com/photoshop/kb/downloadable-plugins-and-content.html#ScriptingListenerplugin) and got this in my log file but I get an error when I place it in my ExtendScript :

function ZoomOnTheNotePS() {
try {

    // =======================================================
    var idhostFocusChanged = stringIDToTypeID( "hostFocusChanged" );
    var desc70740 = new ActionDescriptor();
    var idactive = stringIDToTypeID( "active" );
    desc70740.putBoolean( idactive, true );
    var iddontRecord = stringIDToTypeID( "dontRecord" );
    desc70740.putBoolean( iddontRecord, true );
    var idforceNotify = stringIDToTypeID( "forceNotify" );
    desc70740.putBoolean( idforceNotify, true );
    executeAction( idhostFocusChanged, desc70740, DialogModes.NO );

    // =======================================================
    var idslct = charIDToTypeID( "slct" );
    var desc70741 = new ActionDescriptor();
    var idnull = charIDToTypeID( "null" );
        var ref11361 = new ActionReference();
        var idLyr = charIDToTypeID( "Lyr " );
        ref11361.putName( idLyr, "note_19_drawing_1" );
    desc70741.putReference( idnull, ref11361 );
    var idMkVs = charIDToTypeID( "MkVs" );
    desc70741.putBoolean( idMkVs, false );
    var idfullySelected = stringIDToTypeID( "fullySelected" );
    desc70741.putBoolean( idfullySelected, true );
    var idLyrI = charIDToTypeID( "LyrI" );
        var list12349 = new ActionList();
        list12349.putInteger( 5574 );
    desc70741.putList( idLyrI, list12349 );
    executeAction( idslct, desc70741, DialogModes.NO );

    // =======================================================
    var idhostFocusChanged = stringIDToTypeID( "hostFocusChanged" );
    var desc70742 = new ActionDescriptor();
    var idactive = stringIDToTypeID( "active" );
    desc70742.putBoolean( idactive, false );
    var iddontRecord = stringIDToTypeID( "dontRecord" );
    desc70742.putBoolean( iddontRecord, true );
    var idforceNotify = stringIDToTypeID( "forceNotify" );
    desc70742.putBoolean( idforceNotify, true );
    executeAction( idhostFocusChanged, desc70742, DialogModes.NO );

} catch(error) {
    alert(error);
    return;
}

}

error :

error 2

Do you have any idea why it doesn't work ? Or do you simply have another solution ? Thanks in advance !

1

There are 1 answers

0
Andrei I. Gere On

You can use app.runMenuItem(menuID) for that:

app.runMenuItem(charIDToTypeID("ZmIn"));
app.runMenuItem(charIDToTypeID("ZmOt"));

I found more menu IDs here: http://web.archive.org/web/20140121053819/http://www.pcpix.com/Photoshop/char.htm