Hello,
is there a way to exchange of Multi-Dimensional Arrays between FlexSim and Python?
I have only managed to pass 1-Dim Arrays to my py script, returning a list greater then 1-Dim back to FlexSim results in a Null-Object.
Thank you!
Uli
Hello,
is there a way to exchange of Multi-Dimensional Arrays between FlexSim and Python?
I have only managed to pass 1-Dim Arrays to my py script, returning a list greater then 1-Dim back to FlexSim results in a Null-Object.
Thank you!
Uli
Hello,
this seems to work:
Table tab = Table("MyGlobalTable"); Array arr = tab.clone(); var outVarArray = node("MODEL:/Tools/UserCommands/callPyFnc_getTable/code").evaluate(arr); print(arr, " --> Return from Python --> ", outVarArray);
The only thing to consider: integers arrive as floats on python side, therefore, if used for e.g. indexing, these have to be casted to integer's
Thanks,
Uli
Uli,
per class definition in FlexSim an array is one dimension only:
https://docs.flexsim.com/en/22.2/Reference/CodingInFlexSim/FlexScriptAPIReference/Data/Array.html
You can use arrays or variant type variables as the elements of your one dimensional array to use it in multiple dimensions, but you will have to consider that when reading elements of your array.
Good luck
It seems like if FlexSim <-> Python conversions are "string" centric.
Passing back a dictionary with a Two-Dimensional Array as value is possible by setting the value as a string representation of the array:
def getTable(arrayFromFlexSim): arr = np.array(arrayFromFlexSim) seq = dict() for i in range(0, 3): seq[i] = np.array2string(arr) return seq
The Dictionary get converted correctly to FlexSim:
Map: { 0: Array[3]: {Array[5]: {1,1,0,1,1},Array[5]: {1,0,0,1,1},Array[5]: {1,1,1,1,2}}, 1: Array[3]: {Array[5]: {1,1,0,1,1},Array[5]: {1,0,0,1,1},Array[5]: {1,1,1,1,2}}, 2: Array[3]: {Array[5]: {1,1,0,1,1},Array[5]: {1,0,0,1,1},Array[5]: {1,1,1,1,2}} }
If the 2-Dim Array is not converted to its string representation, the conversion result on FlexSim side will fail:
Map: {0: NULL, 1: NULL, 2: NULL}
Just in case someone might get trapped here too. :)
16 People are following this question.
FlexSim can help you understand and improve any system or process. Transform your existing data into accurate predictions.
FlexSim is a fully 3D simulation software environment. FlexSim can be used to simulate any process in any industry.
FlexSim®, FlexSim Healthcare™, Problem Solved.®, the FlexSim logo, the FlexSim X-mark, and the FlexSim Healthcare logo with stylized Caduceus mark are trademarks of FlexSim Software Products, Inc. All rights reserved.
Privacy | Do not sell or share my personal information | Cookie preferences | Report noncompliance | Terms of use | Legal | © Autodesk Inc. All rights reserved