Hi Chris,
I found today an issue I couldn’t easily solve within MWorks.
I have a bunch of lists: varAList, varBList,varCList,varDList
and a variable I use as an index: N.
I’d like to do two things from the XML/MWEL:
- index the list with the variable, or if the list is length 1, use the first element.
Python example:
if len(varList) == 1:
var = varList[0]
else
var = varList[N]
What I currently do is something like: (python)
def assign_list_or_one(varListStr, indexStr, varStr):
vL = mw.getvar(varListStr)
if len(vL) == 1:
out = vL[0]
else:
out = vL[mw.getvar(indexStr)]
mw.setvar(varListStr, out)
(xml)
<action=“run_python_string” code=“assign_list_or_one(‘varList’, ‘N’, ‘var’)”/> - check to make sure all lists are the same length, or length 1
There’s not really an easy way to do this without temp vars in XML/MWEL.
First, do you see an easier way to do (1), perhaps within the XML/MWEL, without making the code too unreadable?
If I do 10-20 of the calls into python in (1), do you think that will be a speed issue? (i.e. do you have a sense of how much overhead time run_python_string takes to call into and out of python, and how much time mw.getvar() / setvar() take for scalars or reasonable-sized lists?)
And this is the kind of thing that would be easier if there was a Python MW experiment language. But perhaps the current run_python_string solution is the best compromise.
Mark