View Palette

Engaged ,
Aug 03, 2022 Aug 03, 2022

Copy link to clipboard

Copied

Hello everyone, everything good?
I'm trying to create a script that has two types of dialog boxes, a main and a second window, which when opened I can manipulate the elements of the main window. The solution would be a palette-type window, but I have no idea how to make it stay open when executed.
Is there any chance this pallete will be visible when executed? Thanks.

dlg = new Window("palette"); 
dlg.text = "Dialog"; 
dlg.orientation = "column"; 
dlg.alignChildren = ["center","top"]; 

array=[];
p1 = dlg.add("panel", undefined, undefined, {name: "p1"}); 
p1.text = "Panel"; 
p1.preferredSize.width = 150; 
p1.orientation = "column"; 
p1.alignChildren = ["left","top"]; 
p1.spacing = 10; 
p1.margins = 10; 

var valor = 25.00;
b1 = dlg.add("button", undefined, undefined, {name: "b1"}); 
b1.text = "Adicionar"; 
b1.preferredSize.width = 150; 

adiconar();
b2 = dlg.add("button", undefined, undefined, {name: "b2"}); 
b2.text = "Somar"; 
b2.preferredSize.width = 150; 

dlg.layout.layout (true);
b1.onClick = function(){
adiconar();
}

function adiconar(){
    t1 = p1.add("Button"); t1.text = "✔ Moldura 1 : R$ " + valor;
    array.push([ t1.text.split("R$")[1] ]);
    dlg.layout.layout (true);
}

b2.onClick = function(){
	var soma_total = 0;
	for (i = 0; i < array.length; i++) {
		soma_total += Number(array[i]);
		}
    b2.text ="R$: "+ soma_total.toFixed(2).replace('.', ',').replace(/(\d)(?=(\d{3})+(?!\d))/g, '$1.');
}

dlg.show();
TOPICS
Actions and scripting

Views

68

Likes

Translate

Translate

Report

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

Adobe Community Professional , Aug 03, 2022 Aug 03, 2022

Likes

Translate

Translate
Adobe Community Professional ,
Aug 03, 2022 Aug 03, 2022

Copy link to clipboard

Copied

Likes

Translate

Translate

Report

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 ,
Aug 03, 2022 Aug 03, 2022

Copy link to clipboard

Copied

@jazz-y  Thanks! You are a genius! The palette worked fine, however I tried to run the palette by clicking a button in the main dialog and I noticed that the palette only opens when the main window is closed, the idea would be to keep both of them open. You as a great genius that you are, would you know of any method that I can fix this?

var dialog = new Window("dialog"); 
dialog.text = "Dialog"; 
dialog.orientation = "column"; 
dialog.alignChildren = ["center","top"]; 
dialog.spacing = 10; 
dialog.margins = 16; 

var button1 = dialog.add("button", undefined, undefined, {name: "button1"}); 
button1.text = "Button"; 

button1.onClick = function(){adicionar_mais()}

dialog.show();




function adicionar_mais(){

	var bt = new BridgeTalk(); 
	bt.target = "photoshop"; 
	bt.body = "var palette = " + fn.toString() + "; palette();"
	bt.send(); 

	function fn () {
		dlg = new Window("palette",  undefined, undefined, {closeButton:true}); 
		dlg.text = "Dialog"; 
		dlg.orientation = "column"; 
		dlg.alignChildren = ["center","top"]; 

		array=[];
		p1 = dlg.add("panel", undefined, undefined, {name: "p1"}); 
		p1.text = "Panel"; 
		p1.preferredSize.width = 150; 
		p1.orientation = "column"; 
		p1.alignChildren = ["left","top"]; 
		p1.spacing = 10; 
		p1.margins = 10; 

		var valor = 25.00;
		b1 = dlg.add("button", undefined, undefined, {name: "b1"}); 
		b1.text = "Adicionar"; 
		b1.preferredSize.width = 150; 

		adiconar();
		b2 = dlg.add("button", undefined, undefined, {name: "b2"}); 
		b2.text = "Somar"; 
		b2.preferredSize.width = 150; 

		dlg.layout.layout (true);
		b1.onClick = function(){
		adiconar();
		}

		function adiconar(){
			t1 = p1.add("Button"); t1.text = "✔ Moldura 1 : R$ " + valor;
			array.push([ t1.text.split("R$")[1] ]);
			dlg.layout.layout (true);
		}

		b2.onClick = function(){
			var soma_total = 0;
			for (i = 0; i < array.length; i++) {
				soma_total += Number(array[i]);
				}
			b2.text ="R$: "+ soma_total.toFixed(2).replace('.', ',').replace(/(\d)(?=(\d{3})+(?!\d))/g, '$1.');
		}

		dlg.show();
	}


}

Likes

Translate

Translate

Report

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 Professional ,
Aug 11, 2022 Aug 11, 2022

Copy link to clipboard

Copied

Using a window in palette mode has certain limitations. You can try to start both windows in this mode, but it seems to me that it is easier to change interface logic so that there is no need to interact with two windows at the same time.

var bt = new BridgeTalk();
bt.target = "photoshop";
bt.body = "var palette = " + fn.toString() + "; palette();"
bt.send();
function fn() {
    var dialog = new Window("palette", undefined, undefined, { closeButton: true });
    dialog.text = "Dialog";
    dialog.orientation = "column";
    dialog.alignChildren = ["center", "top"];
    dialog.spacing = 10;
    dialog.margins = 16;
    var button1 = dialog.add("button", undefined, undefined, { name: "button1" });
    button1.text = "Button";
    button1.onClick = function () { adicionar_mais() };
    dialog.show();
    function adicionar_mais() {
        var bt = new BridgeTalk();
        bt.target = "photoshop";
        bt.body = "var palette = " + fn.toString() + "; palette();"
        bt.send();
        function fn() {
            dlg = new Window("dialog", undefined, undefined, { closeButton: true });
            dlg.text = "Dialog";
            dlg.orientation = "column";
            dlg.alignChildren = ["center", "top"];
            array = [];
            p1 = dlg.add("panel", undefined, undefined, { name: "p1" });
            p1.text = "Panel";
            p1.preferredSize.width = 150;
            p1.orientation = "column";
            p1.alignChildren = ["left", "top"];
            p1.spacing = 10;
            p1.margins = 10;
            var valor = 25.00;
            b1 = dlg.add("button", undefined, undefined, { name: "b1" });
            b1.text = "Adicionar";
            b1.preferredSize.width = 150;
            adiconar();
            b2 = dlg.add("button", undefined, undefined, { name: "b2" });
            b2.text = "Somar";
            b2.preferredSize.width = 150;
            dlg.layout.layout(true);
            b1.onClick = function () {
                adiconar();
            }
            function adiconar() {
                t1 = p1.add("Button"); t1.text = "✔ Moldura 1 : R$ " + valor;
                array.push([t1.text.split("R$")[1]]);
                dlg.layout.layout(true);
            }
            b2.onClick = function () {
                var soma_total = 0;
                for (i = 0; i < array.length; i++) {
                    soma_total += Number(array[i]);
                }
                b2.text = "R$: " + soma_total.toFixed(2).replace('.', ',').replace(/(\d)(?=(\d{3})+(?!\d))/g, '$1.');
            }
            dlg.show();
        }
    }
}

 

Likes

Translate

Translate

Report

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 ,
Aug 12, 2022 Aug 12, 2022

Copy link to clipboard

Copied

LATEST

@jazz-y thanks for kindly fulfilling my request.

Likes

Translate

Translate

Report

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