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

I'm stuck in my first script

New Here ,
Oct 28, 2024 Oct 28, 2024

Good morning, I am a brand new user of Extendscript toolkit and I am stuck in my first script, I want to save an image in Photoshop by entering the first and last name of the author as well as the choice and type of competition in the final file. I'm stuck because in my drop-down lists I can't retrieve my information but only the chronological position of two lists. I need a serious helping hand. Attached is the blocking part of the s

<
/*
    Création d'une boite de dialogue pour  identifier l'auteur et le choixs des concours
    */
// DIALOG
// ======
var nom;
var prenom;  
var choix ;
var type;



var dialog = new Window("dialog"); 
    dialog.text = "Redimentionnement pour concours F.F de Photographie"; 
    dialog.orientation = "row"; 
    dialog.alignChildren = ["left","top"]; 
    dialog.spacing = 10; 
    dialog.margins = 16; 

// GROUP1
// ======
var group1 = dialog.add("group", undefined, {name: "group1"}); 
    group1.orientation = "column"; 
    group1.alignChildren = ["fill","top"]; 
    group1.spacing = 10; 
    group1.margins = 0; 

// PANEL1
// ======
var panel1 = group1.add("panel", undefined, undefined, {name: "panel1"}); 
    panel1.text = "Auteur"; 
    panel1.preferredSize.height = 150; 
    panel1.orientation = "column"; 
    panel1.alignChildren = ["left","top"]; 
    panel1.spacing = 10; 
    panel1.margins = 10; 
 

var statictext1 = panel1.add("statictext", undefined, undefined, {name: "statictext1"}); 
    statictext1.text = "Entrez votre nom"; 
   var edittext1 = panel1.add('edittext {properties: {name: "edittext1"}}'); 
    edittext1.text = " "; 
    edittext1.preferredSize.width = 120; 
    edittext1.preferredSize.height = 23; 
var statictext2 = panel1.add("statictext", undefined, undefined, {name: "statictext2"}); 
    statictext2.text = "Entrez votre prénom"; 
var edittext2 = panel1.add('edittext {properties: {name: "edittext2"}}'); 
    edittext2.text = " "; 
    edittext2.preferredSize.width = 120; 
    edittext2.preferredSize.height = 23; 


// GROUP3
// ======
var group3 = dialog.add("group", undefined, {name: "group3"}); 
    group3.orientation = "column"; 
    group3.alignChildren = ["fill","top"]; 
    group3.spacing = 10; 
    group3.margins = 0; 

// PANEL2
// ======
var panel2 = group3.add("panel", undefined, undefined, {name: "panel2"}); 
    panel2.text = "Chois des concours"; 
    panel2.preferredSize.height = 150; 
    panel2.orientation = "column"; 
    panel2.alignChildren = ["fill","top"]; 
    panel2.spacing = 10; 
    panel2.margins = 10; 

var statictext2 = panel2.add("statictext", undefined, undefined, {name: "statictext2"}); 
    statictext2.text = "Couleur / Noir et blanc"; 
var dropdown1_array = ["Couleur","N/B"]; 
var dropdown1 = panel2.add("dropdownlist", undefined, undefined, {name: "dropdown1", items: dropdown1_array}); 
   dropdown1.selection = " ";
    
    
 var statictext3 = panel2.add("statictext", undefined, undefined, {name: "statictext3"}); 
    statictext3.text = "Type de concours"; 
var dropdown2_array = ["Portrait","Macro","Paysage"]; 
var dropdown2 = panel2.add("dropdownlist", undefined, undefined, {name: "dropdown2", items: dropdown2_array}); 
   dropdown2.selection = 0; 

// GROUP4
// ======
var group4 = dialog.add("group", undefined, {name: "group4"}); 
    group4.orientation = "column"; 
    group4.alignChildren = ["fill","top"]; 
    group4.spacing = 10; 
    group4.margins = 0; 

    var button1 = group4.add("button", undefined, undefined, {name: "ok"}); 
    button1.text = "OK"; 
    var button2 = group4.add("button", undefined, undefined, {name: "cancel"}); 
    button2.text = "Cancel"; 
    
    

dialog.show();

    var nom=edittext1.text;
    var prenom=edittext2.text;  
    var choix1=dropdown1.selection;
    var  choix2=dropdown2.selection;
    alert(choix1);

>

cript. Translation carried out with Google because I did not find support in France Thank you for your help

249
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
Adobe
Community Expert ,
Oct 28, 2024 Oct 28, 2024

in the future, to find the best place to post your message, use the list here, https://community.adobe.com/

p.s. i don't think the adobe website, and forums in particular, are easy to navigate, so don't spend a lot of time searching that forum list. do your best and we'll move the post (like this one has already been moved) if it helps you get responses.



<"moved from using the community">
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
Community Expert ,
Oct 28, 2024 Oct 28, 2024

@andr�_4582 

 

Please provide full code, a working snippet or at least a screenshot of the working interface.

 

My view and advice is to separate this into two steps:

 

Scripting the underlying process would be my first goal.

 

Adding a scriptUI would be a second step.

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
New Here ,
Oct 30, 2024 Oct 30, 2024

Thank Stephen you for your help, after several searches on the Internet I managed to get my script to work but not in the right way. I use "myReturn = dialog.show ()" to save my information but I want to use button1 to carry out this operation and button2 to exit cleanly from the script. Can you help me with the onClick function on the action of these two buttons. I am attaching the entire script as well as the screenshot of the interface.

AndrewCapture d'écran 2024-10-30 081201.png

 

//
// ============SCRIPT DE REDIMENSIONNEMENT POUR CONCOURS CLUB ============// 

var nom;
var prenom;  
var choix ;
var type;


app.preferences.rulerUnits = Units.PIXELS;			// L'uniti de base sera le pixel
app.displayDialogs = DialogModes.NO;				// Le script est muet


// Vérifie la présence d'un document ouvert et lui donne un nom
var nbr = documents.length; 
if (nbr == 0) 
    { 
     alert("Vous devez d'abord ouvrir un fichier"); 
    } 
else

//
// ==============Dimension  Maximale (hauteur ou largeur) fixié dans DimMax	
//
var DimMaxH =1920;
var DimMaxL =1920;

 
//
//============== Récupération de côtes de l'image et calcul du ratio
//
     var largeur = app.activeDocument.width.value;
	var hauteur = app.activeDocument.height.value;
    MonImage = app.activeDocument;
    
 //   
//============= J'applique les nouvelles dimentions  avec une résolution de 120 et en respectant le Ratio. 
//
    if ((app.activeDocument.width/app.activeDocument.height >= 1) && (largeur>DimMaxL)){
		//mode paysage ou carré on prend en référence la largeur
           //alert("Boucle Horzontale");
           var Ratio = (DimMaxH/largeur);
           MonImage.resizeImage (largeur*Ratio,hauteur*Ratio ,120,ResampleMethod.BICUBIC);
      }
	else
    
    
     if ((app.activeDocument.width/app.activeDocument.height < 1) && (hauteur>DimMaxH)){
		//mode portrait; on prend en référence la hauteur
         //alert("Boucle Verticale"); 
         var Ratio = (DimMaxH/hauteur);
         MonImage.resizeImage (largeur*Ratio,hauteur*Ratio ,120,ResampleMethod.BICUBIC);
      }
     else
     
     
    if((largeur<DimMaxL) && (hauteur<DimMaxH))
     //Si l'image est en dessous de la dimensions 
      {
       MonImage.resizeImage = app.activeDocument;
      }
    
        
      
   

//    Création d'une boite de dialogue pour  identifier l'auteur et le choixs des concours
  
// DIALOG
// ======



var dialog = new Window("dialog"); 
    dialog.text = "Redimentionnement pour concours F.F de Photographie"; 
    dialog.orientation = "row"; 
    dialog.alignChildren = ["left","top"]; 
    dialog.spacing = 10; 
    dialog.margins = 16; 

// GROUP1
// ======
var group1 = dialog.add("group", undefined, {name: "group1"}); 
    group1.orientation = "column"; 
    group1.alignChildren = ["fill","top"]; 
    group1.spacing = 10; 
    group1.margins = 0; 

// Panneau Non et Prénom
// ======
var panel1 = group1.add("panel", undefined, undefined, {name: "panel1"}); 
    panel1.text = "Auteur"; 
    panel1.preferredSize.height = 150; 
    panel1.orientation = "column"; 
    panel1.alignChildren = ["left","top"]; 
    panel1.spacing = 10; 
    panel1.margins = 10; 
 

var statictext1 = panel1.add("statictext", undefined, undefined, {name: "statictext1"}); 
    statictext1.text = "Entrez votre nom"; 
   var edittext1 = panel1.add('edittext {properties: {name: "edittext1"}}'); 
    edittext1.text = " "; 
    edittext1.preferredSize.width = 120; 
    edittext1.preferredSize.height = 23; 
var statictext2 = panel1.add("statictext", undefined, undefined, {name: "statictext2"}); 
    statictext2.text = "Entrez votre prénom"; 
var edittext2 = panel1.add('edittext {properties: {name: "edittext2"}}'); 
    edittext2.text = " "; 
    edittext2.preferredSize.width = 120; 
    edittext2.preferredSize.height = 23; 


// Groupe concours
// ======
var group3 = dialog.add("group", undefined, {name: "group3"}); 
    group3.orientation = "column"; 
    group3.alignChildren = ["fill","top"]; 
    group3.spacing = 10; 
    group3.margins = 0; 

// Panneau Choix et Type de concours
// ======
var panel2 = group3.add("panel", undefined, undefined, {name: "panel2"}); 
    panel2.text = "Chois des concours"; 
    panel2.preferredSize.height = 150; 
    panel2.orientation = "column"; 
    panel2.alignChildren = ["fill","top"]; 
    panel2.spacing = 10; 
    panel2.margins = 10; 

var statictext2 = panel2.add("statictext", undefined, undefined, {name: "statictext2"}); 
    statictext2.text = "Couleur / Monochrome"; 
var dropdown1_array = ["Couleur","Monochrome"]; 
var dropdown1 = panel2.add("dropdownlist", undefined, undefined, {name: "dropdown1", items: dropdown1_array}); 
   dropdown1.selection = " ";
    
    
 var statictext3 = panel2.add("statictext", undefined, undefined, {name: "statictext3"}); 
    statictext3.text = "Type de concours"; 
var dropdown2_array = ["Papier","Papier Nature","Nature Image Projetée ","Image Projetée","Concours Auteurs"]; 
var dropdown2 = panel2.add("dropdownlist", undefined, undefined, {name: "dropdown2", items: dropdown2_array}); 
   dropdown2.selection = " "; 

// Groupe Validation ou Abandon
// ======
var group4 = dialog.add("group", undefined, {name: "group4"}); 
    group4.orientation = "column"; 
    group4.alignChildren = ["fill","top"]; 
    group4.spacing = 10; 
    group4.margins = 0; 

    var button1 = group4.add("button", undefined, undefined, {name: "ok"}); 
    button1.text = "OK"; 
    var button2 = group4.add("button", undefined, undefined, {name: "cancel"}); 
    button2.text = "Cancel"; 
    
  myReturn = dialog.show(); 

 if (myReturn == 1)
{
  var nom = edittext1.text   
  var prenom = edittext2.text
  var choix = dropdown1.selection; 
  var type = dropdown2.selection; 
  alert(nom+"__"+prenom+"__"+[choix]+"__"+[type]+".JPEG","Enregistrement du Fichier");
  nouvDocument = (nom+"__"+prenom+"__"+[choix]+"__"+[type]+".jpg");
  
}



var dossier = Folder.selectDialog("Selectionner le Dossier pour l'enregistremnt");
var docRef = activeDocument
var dossierDoc = dossier+"/"+nouvDocument

      jpegOptions = new JPEGSaveOptions(); 
      jpegOptions.quality = 12;
     jpegOptions.embedColorProfile = true; 
     jpegOptions.formatOptions = FormatOptions.STANDARDBASELINE;  
     jpegOptions.matte = MatteType.NONE;
     docRef.saveAs(new File(dossier + "/"+nouvDocument), jpegOptions);
    app.activeDocument.close(SaveOptions.DONOTSAVECHANGES);  
   
   
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
Community Expert ,
Oct 30, 2024 Oct 30, 2024
LATEST

@andr�_4582 

 

I’m not really good with ScriptUI, so I created some "simplified" examples of the standard dialogs in Photoshop such as confirm() to try to understand the process of linking things up to the buttons:

 

https://github.com/MarshySwamp/ScriptUI-Confirm-Window

 

See if that makes sense to you, looking at the comments.

 

You just need to move everything at the bottom into the if block, you don't even need the else block, I just put it there for clarity.

 

I used part of that for your script, changing everything from line 156 onwards:

 

//
// ============SCRIPT DE REDIMENSIONNEMENT POUR CONCOURS CLUB ============// 

var nom;
var prenom;  
var choix ;
var type;


app.preferences.rulerUnits = Units.PIXELS;			// L'uniti de base sera le pixel
app.displayDialogs = DialogModes.NO;				// Le script est muet


// Vérifie la présence d'un document ouvert et lui donne un nom
var nbr = documents.length; 
if (nbr == 0) 
    { 
     alert("Vous devez d'abord ouvrir un fichier"); 
    } 
else

//
// ==============Dimension  Maximale (hauteur ou largeur) fixié dans DimMax	
//
var DimMaxH =1920;
var DimMaxL =1920;

 
//
//============== Récupération de côtes de l'image et calcul du ratio
//
     var largeur = app.activeDocument.width.value;
	var hauteur = app.activeDocument.height.value;
    MonImage = app.activeDocument;
    
 //   
//============= J'applique les nouvelles dimentions  avec une résolution de 120 et en respectant le Ratio. 
//
    if ((app.activeDocument.width/app.activeDocument.height >= 1) && (largeur>DimMaxL)){
		//mode paysage ou carré on prend en référence la largeur
           //alert("Boucle Horzontale");
           var Ratio = (DimMaxH/largeur);
           MonImage.resizeImage (largeur*Ratio,hauteur*Ratio ,120,ResampleMethod.BICUBIC);
      }
	else
    
    
     if ((app.activeDocument.width/app.activeDocument.height < 1) && (hauteur>DimMaxH)){
		//mode portrait; on prend en référence la hauteur
         //alert("Boucle Verticale"); 
         var Ratio = (DimMaxH/hauteur);
         MonImage.resizeImage (largeur*Ratio,hauteur*Ratio ,120,ResampleMethod.BICUBIC);
      }
     else
     
     
    if((largeur<DimMaxL) && (hauteur<DimMaxH))
     //Si l'image est en dessous de la dimensions 
      {
       MonImage.resizeImage = app.activeDocument;
      }
    
        
      
   

//    Création d'une boite de dialogue pour  identifier l'auteur et le choixs des concours
  
// DIALOG
// ======



var dialog = new Window("dialog"); 
    dialog.text = "Redimentionnement pour concours F.F de Photographie"; 
    dialog.orientation = "row"; 
    dialog.alignChildren = ["left","top"]; 
    dialog.spacing = 10; 
    dialog.margins = 16; 

// GROUP1
// ======
var group1 = dialog.add("group", undefined, {name: "group1"}); 
    group1.orientation = "column"; 
    group1.alignChildren = ["fill","top"]; 
    group1.spacing = 10; 
    group1.margins = 0; 

// Panneau Non et Prénom
// ======
var panel1 = group1.add("panel", undefined, undefined, {name: "panel1"}); 
    panel1.text = "Auteur"; 
    panel1.preferredSize.height = 150; 
    panel1.orientation = "column"; 
    panel1.alignChildren = ["left","top"]; 
    panel1.spacing = 10; 
    panel1.margins = 10; 
 

var statictext1 = panel1.add("statictext", undefined, undefined, {name: "statictext1"}); 
    statictext1.text = "Entrez votre nom"; 
   var edittext1 = panel1.add('edittext {properties: {name: "edittext1"}}'); 
    edittext1.text = " "; 
    edittext1.preferredSize.width = 120; 
    edittext1.preferredSize.height = 23; 
var statictext2 = panel1.add("statictext", undefined, undefined, {name: "statictext2"}); 
    statictext2.text = "Entrez votre prénom"; 
var edittext2 = panel1.add('edittext {properties: {name: "edittext2"}}'); 
    edittext2.text = " "; 
    edittext2.preferredSize.width = 120; 
    edittext2.preferredSize.height = 23; 


// Groupe concours
// ======
var group3 = dialog.add("group", undefined, {name: "group3"}); 
    group3.orientation = "column"; 
    group3.alignChildren = ["fill","top"]; 
    group3.spacing = 10; 
    group3.margins = 0; 

// Panneau Choix et Type de concours
// ======
var panel2 = group3.add("panel", undefined, undefined, {name: "panel2"}); 
    panel2.text = "Chois des concours"; 
    panel2.preferredSize.height = 150; 
    panel2.orientation = "column"; 
    panel2.alignChildren = ["fill","top"]; 
    panel2.spacing = 10; 
    panel2.margins = 10; 

var statictext2 = panel2.add("statictext", undefined, undefined, {name: "statictext2"}); 
    statictext2.text = "Couleur / Monochrome"; 
var dropdown1_array = ["Couleur","Monochrome"]; 
var dropdown1 = panel2.add("dropdownlist", undefined, undefined, {name: "dropdown1", items: dropdown1_array}); 
   dropdown1.selection = " ";
    
    
 var statictext3 = panel2.add("statictext", undefined, undefined, {name: "statictext3"}); 
    statictext3.text = "Type de concours"; 
var dropdown2_array = ["Papier","Papier Nature","Nature Image Projetée ","Image Projetée","Concours Auteurs"]; 
var dropdown2 = panel2.add("dropdownlist", undefined, undefined, {name: "dropdown2", items: dropdown2_array}); 
   dropdown2.selection = " "; 

// Groupe Validation ou Abandon
// ======
var group4 = dialog.add("group", undefined, {name: "group4"}); 
    group4.orientation = "column"; 
    group4.alignChildren = ["fill","top"]; 
    group4.spacing = 10; 
    group4.margins = 0; 

    var button1 = group4.add("button", undefined, undefined, {name: "ok"}); 
    button1.text = "OK"; 
    var button2 = group4.add("button", undefined, undefined, {name: "cancel"}); 
    button2.text = "Cancel"; 
    
  

// Groupe Validation ou Abandon
// ======
if (dialog.show() === 1) {

    var nom = edittext1.text
    var prenom = edittext2.text
    var choix = dropdown1.selection;
    var type = dropdown2.selection;
    alert(nom + "__" + prenom + "__" + [choix] + "__" + [type] + ".JPEG", "Enregistrement du Fichier");
    nouvDocument = (nom + "__" + prenom + "__" + [choix] + "__" + [type] + ".jpg");

    var dossier = Folder.selectDialog("Selectionner le Dossier pour l'enregistremnt");
    var docRef = activeDocument
    var dossierDoc = dossier + "/" + nouvDocument

    jpegOptions = new JPEGSaveOptions();
    jpegOptions.quality = 12;
    jpegOptions.embedColorProfile = true;
    jpegOptions.formatOptions = FormatOptions.STANDARDBASELINE;
    jpegOptions.matte = MatteType.NONE;
    docRef.saveAs(new File(dossier + "/" + nouvDocument), jpegOptions);
    app.activeDocument.close(SaveOptions.DONOTSAVECHANGES); 

} else {
    alert("Script cancelled!");
}

 

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