question

Paulino SMH avatar image
0 Likes"
Paulino SMH asked Mischa Spelt commented

Process time within flexscript

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.

FlexSim 22.1.1
global tableflexscriptprocess time
5 |100000

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.

1 Answer

Joerg Vogel avatar image
3 Likes"
Joerg Vogel answered Mischa Spelt commented

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.

· 4
5 |100000

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.

Felix Möhlmann avatar image Felix Möhlmann commented ·

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.

2 Likes 2 ·
Joerg Vogel avatar image Joerg Vogel Felix Möhlmann commented ·
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 0 ·
Mischa Spelt avatar image Mischa Spelt Joerg Vogel commented ·

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.

1 Like 1 ·
Paulino SMH avatar image Paulino SMH commented ·
Both solutions work well.

Than you very much for the support.

0 Likes 0 ·