Copy link to clipboard
Copied
Good day dear audience!
Recently I asked how to pass a variable from JavaScript to JSX.
Re: How to pass a variable from js to jsx?
The user r-bin was offered a wonderful simple solution. Now I have the exact opposite question. How to pass a variable from JSX in JavaScript?
The forum has found a much-needed script.
And slightly altered it for their needs:
var idgaussianBlur = stringIDToTypeID( "gaussianBlur" );
var desc6 = new ActionDescriptor();
var idradius = stringIDToTypeID( "radius" );
var idpixelsUnit = stringIDToTypeID( "pixelsUnit" );
desc6.putUnitDouble( idradius, idpixelsUnit, 30.000000 );
var returnD = executeAction( idgaussianBlur, desc6, DialogModes.ALL );
var rad = returnD.getUnitDoubleValue(idradius);
How to pass a rad variable in JavaScript?
Thank you in advance for any help.
1 Correct answer
By analogy with my past example
in JS
$("#rgb_c").button().click(function(a){ csInterface.evalScript('$.evalFile("'+extensionRoot+'tools/RGB.jsx"); func_in_jsx();', function f(x) { alert(x); } );
in RGB.jsx
// some code
// some code
// some code
// some code
function func_in_jsx() { return 123; }
Checked, works.
Explore related tutorials & articles
Copy link to clipboard
Copied
You may save it to .txt file by .jsx and then read from that. txt file by .js.
Copy link to clipboard
Copied
Thank you, but could you write an example? Unfortunately, I do not know the scripts to do it myself.
Copy link to clipboard
Copied
For .jsx it would be:
v = 'value', (fle = File('~/desktop/.txt')).open('w'), fle.write(v), fle.close()
For .js it would be (however I don't know it will work, but in .jsx it does):
(fle = File('~/desktop/.txt')).open('r'), r = fle.read(), fle.close(), alert(r)
Ps. probably alert() in .js won't work, but I'm not sure.
Copy link to clipboard
Copied
Tried. In JSX, it works. Thank you for way to, very use to anyone in the future. But JS unfortunately doesn't work.
Copy link to clipboard
Copied
By analogy with my past example
in JS
$("#rgb_c").button().click(function(a){ csInterface.evalScript('$.evalFile("'+extensionRoot+'tools/RGB.jsx"); func_in_jsx();', function f(x) { alert(x); } );
in RGB.jsx
// some code
// some code
// some code
// some code
function func_in_jsx() { return 123; }
Checked, works.
Copy link to clipboard
Copied
I'm sorry, but... It's not working. Repeated all one in one. At the end of the script error appears: EvalScript error
Copy link to clipboard
Copied
Everything works. Show the button code
You need to use $.evalFile instead of $._ ext.evalFile
Copy link to clipboard
Copied
That's exactly what I did. It doesn't. It gives an error. If you substitute a number instead of X in alert, a window with a number appears. And it's not working. And I totally understand where it does come from X?
Copy link to clipboard
Copied
X is the argument of a function. Why "substitute"?
It is equal to the value returned by func_in_jsx().in JSX
And you can already use it (X) inside JS
ЗЫ. надеюсь понял )
Copy link to clipboard
Copied
I beg your pardon. I'm an idiot. Did everything as You wrote, well, the way I was JSXBIN file is edited JSX )))))))
I put:
function func_in_jsx() { return 123; };
at the very end of the JSX script. In the last line.
Here is a fragment of my JS which I remade on the recommendation:
$("#res_tex").button().click(function(a) {
csInterface.evalScript('$.evalFile("' + extensionRoot + 'work/Restoration_Skin_Texture_v3_2_Simple.jsx"); func_in_jsx();', function f(x) {alert(x);})
});
Other than that, I posted:
function func_in_jsx() { return 123; };
inside JSX functions. Apparently, as the wrong. I'll deal with it myself from now on.
And so, everything works fine. Thank you very much! That's exactly what I need. Thank you so much for two great tools for sharing variables between JS and JSX!!!
Copy link to clipboard
Copied
Use the search. I found a solution in this forum, although I do not understand anything in extensions.
Copy link to clipboard
Copied
Is that really the only way to communicate between the two? Seems inefficient to serialize that way.

