Use GUI for Create Flow Item by edit field Automatically.

Use GUI for Create Flow Item by edit field Automatically.

anutt_k
Not applicable
42 Views
17 Replies
Message 1 of 18

Use GUI for Create Flow Item by edit field Automatically.

anutt_k
Not applicable

[ FlexSim 22.1.1 ]

Hello. I'm try to use GUI for create flow item by use edit field. I have question it can be possible to create item for Automatically.

Case 1 :

Type a text in edit field then press "Enter" key on keyboard. Then Flow Item will be create in Queue.

- Exam : Type "Box" in edit field and ENTER. A "Box" will be create in Queue.

Case 2 :

Type a text in edit field then time delay for 1-2 Second. Then Flow Item will be Create in Queue.

- Exam : Type "Box" in edit field then time delay for 1-2 Second. Then "Box" will be Create in Queue. (Automatically)

1659431677764.png


Thank You so much for help me and Knowledge Sharing.


0 Likes
Accepted solutions (1)
43 Views
17 Replies
Replies (17)
Message 2 of 18

moehlmann_fe
Explorer
Explorer
Accepted solution

Add the 'OnKeyDown' event to the edit field (Select 'All Attributes' in the attributes list on the bottom left to see it there). Then add the following code.

'lastkeydown()' returns the number code of the key that was pressed last (13 == "Enter", Lists of these codes can be easily found on the Internet). If that is the case, an item with the same name in the FlowItemBin as the entered text is created in the model and moved into Queue1.

1659439317201.png

Message 3 of 18

anutt_k
Not applicable

Thank You to reply me. I not found the Attribute "enterDown" and "evenfunction" like a picture.

1659668400442.png

But I found "OnKeyDown" and Add to lower of tool tip and test form yourcode and this error.

I think that because it don't have "enterDown" and "evenfunction".

1659668738309.png

It error when I,m try to type the item name such a Box.

1659668784572.png

1659668798960.png

0 Likes
Message 4 of 18

moehlmann_fe
Explorer
Explorer
'enterDown' was a node I experimented with, you can ignore that. 'eventfunctions' also seems to be unnecessary, since the code is triggered for you.

The error tells you that the variable type 'String' is unknown. The correct type is 'string' with a small s (Note how the other variable types are bolded in the code, yet 'String' is not)

The case also matters for the Flow Item name you enter into the field. There is no item called 'box', only 'Box'.
Message 5 of 18

anutt_k
Not applicable

Excellent it work. Now I can create item by edit flow item name in field and press enter. Thank You very much.

1659715609914.png

And I have a few one more questions.

How can we text in edit field and wait for few second then item will create for automatically.

Exam. Type the "Box" in edit field >> Waiting for 3 second >> After 3 second box will created in Queue.

(I try to upload my model for share it but when I'm upload file it tell me something went wrong. try again)

0 Likes
Message 6 of 18

moehlmann_fe
Explorer
Explorer

You could use the await statement to delay the code execution when a valid item name is entered into the edit field. Note that this will only work while the model is running. (I also don't really see why one would ever need this behaviour instead of creating the items directly on a key press)

1659776698633.png

Message 7 of 18

anutt_k
Not applicable

I want to use this behaviour for input text from USB Barcode Canner to make it create item automatically by type of text from barcode. I therefore need this behaviour.


From your reply code delay await statement. I try at it in OnKeyDown but it not create item. Although I run the model and wait from finish type text in edit field.

1659784948680.png

Then I try to use other Attiributes is a OnSelect or OnOpen or objectfocus. But it not create item too.

1659785115400.png

1659785161681.png

1659785234163.png

0 Likes
Message 8 of 18

moehlmann_fe
Explorer
Explorer

I see two errors in your code:

- There is a '/' missing after 'FlowItemBin' in line 5
- In line 9 it should be 'step' not 'strp'.

And to be sure: What I mean when I say that the model must be running is that the model time has to be moving. The delay happens after a certain time has passed in the model (as far as I know, FlexSim can't do real-time delays).

To have the code also work while there is no pending event in the model (the clock is not moving), you could create an event by sending a delayed message to the queue.

This message could also contain the rank of the flowitem, so that the creation can happen in the OnMessage trigger of the queue.

1659870670258.png

Message 9 of 18

anutt_k
Not applicable

I edit my error in line 5 and line 9 from your reply. And I can run model by use process flow by source and sink for run the the model time. Then it work well.

1659889103735.png

Now I try to clear text in edit field by solution that you told me from me use edit field of dashboard.

1659889400640.png

And no I try to use same method that you seen in this picture below at line 14 but it not clear after the item created.

1659889508028.png

I'm not sure. Where I should add command to clear string ItemName.

0 Likes
Message 10 of 18

moehlmann_fe
Explorer
Explorer
Here the edit field is not linked to any node. To set its text, use 'setviewtext(c, "")'.
0 Likes
Message 11 of 18

anutt_k
Not applicable

Thank You very much. Now It work well.

0 Likes
Message 12 of 18

donald_harkins
Not applicable
Hello Felix,


This solution is very cool! I was wondering if it would be possible to get this GUI to create items that aren't from the FlowItem Bin.


For example, I have my source and it has items coming in an arrival schedule. I want to know how to find out what name I put in at line 5 of the code to get my GUI to output my specific items, if it is possible. Let me know!

0 Likes
Message 13 of 18

moehlmann_fe
Explorer
Explorer
What exactly do you mean by "specific items"? A source also just creates copies of objects in the flowitem bin and possibly automatically assigns labels to them.
Message 14 of 18

donald_harkins
Not applicable

So for specific items I mean the objects in my Arrival Schedule under the ItemName column. I was just wondering what the code would be to reference these objects in the arrival schedule, for example one of the objects is called PMA, so I want to see if it's possible to just write "PMA" in the GUI and then have create a PMA in the queue.



0 Likes
Message 15 of 18

moehlmann_fe
Explorer
Explorer

Then "PMA" is just the name of the item. The class of the item is still one of the types available in the FlowItem bin, which you choose in the properties of the source. (I guess the variable name in the code might be confusing).

1661356266648.png

In theory you could write code that searches the arrival schedule of all sources for a "PMA" entry and then creates an item with that name and of the class that the respective source is set to. But I don't really see the use for that.

A simpler adjustment would be to allow the user to specify the name that the created item should be given..

1661356094038.png

With this code you could enter "Box, PMA" (separate class and name with a comma) and the created item (of class Box) would be assigned the name PMA.

Message 16 of 18

donald_harkins
Not applicable

Hey Felix,


Thank you for the code! I am running into a FlexScript error though:

"Flexscript Error VIEW:/active/GUI 1890856512/edit5>OnKeyDown Line 5 syntax error, unexpected identifier, expecting ';'

Could not finish parsing because of previous errors. "


I'm looking into solutions and should figure out why, probably something on my end, however I do have one more question regarding the code for the GUI and that's just more on what code to write for wanting to set labels, if possible. If it's not or it's too much then don't worry! You've been insanely helpful already Felix, thank you so much!


0 Likes
Message 17 of 18

moehlmann_fe
Explorer
Explorer

That's my bad. There is a semicolon missing at the end of line 4.

There are multiple ways to add labels:

item.LabelName = value; // If LabelName is a fixed value

item.labels.assert(LabelName, value); // If LabelName is variable that holds the name

You can use this after line 16 where "item" gets defined.

The following code assumes that the typed in text has the following format

itemClass, itemName, labelName1, labelValue1, labelName2, ...

1661364313710.png

Message 18 of 18

donald_harkins
Not applicable
Felix,


Thank you so much everything works! I appreciate all of your help!!

0 Likes