Copy link to clipboard
Copied
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();
}());
Copy link to clipboard
Copied
var flag = true;
button.onClick = function(){
if(flag == true){
flag = false;
//do stuff
}
else{
flag = true;
//do different stuff
}
}
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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();
}
}}
Copy link to clipboard
Copied
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 );
}
Copy link to clipboard
Copied
Slightly different way of writing it:
var flag = true;
button.onClick = function(){
flag = flag==false;
if(flag){
//do something
}
else{
//do something different
}
}
Find more inspiration, events, and resources on the new Adobe Community
Explore Now