Read macro from table, assign to flexscript label

Read macro from table, assign to flexscript label

guiroehe
Advocate Advocate
14 Views
5 Replies
Message 1 of 6

Read macro from table, assign to flexscript label

guiroehe
Advocate
Advocate

[ FlexSim 25.0.2 ]

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.

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

moehlmann_fe
Observer
Observer
Accepted solution

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

Message 3 of 6

guiroehe
Advocate
Advocate

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
Message 4 of 6

guiroehe
Advocate
Advocate

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
Message 5 of 6

moehlmann_fe
Observer
Observer

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"]);
Message 6 of 6

guiroehe
Advocate
Advocate
Hello, @Felix Möhlmann ,

thank you for your answer. However, I am sure the labels were set as flexscript. I checked it before my first answer and double checked it just now.

It seems that macros are not completely translated when inserted in the properties or tables. (speculation).

I will have to move away from them until a reliable syntax interpretation is available.

Thank you anyway.

0 Likes