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

HTML Panel Extendscript: Button run first script on first click and second script on second click

Explorer ,
Mar 03, 2020 Mar 03, 2020

Hey there!

Im trying to make a button that  runs a existing script which adds a 3dlut on first click.

The second click on the same button removes the 3dlut by another existing script.

The third click adds the Lut again...the fourth removes it again and so on.

I think a checkbox would be overcomplicated because of persistency over different documents?

 

By now i have two Buttons like "Pastel-Effect" and another one like "Undo".
Here i have the two simple functions to execute my scripts:

 

 

(function () {
    'use strict';

    var csInterface = new CSInterface();


    function init() {

        themeManager.init();

        $("#rempastel").click(function () {
            csInterface.evalScript('rempastel()');
        });
    }

    init();

}());

(function () {
    'use strict';

    var csInterface = new CSInterface();


    function init() {

        themeManager.init();

        $("#pastel").click(function () {
            csInterface.evalScript('pastel()');
        });
    }

    init();

}());

 

 

 

TOPICS
Actions and scripting
979
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
LEGEND ,
Mar 03, 2020 Mar 03, 2020

var flag = true;

button.onClick = function(){

    if(flag == true){

        flag = false;

        //do stuff

        }

    else{

        flag = true;

        //do different stuff

        }

    }

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
Explorer ,
Mar 03, 2020 Mar 03, 2020

Thank you Sir! I am new to js/jsx and i have still problems figuring out how to put things together although i´m trying hard to learn. What would the whole function look like when my functions are implemented?
I´m trying and trying but i still get errors with syntax and what not. I just might be too stupid and have to learn more basics but i just don´t get it.

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
LEGEND ,
Mar 03, 2020 Mar 03, 2020

That's just example Extendscript/ScriptUI syntax for how to make one button do multiple things. Use a variable to store state. You'll need to adapt it to your specific need.

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
Explorer ,
Mar 04, 2020 Mar 04, 2020

So in hostscript.jsx it should look like something like this?

function pastel(){

var flag = true;

button.onClick = function(){

    if(flag == true){

        flag = false;

        //do stuff
        
        doAction("Pastel","Action Set");

        }

    else{

        flag = true;

        //do different stuff

        activeDocument.layers.getByName("Pastel").remove();
        }

    }}
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 ,
Mar 04, 2020 Mar 04, 2020

Instead of the doAction you can use  Action Manager Code to run your external Scripts and pas the script parameters if the script is a Plug-in like Fit Image.  Or you doAction and the Action can run your external Script Using a Action just add one more item the need to be maintained distributed and installed,  You can eliminate the need for action by using Action Manager code to run the script with the button onclick function.

 

 

AdobeScriptAutomationScripts("Toggle10x10Guides", "undefined");
		
		function AdobeScriptAutomationScripts(javaScriptName, javaScriptMessage) {
			var descriptor = new ActionDescriptor();
			descriptor.putString( stringIDToTypeID( "javaScriptName" ), javaScriptName );
			descriptor.putString( stringIDToTypeID( "javaScriptMessage" ), javaScriptMessage );
			executeAction( stringIDToTypeID( "AdobeScriptAutomation Scripts" ), descriptor, DialogModes.NO );
		}

 

 

JJMack
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 ,
Mar 04, 2020 Mar 04, 2020
LATEST

Slightly different way of writing it:

 

var flag = true;

button.onClick = function(){

    flag = flag==false;

    if(flag){

        //do something 

        }

    else{

        //do something different 

        }

    }

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