How to call the user command having array as a parameter?

How to call the user command having array as a parameter?

rajankur6494
Advocate Advocate
71 Views
10 Replies
Message 1 of 11

How to call the user command having array as a parameter?

rajankur6494
Advocate
Advocate

[ FlexSim 23.2.1 ]

Hi Team,

I have created a user command and passing array as a parameter. But, it is showing errors while calling the user command.

1726063660777.png


1726063984957.png

Could you help me to know where it is going wrong?

Thank you!

0 Likes
Accepted solutions (1)
72 Views
10 Replies
Replies (10)
Message 2 of 11

jason_lightfootVL7B4
Autodesk
Autodesk
Accepted solution

Here's the documentation - you should use "var seq" in your list of parameters.

0 Likes
Message 3 of 11

rajankur6494
Advocate
Advocate

@Jason Lightfoot

Thanks for providing the documentation link.

Before, I was using Array seq = param(1); while defining user command.

Now, I made the correction as below:

var seq = param(1);

Even I am getting the same errors while calling the user command as

int Min_Time = Min_Changeover_Time([1,2,3]);

It is not accepting array as a parameter.

Do I need to change anything else?

Thank you!

0 Likes
Message 4 of 11

K_yun
Not applicable

002.png

try here

0 Likes
Message 5 of 11

jason_lightfootVL7B4
Autodesk
Autodesk

The Array type is correct in the code but not in the parameter definition of the user command where you must use 'var' or Variant.

Example attached.

UserComand_minValInArray.fsm

0 Likes
Message 6 of 11

rajankur6494
Advocate
Advocate
@Jason Lightfoot

I can't open it as it is in 2024 version.

Could you share it 2023 version?

Thank you!

0 Likes
Message 7 of 11

jason_lightfootVL7B4
Autodesk
Autodesk

The code is this:

Array theArray=param(1);
double minval=GLOBAL_UNREACHABLE;
for (int n=theArray.length;n>0;n--)
    minval=Math.min(minval,theArray);
return minval;

The command is setup like this:

1726136260020.png

I called it using this line in a script console:

minValInArray([5,8,33])
0 Likes
Message 8 of 11

rajankur6494
Advocate
Advocate
@Jason Lightfoot

Thank you so much! It is working now.

0 Likes
Message 9 of 11

rajankur6494
Advocate
Advocate

@Jason Lightfoot

I have one more question to ask for better clarity if I can.

For return type, we have used num as the return value is an integer.

But instead of 1, I would like to add 2 return values as an output. For example:-

Final Sequence Array along with Min Changeover Time

1726213435946.png


1726213494624.png


After defining the user command, that's how I was calling it:

1726213629770.png

Here is the output:

1726213861413.png

It is not working correctly for min_Time value as it should be 224. I feel it is just taking the first element of array as output for min_Time.

Any help would be appreciated.

Thanks!

0 Likes
Message 10 of 11

moehlmann_fe
Observer
Observer
Code execution stops after the first "return". You have to return the values as an array.
return [bestOrder, minTime];
Use "Variant" as the return type and assign the values as follows.
Array result = Get_Min_CO_Time(...).as(Array);
Array bestsequence = result[1];
double min_Time = result[2];
0 Likes
Message 11 of 11

rajankur6494
Advocate
Advocate
Got it @Felix Möhlmann

Working as expected. Thank you so much!

0 Likes