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

Add thumbnail to the user interface.

Contributor ,
Nov 06, 2017 Nov 06, 2017

Hello everyone! How do I view the thumbnail of the active layer in a "ScriptUI" user interface?

thumbnail size 196 x 235 px

Is there any possibility? Thank you.

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

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

Thub=View.add("panel",[10,10,196,235]);

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

Thu_layer=Thub.add("statictext",[40,90,160,130] ,"Thumbnail On here",{multiline:true});

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

nm_lay=Dlg.add("statictext",[20,290,85,310] ,"Name layer",{multiline:true});

id_lay=Dlg.add("edittext",[85,287,225,307] ,"   Active Layer");

Dlg.center();

Dlg.show();

TOPICS
Actions and scripting
1.1K
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 06, 2017 Nov 06, 2017

Might be a bit slow!

#target photoshop;   

app.bringToFront();

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, Resample

...
Translate
Adobe
Guide ,
Nov 06, 2017 Nov 06, 2017

Might be a bit slow!

#target photoshop;   

app.bringToFront();

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(199, "px"), undefined, ResampleMethod.BICUBIC);

    }

SavePNG(saveFile);   

app.activeDocument.close(SaveOptions.DONOTSAVECHANGES);    

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

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

Thub=View.add("panel",[10,10,196,235]); 

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

Thu_layer_image = Thub.add ("image", [1,1,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",[20,290,85,310] ,LayerName,{multiline:true}); 

id_lay=Dlg.add("edittext",[85,287,225,307] ,"   Active Layer"); 

Dlg.center(); 

Dlg.show(); 

}

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 );   

};

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 06, 2017 Nov 06, 2017

Ours, great! SuperMerlin here worked very well. When I did not find it slow, it was ideal for me. Congratulations

Only you allow me! How do I align the thumbnail to the top on the gray panel?

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
Guide ,
Nov 06, 2017 Nov 06, 2017

I wish I knew, I have tried but failed to get it to the top, maybe someone can help with this?

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 06, 2017 Nov 06, 2017

SuperMerlin  escreveu

I wish I knew, I have tried but failed to get it to the top, maybe someone can help with this?

I was able to align the thumbnail to the top thanks to an article on page 69 of this manual: http://www.kahrel.plus.com/indesign/scriptui.html

Just add this script to line 3

  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]) / 2, (WH[1] - wh[1]) /90];

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

    WH = wh = xy = null;

}

With some adjustments I was able to line up at the top.

#target photoshop;     

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]) / 2, (WH[1] - wh[1]) /90];

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

    WH = wh = xy = null;

}

 

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);      

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

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

Thub=View.add("panel",[10,10,196,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",[20,290,85,310] ,"ID Layer",{multiline:true});   

id_lay=Dlg.add("edittext",[85,287,225,307] ,LayerName," Active Layer");   

Dlg.center();   

Dlg.show();   

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 );

}

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
Advocate ,
Nov 07, 2017 Nov 07, 2017

a question

and if I want to see more thumbnails of selected layers

the user interface.

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 08, 2017 Nov 08, 2017
LATEST

If you select more that one layer, it will merge then into one file. If you wanted to view each layer in turn that was selected then that would get very complex.

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