question

Sebastien avatar image
0 Likes"
Sebastien asked Sebastien commented

Combobox items linked with a global table column

Hello !

I am building a custom GUI for a processor. I would like to have a combobox in this GUI with which I can choose what machine is this processor. Then it would fill the processor with the appropriate data linked with this machine. Thise data is already availabale in a Global Table. and each row is a machine. In the combobox definition I could only find item to hardcode. Is there a way to define them dynamically ?

I tried that from the documentation

"Often you will want the options in the combobox to be dynamic. You can do this by writing code in an OnOpen or some other trigger that populates the items attribute dynamically. Access the items attribute with the items() attribute command, clear the contents of it, then add nodes into the items attribute with nodeinsertinto(), then set their names with setname(). Once you've populated the list, set the itemcurrent attribute's value to the rank of the option that you would like the combobox to reference by default, then call comborefresh() to refresh the combobox windows options according to the new items list."

Unfortunately it is not clear for me. Moreover some functions are now deprecated.

I cannot find my combobox in the tree with treenode.find("@/combobox7");

But once I have it, how do I clear the attributes / insert new ones and set their names ?

Please find a test model attached.

test-gui-instance.fsm

Best regards,

FlexSim 19.0.0
global tablecombobox
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

·
martin.j avatar image
0 Likes"
martin.j answered Sebastien commented

Hello Sebastian,

I wont be as thorough as in my last explanation, but I have added the model in stead.

1. I added the 3 more processor to your model and named them for the 4 processors in your table.

2. I updated the table with a column that has a link to the processor in question.

3. I edited the code in your OnOpen trigger for the GUI (please see the code comments in the model). It should now populate the items node with 4 subnodes that that have a name matching the "Machine" column in your table, and a value matching the row number of that machine.

4. I edited the OnPress trigger for the Test button, to read the selected index off the combobox to find out which machine was selected. And then use that index to look up the machine and the value in the table, then set the value on the table. This required me to have a place to put that value, since the basic instance processor doesn't have a cycletime variable node like normal processors i created it.

When you double click any of the 4 processor now you get the custom GUI. You can now select which of the 4 processors you want to update the cycletime value for. If you instead want to update the processor you clicked on with the selected value and thereby changing its type and Ignore the third column I created: In your OnPress trigger replace the following line:

Object machine =tableMachine[selectedIndex][3];

with:

Object machine = node("@>objectfocus+",current);

This will get you a reference to the clicked processor rather than the one listed in the table.

I hope this is what you wanted.

Best regards
Martin
FlexSim Nordic


gui.jpg (69.9 KiB)
· 3
5 |100000

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

Sebastien avatar image Sebastien commented ·

Thank you for your answer Martin !

But I think you forgot to attach the model. :)

0 Likes 0 ·
martin.j avatar image martin.j commented ·

oops! Here's the model... test-gui-instance-1.fsm

0 Likes 0 ·
Sebastien avatar image Sebastien martin.j commented ·

Thank you again for your answer and the helpful commentaries !

Best regards,

0 Likes 0 ·

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

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