Copy link to clipboard
Copied
Currently in js with jsx I'm doing the following:
const exc = `setupPlateTemplate(${orders})`;
csiRun.evalScript(exc);
Where orders is an array of data. It doesn't work.
For kicks I tried this:
let testMe = 'something'
const exc = `setupPlateTemplate(${testMe})`;
csiRun.evalScript(exc);
Does not work.
This does work:
const exc = `setupPlateTemplate()`;
csiRun.evalScript(exc);
How can I pass parameters?
Hi, you need to wrap the parameters in a quote:
cs.evalScript(`someFunction('${param}')`)
Notice the quotes inside the round brackets. If you need parameters, best to JSON.stringify them before passing (evalScript can only handle strings) then parse them once in JSX.
Example here, notice evalScript is an imported (promised wrapper) function from a small util library I call cluecumber, here.
Make sure to eval/run a JSON lib in JSX prior to calling JSON.parse in your JSX file though.
Copy link to clipboard
Copied
Never used JS in Illustrator, but based on other experience: why do you evaluate twice (once with `` quotes, once with evalscript)? Just use a a simple string and see if it works.
Copy link to clipboard
Copied
Thanks for your response. Because orders in the first is an array of data. So it's not just a string I'm trying to pass.
Copy link to clipboard
Copied
So, explain why you use the back quotes? Bear in mind the results of any backquoted operation is a string, which you specifically said you want to avoid.
Copy link to clipboard
Copied
Those aren't backslashes. It's JavaScript es6 they're used so I can allow template literals. {$somevariable} in a js string
Copy link to clipboard
Copied
I didn't say backslash. I said backquote, which I know are used to create template literals. Now, I've never used backquotes in JavaScript but it seems to me that the result of a template literal is a string, so of course it will fail.
And consider this example:
let testMe = 'something'
const exc = `setupPlateTemplate(${testMe})`;
csiRun.evalScript(exc);
so... would this script work:
setupPlateTemplate(something)
rather than
setupPlateTemplate('something')
Copy link to clipboard
Copied
In js it would be
let myArray = ["hi", "sun", "blah"]
let putVar = 'hi joe, ${myArray}'
then if we console logged that it be the array. So that's what I'm trying to do here in js to pass the array, in the original example orders is an array of objects.
tryinf to get my data to go to the function in jsx. Sorry if I'm making it more confusing.
Copy link to clipboard
Copied
edit: someone else answered
Copy link to clipboard
Copied
Please explain what you mean when you say testMe is not defined. It's in the code let testMe = "something"
Copy link to clipboard
Copied
edit: someone else answered
Copy link to clipboard
Copied
Generally speaking how would you pass a js object from js to jsx?
Copy link to clipboard
Copied
edit: someone else answered
Copy link to clipboard
Copied
This ${} is es6 js template literal
Copy link to clipboard
Copied
Hi, you need to wrap the parameters in a quote:
cs.evalScript(`someFunction('${param}')`)
Notice the quotes inside the round brackets. If you need parameters, best to JSON.stringify them before passing (evalScript can only handle strings) then parse them once in JSX.
Example here, notice evalScript is an imported (promised wrapper) function from a small util library I call cluecumber, here.
Make sure to eval/run a JSON lib in JSX prior to calling JSON.parse in your JSX file though.
Get ready! An upgraded Adobe Community experience is coming in January.
Learn more