Skip to main content
matias.kiviniemi
Legend
June 16, 2015
Question

Photoshop CC 2015 changes to scripting

  • June 16, 2015
  • 18 replies
  • 15470 views

It's again the time of year that Adobe releases a new version with some new "features" so I was thinking we should share issues to minimize time on debugger

  • Greatly improved Javascript performance, I'd say at least 2-3x improvement in my scripts, Kudos Adobe
  • Dialogs are much more responsive and change updates immediatelly. However in my end loop (waiting for user to click OK) dialog became unresponsive and hanged Photoshop. Needed to add app.refresh() in the loop (but don't use in script as it has great performance impact).

So far looking looking good, but please share if you discover some changes

This topic has been closed for replies.

18 replies

Inspiring
June 25, 2015

When I was writing the ContactSheetII.jsx, the Quality Control people at Adobe were very, very specific about keystroke filters so I learned a lot about them writing up the code.

JJMack
Community Expert
Community Expert
June 26, 2015

X there seems to be a big difference as to how ContactSheetII  UI works in CC 2015 and CC 2014 with some of the input fields it that because of the eventlistener code? The change seem to be in the panel. The CC 2014 version run in cc 2015 still seem to filter some of the numeric input fields not allow character be entered..

I use Mike Hale code for handling numeric input fields in several script and now that way does not work in CC 2015.   Your CC 2014 version of contacsheetII handles in CC 2015 some of your dialogs fields the way I want to.  However I do not know JavaScript only hack at it and I do not understand how your CC 2014 code works.

Could you please do me a favor a post a simple dialog that only allows numeric data to be entered into its input field that will work in CC 2015 and CC 2014.

I like the immediate feedback and not having to check if is not numeric and then have to putout a message and then re-display the dialog.  For that way I need to restructure my poor hacks.

Here the code Mike posted that no longer works in CC 2015  the keydown event handler is never triggered

function NumericEditKeyboardHandler (event) {

    try {

        var keyIsOK = KeyIsNumeric (event) || 

                      KeyIsDelete (event) || 

                      KeyIsLRArrow (event) ||

                      KeyIsTabEnterEscape (event);

                      

        if (! keyIsOK) {

            //    Bad input: tell ScriptUI not to accept the keydown event

            event.preventDefault();

            /*    Notify user of invalid input: make sure NOT

                to put up an alert dialog or do anything which

                requires user interaction, because that

                interferes with preventing the 'default'

                action for the keydown event */

            app.beep();

        }

    }

    catch (e) {

        ; // alert ("Ack! bug in NumericEditKeyboardHandler: " + e);

    }

}

//    key identifier functions

function KeyIsNumeric ( event ) {

    return  ( event.keyName >= '0' ) && ( event.keyName <= '9' ) && ! KeyHasModifier ( event );

}

function KeyHasModifier ( event ) {

    return event.shiftKey || event.ctrlKey || event.altKey || event.metaKey;

}

function KeyIsDelete (event) {

    //    Shift-delete is ok

    return (event.keyName == 'Backspace') && ! (event.ctrlKey);

}

function KeyIsLRArrow (event) {

    return ((event.keyName == 'Left') || (event.keyName == 'Right')) && ! (event.altKey || event.metaKey);

}

function KeyIsTabEnterEscape (event) {

    return event.keyName == 'Tab' || event.keyName == 'Enter' || event.keyName == 'Escape';

}

function createDialog( ) {

    var dlg = new Window( 'dialog', 'Example Dialog' );

    dlg.maskSt = dlg.add( 'edittext', undefined, '' );

    dlg.maskSt.preferredSize.width = 40;

    dlg.maskSt.addEventListener ('keydown', NumericEditKeyboardHandler );

   dlg.btnPnl = dlg.add( 'panel', undefined, 'Process' );

   dlg.btnPnl.orientation = "row";

   dlg.btnPnl.alignment = "right";

   dlg.btnPnl.okBtn = dlg.btnPnl.add( 'button', undefined, 'Ok', { name:'ok' });

   dlg.btnPnl.cancelBtn = dlg.btnPnl.add( 'button', undefined, 'Cancel', { name:'cancel' });

   return dlg;

};

function initializeDialog( w ) {

    w.maskSt.addEventListener ('keydown', NumericEditKeyboardHandler );

    w.maskSt.onChanging = function() {

                                    // range check if needed

                                        if( Number(this.text) < 0 || Number(this.text) > 100 ){

                                            alert('Out of range');

                                            // handle however you like

                                            this.text = '';

                                        }

                                    }

    w.btnPnl.okBtn.onClick = function ( ) { this.parent.parent.close( 1 ); };

    w.btnPnl.cancelBtn.onClick = function ( ) { this.parent.parent.close( 2 ); };

};

runDialog = function( w ) {

   return w.show( );

};

var win = createDialog();

initializeDialog( win );

runDialog( win );

JJMack
Inspiring
June 26, 2015

X there seems to be a big difference as to how ContactSheetII  UI works in CC 2015 and CC 2014 with some of the input fields it that because of the eventlistener code? The change seem to be in the panel. The CC 2014 version run in cc 2015 still seem to filter some of the numeric input fields not allow character be entered..

CSII is Adobe's baby, now. I haven't been keeping up with it at all. But since you have brought this up, I'll take a look at this. We will probably have to file a bug report but I would like to have a solution ready before then.

My main focus these days is CSX, xtools, and Image Processor  Pro.

Could you please do me a favor a post a simple dialog that only allows numeric data to be entered into its input field that will work in CC 2015 and CC 2014.

If/when I figure out what's going on here, I'll post an example that works for CS5 to CC2015 which is what I try to support in my scripts.

Chuck Uebele
Community Expert
Community Expert
June 23, 2015

Were eventlisteners mentioned? I've got one attached to a tabbed panel that controls all the enable features of the the various checkboxes etc. That's not working.

JJMack
Community Expert
Community Expert
June 25, 2015

In my PastImageRoll script I used code I took from Mike Hale web post for handling keyboard events.   The code does not seemed to be triggered in CC 2015.

It was like the handlers that are in the Fit Image plug-in sctipt that have been commented out since CS6.   They work for me in PasteImageRoll up to CC 2015 but not in CC 2015.

// do not allow anything except for numbers 0-9

RollPaperDialog.PrintResPnl.docResEdt.addEventListener ('keydown', NumericEditKeyboardHandler);

RollPaperDialog.PrintResPnl.imgCpysEdt.addEventListener ('keydown', NumericEditKeyboardHandler);

RollPaperDialog.PaperSizePnl.aspectWidthEdt.addEventListener ('keydown', DesmalEditKeyboardHandler);

RollPaperDialog.PaperSizePnl.aspectHeightEdt.addEventListener ('keydown', DesmalEditKeyboardHandler);

RollPaperDialog.CellSizePnl.aspectWidthEdt.addEventListener ('keydown', DesmalEditKeyboardHandler);

RollPaperDialog.CellSizePnl.aspectHeightEdt.addEventListener ('keydown', DesmalEditKeyboardHandler);

RollPaperDialog.GroutSizePnl.aspectWidthEdt.addEventListener ('keydown', DesmalEditKeyboardHandler);

RollPaperDialog.GroutSizePnl.aspectHeightEdt.addEventListener ('keydown', DesmalEditKeyboardHandler);

Seems there are many things like this commented out in Adobe scripts supplied with Photoshop.  In contactsheetII   I see X now use code like this make me almost want to learn scripting

//

// Function: addNumericFilter

// Description: Adds a numeric keystroke filter to a widget

// Input:  obj - UI widget

// Return: <none>

//

ContactSheetUI.addNumericFilter = function(obj) {

  obj.keyFilter = /\d/;

  obj.addEventListener('keydown', ContactSheetUI.filterKey);

};

//

// Function: addNumberFilter

// Description: Adds a number/localized-decimal-point keystroke filter

// Input:  obj - UI widget

// Return: <none>

//

ContactSheetUI.addNumberFilter = function(obj) {

  obj.keyFilter = RegExp("[\\-" + psxui.dpREStr + "\\d]");

  obj.addEventListener('keydown', ContactSheetUI.filterKey);

};

//

// Function: addPositiveNumberFilter

// Description: Adds a positive number/localized-decimal-point keystroke filter

// Input:  obj - UI widget

// Return: <none>

//

ContactSheetUI.addPositiveNumberFilter = function(obj) {

  obj.keyFilter = RegExp("[" + psxui.dpREStr + "\\d]");

  obj.addEventListener('keydown', ContactSheetUI.filterKey);

};

JJMack
Participating Frequently
June 23, 2015

CC2015 also seems to have broken ScriptUI.environment.keyboardState.

Reported here: Photoshop CC2015 has broken Script UI Keyboard state object

Andreas Jansson
Inspiring
June 18, 2015

Photoshop object model disappeared from the Object Model Viewer ( OMV) for me, when installing Photoshop 2015. Is that the case for other scripters? Please open ExtendScript ToolKit CC and check for Photoshop in the list.

Also see: Photoshop missing in Object Model Viewer (ExtendScript ToolKit CC) after installing 2015 CC for a screen shot.

y.fujisawa
Inspiring
June 18, 2015

Window.find('xxxx').close() doesn't work on my code.

Participating Frequently
June 17, 2015

So far I've run into these issues:

- Photoshop CC2015 on Win7 crashes instantly when an extension runs a jsx to draw a window or palette using script UI. The same script works perfect when being run from ExtendScript instead of from the extension. Also, if I just briefly run any script that draws a script UI window (either from ExtendScript or from File->Scripts) then the extension works without any crashes... until next time PS is restarted. Vote for the support ticket here: PS CC2015 (win7) crashes instantly when extension uses script UI

- Seems there is a change in what kind of error dialogs are shown. Stdlib.convertToSmartLayer() now results in an error saying "The object 'layer 394 of document 5932' is not currently available". This is caused in Stdlib.wrapLCLayer() when it tries to reselect the layer and it's not available. It can be avoided by using app.displayDialogs = DialogModes.NO

/ Rune

Inspiring
June 17, 2015

A similar problem popped up a few versions ago which was solved by adding an app.refresh() or Stdlib.waitForRedraw(). I'll add an exception handler in and put your DialogModes.NO work-around in wrapLCLayer.

I'll do a push of xtools to the CVS tree on SourceForge later this week and a full release after the dust settles on the PS/CC2015 release. I've already dropped in changes for CC2015 elsewhere in xtools that will be included in that refresh.

Inspiring
June 18, 2015

I pushed my current xtools environment out to SourceForge that includes the wrapLCLayer() fix and all of my CC2015 and other mods. I'll packaged up a beta zip later in the week.

DBarranca
Legend
June 16, 2015

Don't forget the new Mondo rendering engine for Scripts!!

---

(Ops, had the message window open for a long time and posted this not noticing it's been already mentioned in the thread. I'll be collecting Mondo discrepancies vs the previous ScriptUI engine and report here!)

Davide Barranca

DBarranca
Legend
June 16, 2015

Speaking of Mondo, JPGs can't be loaded anymore in ScriptUI dialogs:

var w = new Window ("dialog", "Bouquet");

var flowers = w.add ("image", undefined, File ("~/Desktop/Fiore.jpg"));

w.show ();

Invalid Image Data error - only PNGs - hopefully this is going to be fixed.

Davide

Chuck Uebele
Community Expert
Community Expert
June 16, 2015

Umm, I've always used pngs, just for the transparency.

Inspiring
June 16, 2015

Notes on PS2015/JS:

- The underlying UI engine has changed which is the reason for all that is new and/or different.

- ScriptUI is very much faster. Not sure about the actual DOM side.

- Some script's UIs will break. I have some serious issues RadioButtons. [Reported]

- UI widgets have been 'adjusted' which means layout will be off a bit or a lot depending on what you are doing. Auto-layout may or may not be affected.

- Centering palette windows with multiple monitors centers relative to the bounding box of the monitors, not to the active/current monitor. [Reported]

- I have a version of Image Processor Pro in development that will crash PS after running the script and simply hitting the Cancel button.

  This appears to be happening as the window is being deconstructed. This only happens on Win7. [Reported]

- There may still be JS syntax or runtime errors that are not recognized. By this, I mean the script just terminates without an error dialog. [Reported]

Ex:

if (|| true) {

  alert('true');

}

will (occasionally) run without incident but throw an error on CC2014 and CS6.

I've filed bugs for all of these and the good people at Adobe are aware of them.

If anybody finds additional bugs, please post them in this thread and report them here: Adobe - Feature Request/Bug Report Form

Edited for clarity.

Chuck Uebele
Community Expert
Community Expert
June 16, 2015

I was having issue with radio buttons too. They would not work unless they were in a group. I got a note that said that it was fixed, but haven't checked yet. the new UI size does mess up some of my scripts. Would love to have a scroll bar on the UI.

JJMack
Community Expert
Community Expert
June 16, 2015

Adobe documented something in what new on that.

Photoshop Help | Photoshop UI toolkit for plug-ins and scripts

UI Layout

There are no changes in the scripting APIs for creating user interfaces. However, there is a difference in the way the grouping widget works.

In Flex, the “group” widget used to act as layout mechanism for grouping widgets and used to be completely invisible itself. Now, “group” is itself a widget with its own background and can’t overlap with other widgets.

For instance, if we have two groups arranged one over the other with widgets in each group such that widgets from one group do not overlap with widgets in the other group, all widgets are visible in Flex.

Group widget - Flex


However, in the new framework, in the same scenario, the group at the top hides the group at the bottom.

Group widget - New framework


Note:

Some users may find that their existing scripts have incorrect UI layout in the new framework because of this same reason. All such scripts should be modified by removing overlaps in the “group” widgets. Scripts created afresh in the new framework or modified to run in it work fine in Flex as well.

JJMack