I’m creating a component that makes a button. The component takes as a parameter the function to be executed when the button is pressed and creates a sp-action-button that performs that action when pressed.
in this example the function dBCurve() is received by the component as paramter “FunctionToBeExecuted” and should be launched, from inside the component, via photoshop.core.executeAsModal () to which in turn is passed as a parameter . The name of the function that should be executed is dBCurve () which the ActionButton component handles as the FunctionToBeExecuted parameter passing it again as a parameter to require(“photoshop”).core.executeAsModal(()
Unfortunately, however, the dBCurve () function is not performed whan passed as a parameter to photoshop.core.executeAsModal () . The ActionButton component works correctly (verified via UI) and correctly receives the dBCurve () parameter as the name of the function to be executed (verified via log) but the function correctly passed as a parameter to the component and passed by it as a parameter to photoshop.core.executeAsModal () is not executed
If, on the other hand, photoshop.core.executeAsModal () is executed in the same component by directly inserting the name of the function to execute, that is to say, dBCurve (), instead of the FunctionToBeExecuted parameter which represents dBCurve (), the dBCurve () function is executed correctly when the button is pressed.
This is the code. Do you have any suggestion ?
import { dBCurve } from "../../../utilities/Photoshop/Trasversali/DodgeBurn"
const ActionButton = ( {FunctionToBeExecuted, children} ) => {
console.log("ActionButton executeAsmodal should execute parameter..." + FunctionToBeExecuted ) // log confirm parameter is OK !!
const clickHandler = async () => {
await require("photoshop").core.executeAsModal(() => FunctionToBeExecuted ) // DOESN'T WORKS
await require("photoshop").core.executeAsModal(() => dBCurve() ) // WORKS
}
return (
<sp-action-button onClick={clickHandler}>
{ children }
</sp-action-button>
); //
}
export default ActionButton;
This is the piece of code that activates the ActionButton component by passing it the name of the function to execute, i.e. dBcurve ()
<ActionButton FunctionToBeExecuted="dBCurve()" >Test myActionButton</ActionButton>
Thanks in advance for your kind reply
I have tried all your suggestions, in all possible combinations but it still doesn’t work: nothing happen, there is no message in the console and the program flow continue executing the following instructions (the instructions following the executeModal instruction, that has no effect)
I have tried both passing dBCurve() or just dBCurve in both the executeAsModal ways that you suggested (that I would consider correct) but in all cases nothing happen
I’m pretty sure that there is no problem in dBcurve() because it is properly executed, as I wrote in the first post, when directly launched via await require(“photoshop”).core.executeAsModal(() => dBCurve() within the same component for testing purposes. Layers are created as supposed and console confirm execution through the message that I’m sending to the console for the purpose. The problem arise when dBcurve() - with or without brackets - is passed as a FunctionToBeExecuted paramenter to executeAsModal (whatever of the two differnt syntax that you kindly suggested)
I confirm that there is only one message in the console, related to the rendering of ActionButton
In both these cases only a string is being passed, isn’t it? Not sure how this should execute the function then. I’d write it in curly brackets to pass the variable reference (pointing to the function), instead of a string.
@Trasatti Btw, if something isn’t working as expected and nothing is logged by default, just log the batchPlay result (and maybe also put it in a try/catch). You would’ve immediately found the issue then:
I’ ve now modified the function dbCurve() to accept a parameter representing the blend mode of the layer to be created (tested; it works properly when called from outside the component)
If I’m not going too far with asking… I would be happy to know how I should modify the two working instructions above so that the instruction