ScriptUI Panel update or redraw graphics

Find out why the . goes before the /

Moderator: Paul Tuersley

Post Reply
bouncingkeys
Posts: 5
Joined: May 1st, 2015, 2:07 pm

Hi,
I am having a problem redrawing the graphics in a panel group. What I need is when I press a button, the currently drawn graphics to be cleared/disappear and the new to appear. This is what I have:

Code: Select all

var ctr = 0;
var win = new Window('palette', appName+ver, [100, 100, 330, 410], {resizeable: true});
win.graphics.backgroundColor = win.graphics.newBrush(win.graphics.BrushType.SOLID_COLOR, [0.2, 0.2, 0.2]);
win.ctl_group1 = win.add('panel', [10, 5, 220,200], 'Group 1', { borderStyle: "etched" });
win.ctl_group1.onDraw = redraw;
win.ctl_button1 = win.add('button', [5, 200, 141, 228], 'APPLY');  
win.ctl_button1.onClick = function(){
          win.ctl_group1.onDraw.call();
 };
function redraw()
        {
            ctr++;
            var gfx = this.graphics;
            var pen;
            if(ctr == 1)
            {
                pen = this.graphics.newPen (this.graphics.PenType.SOLID_COLOR, [.5, .6, .7, 1], 2);
                gfx.newPath();			/* outer frame */
                gfx.moveTo(0, 0);
                gfx.lineTo(200, 0);
                gfx.lineTo(200, 200);
                gfx.lineTo(0, 200);
                gfx.lineTo(0, 0);
                gfx.strokePath(pen);
                }
           if(ctr > 1)
          {
                pen = this.graphics.newPen (this.graphics.PenType.SOLID_COLOR, [.6, .7, .8, 1], 1);
                gfx.newPath();			/* inner frame */
                gfx.moveTo(20, 20); 
                gfx.lineTo(180, 20); 
                gfx.lineTo(180, 180); 
                gfx.lineTo(20, 180);
                gfx.lineTo(20, 20); 
                gfx.strokePath(pen);
            }
         
         }
When I launch this, the first rectangle is drawn normally, but when I press apply the second rectangle doesn't appear, and the old one doesn't get cleared.
Do you know of a working method that can clear the whole panel from the current graphics and start clean?

Thanks
Kiril
beginUndoGroup
Posts: 81
Joined: November 27th, 2012, 6:41 am

You can try this:

win.ctl_button1.onClick = function(){
var s = win.ctl_group1.size; win.ctl_group1.size=[s[0], s[1]+1]; win.ctl_group1.size=[s[0], s[1]];
};

For me it works, but it might not for you.
If you want more info, check the Adobe scripting forum for InDesign with keywords "onDraw", or "force redraw", something like this.
I can't remember where i read it, by you can't call onDraw anymore in CS6 and CC, it is ignored.
In addition, redeclaring the same size doesnt work in CC (it does in CS6) so you have to (*) change it and back (*maybe not, but i dont know how)

Xavier.
bouncingkeys
Posts: 5
Joined: May 1st, 2015, 2:07 pm

Hi Xavier and sorry for the late answer!
Works like a charm :)
beginUndoGroup
Posts: 81
Joined: November 27th, 2012, 6:41 am

Ok cool.

Be aware that with this "method", onDraw will be called twice, so i'd rather put the ctr increment part somewhere else than in the onDraw function itself.
Post Reply