"DialogModes" problem with "executeAction"

Anyone, especially newbies, asking for help with Photoshop Scripting and Photoshop Automation - as opposed to those contributing to discussion about an aspect of Photoshop Scripting

Moderators: Tom, Kukurykus

xaero

"DialogModes" problem with "executeAction"

Post by xaero »

The following script works fine for me:
Code: Select allfunction process() {

    // Place=======================================================

        var idPlc = charIDToTypeID( "Plc " );
            var desc3 = new ActionDescriptor();
            var idnull = charIDToTypeID( "null" );
            desc3.putPath( idnull, new File( "D:\\test\\watermark_170x63.psd" ) ); //DialogModes.ALL模式下,文件地址无效,会让用户重新选取
            var idFTcs = charIDToTypeID( "FTcs" );
            var idQCSt = charIDToTypeID( "QCSt" );
            var idQcsa = charIDToTypeID( "Qcsa" );
            desc3.putEnumerated( idFTcs, idQCSt, idQcsa );
            var idOfst = charIDToTypeID( "Ofst" );
                var desc4 = new ActionDescriptor();
                var idHrzn = charIDToTypeID( "Hrzn" );
                var idPxl = charIDToTypeID( "#Pxl" );
                desc4.putUnitDouble( idHrzn, idPxl, 243.000000 );
                var idVrtc = charIDToTypeID( "Vrtc" );
                var idPxl = charIDToTypeID( "#Pxl" );
                desc4.putUnitDouble( idVrtc, idPxl, 168.000000 );
            var idOfst = charIDToTypeID( "Ofst" );
            desc3.putObject( idOfst, idOfst, desc4 );
        executeAction( idPlc, desc3, DialogModes.ALL );
 }

function go() {
    var openFolder = Folder("D:\\test");
        var fileList = openFolder.getFiles();
        for (i=0; i<fileList.length; i++){
            if (fileList instanceof File && fileList.hidden == false){
                open(fileList);
                var docRef = app.activeDocument;
                process();
            }
        }
}

//save original ruler units, then assign it to pixels
var PRESOLUTION = 72;
var startRulerUnits = app.preferences.rulerUnits;
var startTypeUnits = app.preferences.typeUnits;

app.preferences.rulerUnits = Units.PIXELS;
app.preferences.typeUnits = TypeUnits.PIXELS;

var title = "test";

res = "dialog{ \
text:'"+ title +"', \
    buttons: Group{orientation: 'row', alignment: 'right', \
                    Btnok: Button{text: 'GO', properties:{name: 'ok'}}, \
                    Btncancel: Button{text: 'Cancel', properties:{name: 'cancel'}} \
                    }, \
}";

//win = new Window(res);


go();


//取消按钮
/*
win.buttons.Btncancel.onClick = function(){
    app.preferences.rulerUnits = startRulerUnits;
    app.preferences.typeUnits = startTypeUnits;
    this.close();
}
//确定按钮
win.buttons.Btnok.onClick = function() {
    this.parent.parent.close();
    go();
}*/

//win.center();
//win.show();
Pay attention:
There should be some JPEG files under D:\test\.
With "DialogModes.ALL" of the "executeAction", I CAN move the watermark_170x63.psd to everywhere freely.


BUT, With the following script, I CAN'T move the watermark_170x63.psd anymore! I just put a simple User Interface dialog before the script running.

WHY? how to move the watermark_170x63.psd freely with UI dialog?
Code: Select allfunction process() {

    // Place=======================================================

        var idPlc = charIDToTypeID( "Plc " );
            var desc3 = new ActionDescriptor();
            var idnull = charIDToTypeID( "null" );
            desc3.putPath( idnull, new File( "D:\\taobao\\watermark\\watermark_170x63.psd" ) ); //DialogModes.ALL模式下,文件地址无效,会让用户重新选取
            var idFTcs = charIDToTypeID( "FTcs" );
            var idQCSt = charIDToTypeID( "QCSt" );
            var idQcsa = charIDToTypeID( "Qcsa" );
            desc3.putEnumerated( idFTcs, idQCSt, idQcsa );
            var idOfst = charIDToTypeID( "Ofst" );
                var desc4 = new ActionDescriptor();
                var idHrzn = charIDToTypeID( "Hrzn" );
                var idPxl = charIDToTypeID( "#Pxl" );
                desc4.putUnitDouble( idHrzn, idPxl, 243.000000 );
                var idVrtc = charIDToTypeID( "Vrtc" );
                var idPxl = charIDToTypeID( "#Pxl" );
                desc4.putUnitDouble( idVrtc, idPxl, 168.000000 );
            var idOfst = charIDToTypeID( "Ofst" );
            desc3.putObject( idOfst, idOfst, desc4 );
        executeAction( idPlc, desc3, DialogModes.ALL );


    // Flatten=======================================================
    var idFltI = charIDToTypeID( "FltI" );
    executeAction( idFltI, undefined, DialogModes.NO );
 }

function go() {
    var openFolder = Folder("D:\\taobao\\ps工具\\test");
        var fileList = openFolder.getFiles();
        for (i=0; i<fileList.length; i++){
            if (fileList instanceof File && fileList.hidden == false){
                open(fileList);
                var docRef = app.activeDocument;
                process();
            }
        }
}

//save original ruler units, then assign it to pixels
var PRESOLUTION = 72;
var startRulerUnits = app.preferences.rulerUnits;
var startTypeUnits = app.preferences.typeUnits;

app.preferences.rulerUnits = Units.PIXELS;
app.preferences.typeUnits = TypeUnits.PIXELS;

var title = "test";

res = "dialog{ \
text:'"+ title +"', \
    buttons: Group{orientation: 'row', alignment: 'right', \
                    Btnok: Button{text: '开始', properties:{name: 'ok'}}, \
                    Btncancel: Button{text: '取消', properties:{name: 'cancel'}} \
                    }, \
}";

win = new Window(res);

//go();

//cancel

win.buttons.Btncancel.onClick = function(){
    app.preferences.rulerUnits = startRulerUnits;
    app.preferences.typeUnits = startTypeUnits;
    this.parent.parent.close();
}
//GO
win.buttons.Btnok.onClick = function() {
    this.parent.parent.close();
    go();
}

win.center();
win.show();

Professional AI Audio Generation within Adobe Premiere Pro - Download Free Plugin here

Mike Hale

"DialogModes" problem with "executeAction"

Post by Mike Hale »

I did not try to run your script so there may be other problems but I think the reason it will not work is because dialogs in Photoshop are modal. Meaning that you can not interact with Photoshop while the dialog is running. You can only interact with the dialog.

You could move the go() function call from the bntok.onClick to after the win.show(). If you only want to call go() if the user clicks on the ok button you can wrap that line in an if statement that checks the results of win.show().
xaero

"DialogModes" problem with "executeAction"

Post by xaero »

Am I right? it can't work
Code: Select all...
win = new Window(res);
win.center();
win.show();

//GO
win.buttons.Btnok.onClick = function() {
    if (win.show()) {
        go();
        win.close();
    }
}
Mike Hale

"DialogModes" problem with "executeAction"

Post by Mike Hale »

No, it will not work as part of the dialog. You need to call the function after the dialog closes.Code: Select all...
win = new Window(res);
win.buttons.Btnok.onClick = function() { win.close();}
win.center();
var result = win.show();
if(result == 1){// if user clicks on the 'ok' button
     //GO
     go();
}

If you must have the user interface showing while transforming you could create a custom panel using the CS-SDK. But that it much more involved than ScriptUI.
xaero

"DialogModes" problem with "executeAction"

Post by xaero »

Thanks a lot! It works!
but the return value of win.show() is 0 not 1...

Code: Select all...
win = new Window(res);

win.buttons.Btnok.onClick = function() {
    win.close();
}

win.center();
var result = win.show();
//alert(result);
if (result == 0) { //only could work with zero not 1
    go();
}