How to pass a variable from js to jsx?
Good day dear audience!
Sorry for my bad English. I ask for help in writing a script for the extension panel.
There is a script button and a slider:
<button class="tool" id="gb_3b"><div class="inst">Start</div></button>
<b>Middle radius: <span style="font-size: 1.2em" id="gb3rval"></span></b>
<div id="gblur3rad"></div>
Running the script and initializing the slider in JS:
$("#gb_3b").button().click(function(a) {
csInterface.evalScript('$._ext.evalFile("' + extensionRoot + 'work/Smart_Frequency_3_Band_GB.jsxbin")')
});
$(function() {
$('#gblur3rad').slider({
min: 0.1,
max: 20,
step: 0.1,
value: 5,
create: setInputsFromSlider1,
slide: setInputsFromSlider1,
stop: setInputsFromSlider3
});
function setInputsFromSlider1() {
$('#gb3rval').text($('#gblur3rad').slider("value"));
};
function setInputsFromSlider3() {
var radius = $('#gblur3rad').slider("value");
csInterface.evalScript('GBlur3S("'+radius+'")', function() {csInterface.evalScript('GBlur3S2("'+radius+'")');});
};
};
main.jsx which is specified in the manifest:
function GBlur3S(radius) {
var idslct = charIDToTypeID( "slct" );
var desc16 = new ActionDescriptor();
var idnull = charIDToTypeID( "null" );
var ref5 = new ActionReference();
var idLyr = charIDToTypeID( "Lyr " );
ref5.putName( idLyr, "Base Middle GB" );
desc16.putReference( idnull, ref5 );
var idMkVs = charIDToTypeID( "MkVs" );
desc16.putBoolean( idMkVs, false );
var idLyrI = charIDToTypeID( "LyrI" );
var list3 = new ActionList();
list3.putInteger( 3 );
desc16.putList( idLyrI, list3 );
executeAction( idslct, desc16, DialogModes.NO );
var idsetd = charIDToTypeID( "setd" );
var desc34236 = new ActionDescriptor();
var idnull = charIDToTypeID( "null" );
var ref236 = new ActionReference();
var idfilterFX = stringIDToTypeID( "filterFX" );
ref236.putIndex( idfilterFX, 1 );
var idLyr = charIDToTypeID( "Lyr " );
var idOrdn = charIDToTypeID( "Ordn" );
var idTrgt = charIDToTypeID( "Trgt" );
ref236.putEnumerated( idLyr, idOrdn, idTrgt );
desc34236.putReference( idnull, ref236 );
var idfilterFX = stringIDToTypeID( "filterFX" );
var desc34237 = new ActionDescriptor();
var idFltr = charIDToTypeID( "Fltr" );
var desc34238 = new ActionDescriptor();
var idRds = charIDToTypeID( "Rds " );
var idPxl = charIDToTypeID( "#Pxl" );
desc34238.putUnitDouble( idRds, idPxl, radius );
var idGsnB = charIDToTypeID( "GsnB" );
desc34237.putObject( idFltr, idGsnB, desc34238 );
var idfilterFX = stringIDToTypeID( "filterFX" );
desc34236.putObject( idfilterFX, idfilterFX, desc34237 );
executeAction( idsetd, desc34236, DialogModes.NO );
};
function GBlur3S2(radius) {
var idslct = charIDToTypeID( "slct" );
var desc16 = new ActionDescriptor();
var idnull = charIDToTypeID( "null" );
var ref5 = new ActionReference();
var idLyr = charIDToTypeID( "Lyr " );
ref5.putName( idLyr, "Base Middle GB (H)" );
desc16.putReference( idnull, ref5 );
var idMkVs = charIDToTypeID( "MkVs" );
desc16.putBoolean( idMkVs, false );
var idLyrI = charIDToTypeID( "LyrI" );
var list3 = new ActionList();
list3.putInteger( 3 );
desc16.putList( idLyrI, list3 );
executeAction( idslct, desc16, DialogModes.NO );
var idsetd = charIDToTypeID( "setd" );
var desc34236 = new ActionDescriptor();
var idnull = charIDToTypeID( "null" );
var ref236 = new ActionReference();
var idfilterFX = stringIDToTypeID( "filterFX" );
ref236.putIndex( idfilterFX, 1 );
var idLyr = charIDToTypeID( "Lyr " );
var idOrdn = charIDToTypeID( "Ordn" );
var idTrgt = charIDToTypeID( "Trgt" );
ref236.putEnumerated( idLyr, idOrdn, idTrgt );
desc34236.putReference( idnull, ref236 );
var idfilterFX = stringIDToTypeID( "filterFX" );
var desc34237 = new ActionDescriptor();
var idFltr = charIDToTypeID( "Fltr" );
var desc34238 = new ActionDescriptor();
var idRds = charIDToTypeID( "Rds " );
var idPxl = charIDToTypeID( "#Pxl" );
desc34238.putUnitDouble( idRds, idPxl, radius );
var idGsnB = charIDToTypeID( "GsnB" );
desc34237.putObject( idFltr, idGsnB, desc34238 );
var idfilterFX = stringIDToTypeID( "filterFX" );
desc34236.putObject( idfilterFX, idfilterFX, desc34237 );
executeAction( idsetd, desc34236, DialogModes.NO );
};
After executing the script 2 smart layers with blur are formed. When you move the slider, the blur radius changes simultaneously in both layers.
Until then, everything works. But I would like to make it possible to set the value of the radius slider and this value was transferred to the external JSX.
Here is the part of JSX code where you need to insert a variable from JS:
//
// SmartFrequency3_BandGB.jsx
//
//
// Generated Thu Aug 02 2018 01:02:07 GMT+0300
//
cTID = function(s) { return app.charIDToTypeID(s); };
sTID = function(s) { return app.stringIDToTypeID(s); };
//
//==================== Smart Frequency 3-Band GB ==============
//
function SmartFrequency3_BandGB() {
function step1(enabled, withDialog) {
if (enabled != undefined && !enabled)
return;
var dialogMode = (withDialog ? DialogModes.ALL : DialogModes.NO);
var desc1 = new ActionDescriptor();
var ref1 = new ActionReference();
ref1.putProperty(cTID('Prpr'), cTID('CchP'));
ref1.putEnumerated(cTID('capp'), cTID('Ordn'), cTID('Trgt'));
desc1.putReference(cTID('null'), ref1);
var desc2 = new ActionDescriptor();
desc2.putInteger(cTID('HsSt'), 1);
desc1.putObject(cTID('T '), cTID('CchP'), desc2);
executeAction(sTID('set'), desc1, dialogMode);
};
// code
function step21(enabled, withDialog) {
if (enabled != undefined && !enabled)
return;
var dialogMode = (withDialog ? DialogModes.ALL : DialogModes.NO);
var desc1 = new ActionDescriptor();
desc1.putUnitDouble(cTID('Rds '), cTID('#Pxl'), radius);
executeAction(sTID('gaussianBlur'), desc1, dialogMode);
};
step1();
// code
step21();
};
//=========================================
// SmartFrequency3_BandGB.main
//=========================================
//
SmartFrequency3_BandGB.main = function () {
SmartFrequency3_BandGB();
};
SmartFrequency3_BandGB.main();
// EOF
"SmartFrequency3_BandGB.jsx"
// EOF
How to pass "radius" variable from JS to JSX?
