cs2 force screen redraw

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

Patrick

cs2 force screen redraw

Post by Patrick »

I made a dialog box with a slider, and have it set to perform a selection on the open document whenever the slider is change to allow the user to tweak the selection before clicking ok. The problem is, the screen does not redraw while my dialog box is open so all I see is a gray document.

Is there any function or method I can implement to force a screen redraw? I would like the user to be able to see the full document while the dialog box is floating over if possible. Thanks in advance,

Patrick
Mike Hale

cs2 force screen redraw

Post by Mike Hale »

I'm unsure of this but you can try setting the playback options in the action palette to step by step.

If you are trying to let the user see the change in the selection you may also want to change the control from edittext to slider. I think that would be easier for the user to adjust the tolerance. The min and max values for tolerance are 0 and 255.

Or you can wait for Larry Ligon to check in, he is much better at dialogs that I am.
Larry Ligon

cs2 force screen redraw

Post by Larry Ligon »

Are you trying to run the script in the debugger, ExtendScript Toolkit? Stuff like this won't work when run in the debugger. If not, post your code here and I'll take a look at it.

Try to run it normally in Photoshop. Outside the debugger.
Patrick

cs2 force screen redraw

Post by Patrick »

Thanks for the replies guys. Larry, I was doing it from the debugger - I just ran it from photshop directly and it does not grey out the image anymore, however I am still unable to see the selection. A few minutes ago I was playing with combining the code I came up with at home last night with what I made at work yesterday, and at one point had it where I could see the selection under the popup -- now I can't figure out what I did to make it go away . Below is my code, any ideas you guys have would be appreciated.

Code: Select all// reference open document
var docRef = app.activeDocument;

// function pulled from script listener to use the magic wand
function wand(x,y,tol,option)
{
   // options:
   // setd = initial selection
   // AddT = add to selection

var id9466 = charIDToTypeID( option );
    var desc1828 = new ActionDescriptor();
    var id9467 = charIDToTypeID( "null" );
        var ref1340 = new ActionReference();
        var id9468 = charIDToTypeID( "Chnl" );
        var id9469 = charIDToTypeID( "fsel" );
        ref1340.putProperty( id9468, id9469 );
    desc1828.putReference( id9467, ref1340 );
    var id9470 = charIDToTypeID( "T   " );
        var desc1829 = new ActionDescriptor();
        var id9471 = charIDToTypeID( "Hrzn" );
        var id9472 = charIDToTypeID( "#Pxl" );
        desc1829.putUnitDouble( id9471, id9472, x );
        var id9473 = charIDToTypeID( "Vrtc" );
        var id9474 = charIDToTypeID( "#Pxl" );
        desc1829.putUnitDouble( id9473, id9474, y );
    var id9475 = charIDToTypeID( "Pnt " );
    desc1828.putObject( id9470, id9475, desc1829 );
    var id9476 = charIDToTypeID( "Tlrn" );
    desc1828.putInteger( id9476, tol );
    var id9477 = charIDToTypeID( "AntA" );
    desc1828.putBoolean( id9477, true );
executeAction( id9466, desc1828, DialogModes.NO );
};

function wandPopUp()
{
   var startTol = 20;
   wand(50,50,startTol,"setd");
   
   // build dialog window
   var win = new Window(
   "dialog{text:'Erase Background',bounds:[100,100,300,230],\
      button0:Button{bounds:[50,90,150,110] , text:'OK' },\
      statictext0:StaticText{bounds:[20,20,140,37] , text:'Magic Wand Tolerance' ,properties:{scrolling:undefined,multiline:undefined}},\
      edittext0:EditText{bounds:[150,20,175,37] , text:'" +  startTol +"' ,properties:{multiline:false,noecho:false,readonly:false}},\
      slider0:Slider{bounds:[20,60,180,70] , minvalue:1,maxvalue:100,value:" + startTol +"}\
   };");

   // update text on slider change
   win.slider0.onChanging = function() {
      var v = Math.floor(this.value);
      this.parent.edittext0.text = v;
   };

   // update slider on text change
   win.edittext0.onChanging = function() {
      var v = parseInt(this.text);
      if ( v >= 1 && v <= 100) {
         this.parent.slider0.value = v;
      }
   };

   // make selection after slider change
   win.slider0.onChange = function() {
      var v = Math.floor(this.value);
      docRef.selection.deselect();
      wand(50,50,v,"setd");
   };


   // show the dialog window
   win.center();
   win.show();

   // clean dialog result for after the function
   usertol = win.slider0.value.toFixed(0);
};

wandPopUp();

Regards,
Patrick


EDIT - just a update, after reading Mike's post again I turned it from accelerated to step-by-step in playback options, now it works exactly like I was wanting.
xbytor

cs2 force screen redraw

Post by xbytor »

Here's a bit of code that I've used for waiting for redraws.

Code: Select allcTID = function(s) { return app.charIDToTypeID(s); };

waitForRedraw = function() {
  var desc = new ActionDescriptor();
  desc.putEnumerated(cTID("Stte"), cTID("Stte"), cTID("RdCm"));
  executeAction(cTID("Wait"), desc, DialogModes.NO)
};

-X
Patrick

cs2 force screen redraw

Post by Patrick »

Thanks X, that function should definitely prove helpful in the future.
Timo Autiokari

cs2 force screen redraw

Post by Timo Autiokari »

When a dialog is open in such way that it appears on top of a doc and then the dialog is moved, then the waitForRedraw does not help, I tried it like:

alarmdlg.onMove = function(){
alert ("alarm box was moved");
waitForRedraw();
}

From the alert I know that it goes there when I move the alarmdlg but the Redraw does not happen. So what I have on the screen is a rectangle inside the doc that looks like Opacity 0% in that place where the alarmdlg had been. Not nice.

So, an unconditional Redraw would be very nice to have.

Thanks,
Timo Autiokari
Mike Hale

cs2 force screen redraw

Post by Mike Hale »

That is strange. On my system the screen redraws when I move a dialog that is over the image.
xbytor

cs2 force screen redraw

Post by xbytor »

Don't forget that the Action Playback mode also has an effect on screen redraws. You get (almost) always get redraws in Step-by-step mode and almost never in Accelerated mode.

-X
Mike Hale

cs2 force screen redraw

Post by Mike Hale »

Hi X,

My play back option is set to accelerated and the screen is still refreshed when I move a dialog that is over an image.

But you are right in that while most scripts are running, that is not waiting on a dialog, the screen is not refreshed.