Process time within flexscript

Process time within flexscript

paulino_smh
Not applicable
574 Views
5 Replies
Message 1 of 6

Process time within flexscript

paulino_smh
Not applicable

[ FlexSim 22.1.1 ]

Hello everyone.

I've been reading the "Process Time" of a processor inside an script in order to be able to automatically adjust an animation based on that time.

In the following image you can see an example of what I've been doing to read the value (basically using the getProperty command):

getprocesstime.png


Everything works fine if the processor time value is being entered as a number directly. The problem I'm facing now is that we have a model where the processor times are being provided as table cells.

As you can see in the following image using the same code returns 0 in this case:

getprocesstime-tableerror.png


Based on the documentation getProperty returns a Variant, when I use that as the datatype I get a reference to the table but I have not been able to parse it as an integer:

getprocesstime-variant.png


Is there a function in flexscript to evaluate that Variant as a command and get the processing times provided in this way as integers ?

This is the test model I've been using:

test_processTimeTableScript.fsm


Thank you in advance.

0 Likes
Accepted solutions (1)
575 Views
5 Replies
Replies (5)
Message 2 of 6

joerg_vogel_HsH
Mentor
Mentor
Accepted solution

Process Time is a function. A Function returns a value for an Event in FlexSim. You can parse a Model Parameter to be returned into this Function. Then you can evaluate this Parameter simultaneously somewhere else.

Before we used Parameters for the experimenter, a Classic approach was to set a label value in processor and read this value to be returned in a Process Time function. Then we were able to get access to the process time as a numerical value.

Message 3 of 6

moehlmann_fe
Advocate
Advocate

To add to this answer:

If using the table is more convenient for your than to use parameters, you can still access the process time value. By accessing the variable's treenode directly, you can evaluate the FlexScript code it holds which reads the table cell value.

Object processor2 = model().find("Processor2");
Variant processTime = processor2.find(">variables/cycletime").evaluate();
print(processTime);

The developers do not guarantee future compatability when reading directly from the tree like this, as the node position/name or other factors might change.

Message 4 of 6

paulino_smh
Not applicable
Both solutions work well.

Than you very much for the support.

0 Likes
Message 5 of 6

joerg_vogel_HsH
Mentor
Mentor
If you evaluate a script node like cycleTime, then you run the code. This is working well as long as their are static values involved. BUT if you let execute FlexScript code with statistical distributed random functions, then you get a new return value which has nothing in common with the value that controls your cycle time currently.
0 Likes
Message 6 of 6

mischa_spelt
Advisor
Advisor

Also, this may break if the code in the field uses the item parameter. You should pass one in as the first argument to evaluate() if there is any chance that your cycle time is, say, an item label or a Value By Case based on an item label.