question

Gui Vaccaro avatar image
0 Likes"
Gui Vaccaro asked Gui Vaccaro commented

Read macro from table, assign to flexscript label

Hello,

Is there a direct way to have a global table column containing global macros to be read and interpreted as their corresponding macro values. The intent is to have the macro value assigned to an object label, reading from the table.

Example:

Let's say that MyTable[1][1] = MY_MACRO where MY_MACRO is previously defined by

#define MY_MACRO something

Then

myObject.labels["myLabel"].value = MyTable[1][1]; // receive "something", not "MY_MACRO"

I would prefer not having to create a parser function manually, if possible.

Thank you.

FlexSim 25.0.2
tableslabel valueglobal macros
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

Felix Möhlmann avatar image
1 Like"
Felix Möhlmann answered Gui Vaccaro commented

Either set the table cells to contain "FlexScript Data" (Rightclick -> Assign Data -> Assign FlexScript Data) or use the command "executestring()".

In the first case you can still read the string data from the cell by accessing the value of the cell node.

1737531324745.png


1737531324745.png (44.3 KiB)
· 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.

Gui Vaccaro avatar image Gui Vaccaro commented ·

Hi @Felix Möhlmann thank you. I believe setting Flexsript Data in the column would be the preferred way, but I forgot to mention this would be for large tables, and that feature does not work in the bundle mode.

1737553240200.png

I guess executestring() is the way to go until flexscript data is available in bundle tables.

Thank you!

0 Likes 0 ·
1737553240200.png (57.7 KiB)
Gui Vaccaro avatar image Gui Vaccaro Gui Vaccaro commented ·

Hi, @Felix Möhlmann ,

I am still puzzled, as Flexscript labels and macros do not seem to work with nested function calls. Please see the picture below. In this case the definition is as follows:

#define PACKAGE_XS 1

As per your answer, I would expect the results of the first and third print commands to be "1". However, they still keep the macro label as result.

1737598783688.png

Could you please explain?

Thank you.

0 Likes 0 ·
1737598783688.png (219.7 KiB)
Felix Möhlmann avatar image Felix Möhlmann Gui Vaccaro commented ·

Yes, the first and third print commands should show "1".

1737624753124.png

Are you sure that the item label is toggled as FlexScript? When you click on the value cell in the properties, the code editor icon should show up in the upper right corner.

1737624837510.png

To get that you can either pre-define the label in the FlowItemBin. Or you run the following two commands after creating the label and assigning string data to it.

switch_flexscript(item.labels["packageCategory"], 1);
buildnodeflexscript(item.labels["packageCategory"]);
1 Like 1 ·
1737624753124.png (20.5 KiB)
1737624837510.png (8.4 KiB)
Show more comments