ATTENTIONThis FlexSim Community Forum is read-only. Please post any new questions, ideas, or discussions to our new community (we call it Answers) at https://answers.flexsim.com/. Our new Question & Answer site brings a modern, mobile-friendly interface and more focus on getting answers quickly. There are a few differences between how our new Q&A community works vs. a classic, threaded-conversation-style forum like the one below, so be sure to read our Answers Best Practices. |
flexsim.com |
|
Downloads |
Q&A Using Flexsim and building models |
#1
|
|||
|
|||
Create flowitems with onmessage and give them an itemtype
Hi there,
I create a couple of flowitems using a queue and its OnReset trigger to send a message to it's own and to create flowitems with the OnMessage trigger. Works perfectly fine. But how can I assign an itemtype to the created flowitems? I used the predefined "Create Flowitem" function and tried to include the setitemtype(item,1); command, but it doesn't work and I cannot see my logical error at the moment. Code:
/** \nNumber to create: */ int numitems = /**/1/**/; /** \nFlowitem Bin rank: */ int flowitemrank = /**/18/**/; /** \nDestination: */ treenode destination = /**/outobject(current,3)/**/; /**\n\n*/ for (int index = 0; index < numitems; index++) { insertcopy(first(rank(node("/Tools/FlowItemBin",model()),flowitemrank)), destination); setitemtype(item,1); } Thank you in advance! Jens |
#2
|
||||
|
||||
Tried to set the itemtype in the OnExit Trigger and this works fine.
Can´t find the mistake in your code. Maybe anybody else.
__________________
Hemmi |
The Following User Says Thank You to Sebastian Hemmann For This Useful Post: | ||
Jens Mühlheimer (02-02-2011) |
#3
|
||||
|
||||
Hi Jens,
>>item<< is only a special pointer name like >>treenode item<< but the reference is still missing >>treenode item = last(destination)<< Jörg |
The Following User Says Thank You to Jörg Vogel For This Useful Post: | ||
Jens Mühlheimer (02-02-2011) |
#4
|
|||
|
|||
Quote:
thanks for the reply. I forgot to tell a detail. I create 3 different Flowitems with this single queue, using 3 different blocks of the code above. So when I set the itemtype over the OnExit trigger, all Flowitems that are created with this queue get the same itemtype and I want them to differ (itemtypes 1 to 3). At the moment I can't figure out how to differ the created flowitems so I could a case or if determination to assign the proper itemtypes. |
#5
|
|||
|
|||
Quote:
I think I understand what you mean. For a better understanding here the complete code how it is at the moment. I defined the treenode item in the beginning, but I don't think I did it correctly, because it's still not working and the itemtypes are not assigned. Queue1 ist the queue I use to create the flowitems. Code:
treenode current = ownerobject(c); treenode item = last(node("/Queue1",model())); /**Flowitems erstellen*/ { //************* PickOption Start *************\\ /**Pallet*/ /** \nNumber to create: */ int numitems = /**/1/**/; /** \nFlowitem Bin rank: */ int flowitemrank = /**/6/**/; /** \nDestination: */ treenode destination = /**/outobject(current,1)/**/; /**\n\n*/ for (int index = 0; index < numitems; index++) { insertcopy(first(rank(node("/Tools/FlowItemBin",model()),flowitemrank)), destination); } } //******* PickOption End *******\\ { //************* PickOption Start *************\\ /**Box on Pallet*/ /** \nNumber to create: */ int numitems = /**/4/**/; /** \nFlowitem Bin rank: */ int flowitemrank = /**/5/**/; /** \nDestination: */ treenode destination = /**/outobject(current,2)/**/; /**\n\n*/ for (int index = 0; index < numitems; index++) { insertcopy(first(rank(node("/Tools/FlowItemBin",model()),flowitemrank)), destination); } } //******* PickOption End *******\\ { //************* PickOption Start *************\\ /**Green Pallet*/ /** \nNumber to create: */ int numitems = /**/1/**/; /** \nFlowitem Bin rank: */ int flowitemrank = /**/18/**/; /** \nDestination: */ treenode destination = /**/outobject(current,3)/**/; /**\n\n*/ for (int index = 0; index < numitems; index++) { insertcopy(first(rank(node("/Tools/FlowItemBin",model()),flowitemrank)), destination); setitemtype(item,1); } } //******* PickOption End *******\\ |
#6
|
|||
|
|||
The definition of item isn't an expression that is continually evaluated through the rest of the code, it's a value that stores a pointer to the object you want at the time you assign it. Your declaration line may evaluate and assign NULL to the item variable - but that's okay because you re-set it after you create the item.
Just add the following on the line before you set the itemtype: item = last(destination); or replace the set line with: setitemtype(last(destination),1); |
The Following 2 Users Say Thank You to Jason Lightfoot For This Useful Post: | ||
Peter Walters (07-18-2012) |
#8
|
|||
|
|||
Apparently I does not work completely, because in the following process an itemtype of a flowitem gets overwritten or messed up by a seperator.
See my model ... I checked the "Perform Batch" function in Queue4 so the model is "stopped" and you can check that the itemtypes are assigned correctly to the flowitems. But after the combining process (and separating again) the itemtype of the wooden pallet gets overwritten. (from 1 to 0) and i cannot explain why. |
#10
|
|||
|
|||
It seems to do something with the itemtype when moving that iteminit() cannot replace.
This works: insertcopy(first(rank(node("/Tools/FlowItemBin",model()),flowitemrank)), model()); item=last(model()); moveobject(item,destination); setitemtype(item,1); Of course you could also set up these initial itemtype values in the flowitem bin if they are the same for all flowitems of one type. |
The Following User Says Thank You to Jason Lightfoot For This Useful Post: | ||
Jens Mühlheimer (02-02-2011) |
#11
|
|||
|
|||
You can use a schedule on a source with the arrival time set to zero and the number of flowitems you want entered under "Quantity".
|
The Following User Says Thank You to Jason Lightfoot For This Useful Post: | ||
Sebastian Hemmann (02-02-2011) |
#12
|
||||
|
||||
Thanks a lot Jason,
my question had been more rethorical. Why using code if it is this easy to solve with using a Flexsim standard tool? Only as a approach! Got the same scenarios very often with colleagues, wich try to use very difficult ways to solve problems. And then get lost in their coding or need hours to find mistakes. Sometimes such hints (or asking for it) helps and possibly Jens only got lost.
__________________
Hemmi |
#13
|
|||
|
|||
Quote:
---- Since the different classes will always keep there itemtypes, I will just predefine the itemtype in the TreeView. I didn't know about this possibility and just found out about it when Jason mentioned it. Another solution would be to set labels in the FlowItem Bin. This makes the FlowItems identifiable if you need that function later (e.g. for sorting, etc) you could also read out the label(s). // And yes, Sebastian was right, I got lost and couldn't find my error ... but this is how you learn those "tricks" |
#14
|
|||
|
|||
I just realized that I use a queue as a FlowItem. I found another thread where it was shown how to create a queue object and copy it over to the FlowItem Bin, so you could use it as a FlowItem (can be handy for simulating a stacking process)
Since the queue object does not have an itemtype attribute I cannot assign an itemtype. I think I will use labels now. Other question: I can't create FlowItems with the code from above when the object in the FlowItem Bin was not originally a intended FlowItem, but one of my "queue-FlowItems". Complicated phrase ... any questions -> let me know. |
#15
|
|||
|
|||
Not to resurrect a long lost thread, but I am having a similar problem.
I moved the setitemtype to the OnExit trigger, but I am trying to set the item label as part of the OnMessage trigger, to be one of the incoming message parameters ( msgparam(2) ). Many thanks to Jason for the advice on the node pointer. If you disconnect the "WH_Queue" from the "MMR_Queue", the flowitems that are generated all appear to have the proper labels. However - when connected, the flow items exit "WH_Queue" and enter "MMR_Queue". On exit from "WH_Queue" they set item type from 0 to 1. For some reason, all flow items in "MMR_Queue" have label 0 instead of what they had in "WH_Queue". Is there a way to retain the item label while changing the itemtype? (I didnt think this would overwrite). (This may look weird - its a much simplified model of a much larger version I am trying to construct). Many thanks for advice! |
#16
|
|||
|
|||
FYI - Solved the problem. I believe the issue was that the queue would create the flow item, and then pass it along before it had a chance to set the label number.
By setting the queue to "Batching" with a minimal max-wait time (0.1 sec), the flow items stay in the queue long enough to set label numbers. Everything appears to work fine with this approach. |
Thread | Thread Starter | Forum | Replies | Last Post |
create flowitems on reset in queue | Congshi Wang | Q&A | 1 | 12-22-2010 10:58 AM |
Question on OnMessage Trigger | KelvinHo | Q&A | 2 | 01-26-2010 02:41 AM |
Can i divide a itemtype? | wilmermoncada | Q&A | 2 | 11-27-2009 08:41 AM |
Using TE FlowItems to Transport other FlowItems | juan alberto | Q&A | 13 | 09-13-2009 09:00 AM |
how to get number of itemtype | Vic Li | Q&A | 11 | 08-19-2009 11:20 PM |