Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Refresh in a dialog box:

Contributor ,
Nov 16, 2017 Nov 16, 2017

Hello friends! Would it be possible to update a dialog box without having to close it and reopen it? I modified a script and made an example using two documents with different images:

#target photoshop;     

StartDialog();///Start Dialog

function StartDialog() {

app.bringToFront(); 

  Image.prototype.onDraw = function() {

      if (!this.image) return;

    var WH = this.size,

        wh = this.image.size,

        k = Math.min(WH[0] / wh[0], WH[1] / wh[1]),

        xy;

    //Resize proportionally:

         wh = [k * wh[0], k * wh[1]];

    //Align image

    xy = [(WH[0] - wh[0]) / 7, (WH[1] - wh[1]) /90];

    this.graphics.drawImage(this.image, xy[0], xy[1], wh[0], wh[1]);

    WH = wh = xy = null;

}

   function promoteBackgroundLayer() {

   var doc = activeDocument;

   var layers = doc.layers;

   var layer = layers[layers.length - 1];

   if (layer.isBackgroundLayer) {

   layer.name = 'Background';}

        }

        if (documents.length) {

   promoteBackgroundLayer();}

      

       /////////////////// 

if(documents.length) main();     

function main(){     

var OutputFolder =Folder(Folder.temp);   

if(!OutputFolder.exists) OutputFolder.create();   

var LayerName = activeDocument.activeLayer.name;     

dupLayers();     

app.activeDocument.trim(TrimType.TRANSPARENT);     

var saveFile = File(OutputFolder + "/temp.png");     

if(activeDocument.width > activeDocument.height){ 

activeDocument.resizeImage(UnitValue(150, "px"), undefined, undefined, ResampleMethod.BICUBIC); //196 x 235  

}else{ 

    activeDocument.resizeImage(undefined,UnitValue(227, "px"), undefined, ResampleMethod.BICUBIC); 

    } 

SavePNG(saveFile);     

app.activeDocument.close(SaveOptions.DONOTSAVECHANGES);      

function SavePNG(saveFile){     

    pngSaveOptions = new PNGSaveOptions();      

activeDocument.saveAs(saveFile, pngSaveOptions, true, Extension.LOWERCASE);      

}     

function dupLayers() {      

var desc143 = new ActionDescriptor();     

var ref73 = new ActionReference();     

ref73.putClass( charIDToTypeID('Dcmn') );     

desc143.putReference( charIDToTypeID('null'), ref73 );     

desc143.putString( charIDToTypeID('Nm  '), activeDocument.activeLayer.name );     

var ref74 = new ActionReference();     

ref74.putEnumerated( charIDToTypeID('Lyr '), charIDToTypeID('Ordn'), charIDToTypeID('Trgt') );     

desc143.putReference( charIDToTypeID('Usng'), ref74 );     

executeAction( charIDToTypeID('Mk  '), desc143, DialogModes.NO );

}

Dlg=new Window("dialog","My Dialog",[0,0,250,350],{closeButton: true});   

View=Dlg.add("panel",[20,20,230,270]);   

Thub=View.add("panel",[18,10,191,239]);   

Thub.graphics.backgroundColor = Thub.graphics.newBrush (Thub.graphics.BrushType.SOLID_COLOR,[0.75,0.75,0.75]);   

Thu_layer_image = Thub.add ("image", [-2,-5,185,233], File (saveFile));

Thu_layer_image.graphics.foregroundColor = Thu_layer_image.graphics.newPen (Thu_layer_image.graphics.PenType.SOLID_COLOR,[0,0,0], 1);   

nm_lay=Dlg.add("statictext",[70,270,250,310] ,LayerName);   

NextDoC = Dlg.add('button',[42,310,200,310],'Next Image Dialog',{name:'ok'}); 

/////////////

NextDoC.onClick = function() {

var descriptor = new ActionDescriptor();

var reference = new ActionReference();

reference.putOffset( stringIDToTypeID( "document" ), 1 );

descriptor.putReference( charIDToTypeID( "null" ), reference );

descriptor.putInteger( stringIDToTypeID( "documentID" ), 1691 );

executeAction( stringIDToTypeID( "select" ), descriptor, DialogModes.NO );

Dlg.close(); 

StartDialog(); ///Start Dialog

}

Dlg.center();   

Dlg.show(); 

}

My video shows that the images load, but only when the dialog box is executed again:

TOPICS
Actions and scripting
1.8K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Guide , Nov 16, 2017 Nov 16, 2017

Please try this.

#target photoshop;       

StartDialog();///Start Dialog 

function StartDialog() { 

   

app.bringToFront();   

  Image.prototype.onDraw = function() { 

      if (!this.image) return; 

    var WH = this.size, 

        wh = this.image.size, 

        k = Math.min(WH[0] / wh[0], WH[1] / wh[1]), 

        xy; 

    //Resize proportionally: 

         wh = [k * wh[0], k * wh[1]]; 

    //Align image 

    xy = [(WH[0] - wh[0]) / 7, (WH[1] - wh[1]) /90]; 

    this.graphics.drawImage(this.imag

...
Translate
Adobe
Guide ,
Nov 16, 2017 Nov 16, 2017

Please try this.

#target photoshop;       

StartDialog();///Start Dialog 

function StartDialog() { 

   

app.bringToFront();   

  Image.prototype.onDraw = function() { 

      if (!this.image) return; 

    var WH = this.size, 

        wh = this.image.size, 

        k = Math.min(WH[0] / wh[0], WH[1] / wh[1]), 

        xy; 

    //Resize proportionally: 

         wh = [k * wh[0], k * wh[1]]; 

    //Align image 

    xy = [(WH[0] - wh[0]) / 7, (WH[1] - wh[1]) /90]; 

    this.graphics.drawImage(this.image, xy[0], xy[1], wh[0], wh[1]); 

    WH = wh = xy = null; 

   function promoteBackgroundLayer() { 

   var doc = activeDocument; 

   var layers = doc.layers; 

   var layer = layers[layers.length - 1]; 

   if (layer.isBackgroundLayer) { 

   layer.name = 'Background';} 

        } 

        if (documents.length) { 

   promoteBackgroundLayer();} 

        

       ///////////////////   

if(documents.length) main();       

function main(){  

docCount=app.documents.length;

activeDoc=0;

activeDocument=app.documents[0];

getDup();

function getDup(){

var OutputFolder =Folder(Folder.temp);     

if(!OutputFolder.exists) OutputFolder.create();     

LayerName = activeDocument.activeLayer.name;       

dupLayers();       

//app.activeDocument.trim(TrimType.TRANSPARENT);       

saveFile = File(OutputFolder + "/temp.png");         

SavePNG(saveFile);       

app.activeDocument.close(SaveOptions.DONOTSAVECHANGES);        

}

function SavePNG(saveFile){       

    pngSaveOptions = new PNGSaveOptions();        

activeDocument.saveAs(saveFile, pngSaveOptions, true, Extension.LOWERCASE);        

}       

function dupLayers() {        

var desc143 = new ActionDescriptor();       

var ref73 = new ActionReference();       

ref73.putClass( charIDToTypeID('Dcmn') );       

desc143.putReference( charIDToTypeID('null'), ref73 );       

desc143.putString( charIDToTypeID('Nm  '), activeDocument.activeLayer.name );       

var ref74 = new ActionReference();       

ref74.putEnumerated( charIDToTypeID('Lyr '), charIDToTypeID('Ordn'), charIDToTypeID('Trgt') );       

desc143.putReference( charIDToTypeID('Usng'), ref74 );       

executeAction( charIDToTypeID('Mk  '), desc143, DialogModes.NO );  

}  

Dlg=new Window("dialog","My Dialog",undefined,{closeButton: true});       

Thub=Dlg.add("panel",undefined,"View");   

Thub.preferredSize=[200,300];

Thub.graphics.backgroundColor = Thub.graphics.newBrush (Thub.graphics.BrushType.SOLID_COLOR,[0.75,0.75,0.75]);     

Thu_layer_image = Thub.add ("image", undefined, File (saveFile));  

 

Thu_layer_image.graphics.foregroundColor = Thu_layer_image.graphics.newPen (Thu_layer_image.graphics.PenType.SOLID_COLOR,[0,0,0], 1);     

nm_lay=Dlg.add("statictext",undefined ,LayerName);     

nm_lay.preferredSize=[200,20];

 

NextDoC = Dlg.add('button',undefined,'Next Image Dialog',{name:'ok'}); 

close = Dlg.add('button',undefined,"Done");

///////////// 

close.onClick=function(){

    Dlg.close(0);

    }

NextDoC.onClick = function() { 

nextDoc = activeDoc + 1;

if(nextDoc >= docCount){

    nextDoc = 0;

    activeDoc=0;

    }else{

        activeDoc++;

        }

    $.writeln("Active Doc = " + activeDoc);

activeDocument=app.documents[activeDoc];

getDup();

Thu_layer_image.image=saveFile;

nm_lay.text=activeDocument.activeLayer.name;

Dlg.layout.layout(true);

//app.refresh();

Dlg.center();     

Dlg.show();   

}   

};

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Nov 16, 2017 Nov 16, 2017

Great! Once again, beautiful work SuperMerlin! I do not know if you also noticed a small bug, when I open the window with the second active document, it returns to the first displaying its respective thumbnail. But that was only a small remark of mine. You really are a magician. Thank you so much again.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Nov 18, 2017 Nov 18, 2017

I was looking for something similar to this for a project with thumbnail SuperMerlin! Could you explain me only which function only takes care of doing the refresh in the window without having to close it ?. This information will be critical. Thank you

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Nov 18, 2017 Nov 18, 2017

In this case it was:-

Thu_layer_image.image=saveFile;

In the NextDoC function.

As it updates the image file.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Nov 18, 2017 Nov 18, 2017
LATEST

Got it SuperMerlin! I did some testing here and it worked very well! Thank you very much, British friend.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines