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

How to pass a variable from JSX in JavaScript

Explorer ,
Aug 29, 2018 Aug 29, 2018

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.

How to call the Gaussian Blur filter dialog window using JavaScript? applyGaussianBlur() method does...

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.

TOPICS
Actions and scripting
2.7K
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

correct answers 1 Correct answer

People's Champ , Aug 29, 2018 Aug 29, 2018

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.

Translate
Adobe
LEGEND ,
Aug 29, 2018 Aug 29, 2018

You may save it to .txt file by .jsx and then read from that. txt file by .js.

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 ,
Aug 29, 2018 Aug 29, 2018

Thank you, but could you write an example? Unfortunately, I do not know the scripts to do it myself.

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 ,
Aug 29, 2018 Aug 29, 2018

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.

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 ,
Aug 29, 2018 Aug 29, 2018

Tried. In JSX, it works. Thank you for way to, very use to anyone in the future. But JS unfortunately doesn't work.

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
People's Champ ,
Aug 29, 2018 Aug 29, 2018

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.

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 ,
Aug 30, 2018 Aug 30, 2018

I'm sorry, but... It's not working. Repeated all one in one. At the end of the script error appears: EvalScript error

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
People's Champ ,
Aug 30, 2018 Aug 30, 2018

Everything works. Show the button code
You need to use $.evalFile instead of $._ ext.evalFile

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 ,
Aug 30, 2018 Aug 30, 2018

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?

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
People's Champ ,
Aug 30, 2018 Aug 30, 2018

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

ЗЫ. надеюсь понял )

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 ,
Aug 30, 2018 Aug 30, 2018

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!!!

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
People's Champ ,
Aug 30, 2018 Aug 30, 2018
LATEST

Use the search. I found a solution in this forum, although I do not understand anything in extensions.

Re: HTML equivalent of ScriptUI ListBox?

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
Engaged ,
Aug 29, 2018 Aug 29, 2018

Is that really the only way to communicate between the two? Seems inefficient to serialize that way.

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