ATTENTION

This 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

Go Back   FlexSim Community Forum > FlexSim Software > Q&A
Downloads

Q&A Using Flexsim and building models

  #1  
Old 02-02-2011
Jens Mühlheimer Jens Mühlheimer is offline
Flexsim User
 
Join Date: Jul 2008
Location: Stuttgart, Germany
Posts: 140
Downloads: 8
Uploads: 0
Thanks: 40
Thanked 35 Times in 27 Posts
Rep Power: 174
Jens Mühlheimer will become famous soon enoughJens Mühlheimer will become famous soon enough
Default 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);
}
Would be great if you could help me out.
Thank you in advance!

Jens
  #2  
Old 02-02-2011
Sebastian Hemmann's Avatar
Sebastian Hemmann Sebastian Hemmann is offline
Flexsim User
 
Join Date: Sep 2009
Location: Braunschweig (Germany)
Posts: 439
Downloads: 52
Uploads: 0
Thanks: 472
Thanked 217 Times in 154 Posts
Rep Power: 319
Sebastian Hemmann is a splendid one to beholdSebastian Hemmann is a splendid one to beholdSebastian Hemmann is a splendid one to beholdSebastian Hemmann is a splendid one to beholdSebastian Hemmann is a splendid one to beholdSebastian Hemmann is a splendid one to beholdSebastian Hemmann is a splendid one to behold
Default

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  
Old 02-02-2011
Jörg Vogel's Avatar
Jörg Vogel Jörg Vogel is offline
Flexsim User
 
Join Date: Sep 2007
Location: Hannover, Germany
Posts: 643
Downloads: 35
Uploads: 0
Thanks: 802
Thanked 665 Times in 410 Posts
Rep Power: 642
Jörg Vogel has a reputation beyond reputeJörg Vogel has a reputation beyond reputeJörg Vogel has a reputation beyond reputeJörg Vogel has a reputation beyond reputeJörg Vogel has a reputation beyond reputeJörg Vogel has a reputation beyond reputeJörg Vogel has a reputation beyond reputeJörg Vogel has a reputation beyond reputeJörg Vogel has a reputation beyond reputeJörg Vogel has a reputation beyond reputeJörg Vogel has a reputation beyond repute
Default

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  
Old 02-02-2011
Jens Mühlheimer Jens Mühlheimer is offline
Flexsim User
 
Join Date: Jul 2008
Location: Stuttgart, Germany
Posts: 140
Downloads: 8
Uploads: 0
Thanks: 40
Thanked 35 Times in 27 Posts
Rep Power: 174
Jens Mühlheimer will become famous soon enoughJens Mühlheimer will become famous soon enough
Default

Quote:
Originally Posted by Sebastian Hemmann View Post
Tried to set the itemtype in the OnExit Trigger and this works fine.
Can´t find the mistake in your code. Maybe anybody else.
Hi Sebastian,

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  
Old 02-02-2011
Jens Mühlheimer Jens Mühlheimer is offline
Flexsim User
 
Join Date: Jul 2008
Location: Stuttgart, Germany
Posts: 140
Downloads: 8
Uploads: 0
Thanks: 40
Thanked 35 Times in 27 Posts
Rep Power: 174
Jens Mühlheimer will become famous soon enoughJens Mühlheimer will become famous soon enough
Default

Quote:
Originally Posted by Jörg Vogel View Post
Hi Jens,

>>item<< is only a special pointer name like >>treenode item<< but the reference is still missing >>treenode item = last(destination)<<


Jörg
Hi Jörg, also thanks for your help.

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  
Old 02-02-2011
Jason Lightfoot Jason Lightfoot is offline
Flexsim Consultant
 
Join Date: Aug 2007
Location: Somerset, UK
Posts: 719
Downloads: 20
Uploads: 0
Thanks: 123
Thanked 953 Times in 446 Posts
Rep Power: 773
Jason Lightfoot has a reputation beyond reputeJason Lightfoot has a reputation beyond reputeJason Lightfoot has a reputation beyond reputeJason Lightfoot has a reputation beyond reputeJason Lightfoot has a reputation beyond reputeJason Lightfoot has a reputation beyond reputeJason Lightfoot has a reputation beyond reputeJason Lightfoot has a reputation beyond reputeJason Lightfoot has a reputation beyond reputeJason Lightfoot has a reputation beyond reputeJason Lightfoot has a reputation beyond repute
Default

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)
  #7  
Old 02-02-2011
Jens Mühlheimer Jens Mühlheimer is offline
Flexsim User
 
Join Date: Jul 2008
Location: Stuttgart, Germany
Posts: 140
Downloads: 8
Uploads: 0
Thanks: 40
Thanked 35 Times in 27 Posts
Rep Power: 174
Jens Mühlheimer will become famous soon enoughJens Mühlheimer will become famous soon enough
Default

See next post

Last edited by Jens Mühlheimer; 02-02-2011 at 06:56 AM.
  #8  
Old 02-02-2011
Jens Mühlheimer Jens Mühlheimer is offline
Flexsim User
 
Join Date: Jul 2008
Location: Stuttgart, Germany
Posts: 140
Downloads: 8
Uploads: 0
Thanks: 40
Thanked 35 Times in 27 Posts
Rep Power: 174
Jens Mühlheimer will become famous soon enoughJens Mühlheimer will become famous soon enough
Default

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.
Attached Files
File Type: zip container test.zip (44.5 KB, 170 views)
  #9  
Old 02-02-2011
Sebastian Hemmann's Avatar
Sebastian Hemmann Sebastian Hemmann is offline
Flexsim User
 
Join Date: Sep 2009
Location: Braunschweig (Germany)
Posts: 439
Downloads: 52
Uploads: 0
Thanks: 472
Thanked 217 Times in 154 Posts
Rep Power: 319
Sebastian Hemmann is a splendid one to beholdSebastian Hemmann is a splendid one to beholdSebastian Hemmann is a splendid one to beholdSebastian Hemmann is a splendid one to beholdSebastian Hemmann is a splendid one to beholdSebastian Hemmann is a splendid one to beholdSebastian Hemmann is a splendid one to behold
Default

Is it completely impossible to use a Source wich sends all Items at arrivaltime 0?
__________________
Hemmi
  #10  
Old 02-02-2011
Jason Lightfoot Jason Lightfoot is offline
Flexsim Consultant
 
Join Date: Aug 2007
Location: Somerset, UK
Posts: 719
Downloads: 20
Uploads: 0
Thanks: 123
Thanked 953 Times in 446 Posts
Rep Power: 773
Jason Lightfoot has a reputation beyond reputeJason Lightfoot has a reputation beyond reputeJason Lightfoot has a reputation beyond reputeJason Lightfoot has a reputation beyond reputeJason Lightfoot has a reputation beyond reputeJason Lightfoot has a reputation beyond reputeJason Lightfoot has a reputation beyond reputeJason Lightfoot has a reputation beyond reputeJason Lightfoot has a reputation beyond reputeJason Lightfoot has a reputation beyond reputeJason Lightfoot has a reputation beyond repute
Default

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  
Old 02-02-2011
Jason Lightfoot Jason Lightfoot is offline
Flexsim Consultant
 
Join Date: Aug 2007
Location: Somerset, UK
Posts: 719
Downloads: 20
Uploads: 0
Thanks: 123
Thanked 953 Times in 446 Posts
Rep Power: 773
Jason Lightfoot has a reputation beyond reputeJason Lightfoot has a reputation beyond reputeJason Lightfoot has a reputation beyond reputeJason Lightfoot has a reputation beyond reputeJason Lightfoot has a reputation beyond reputeJason Lightfoot has a reputation beyond reputeJason Lightfoot has a reputation beyond reputeJason Lightfoot has a reputation beyond reputeJason Lightfoot has a reputation beyond reputeJason Lightfoot has a reputation beyond reputeJason Lightfoot has a reputation beyond repute
Default

Quote:
Originally Posted by Sebastian Hemmann View Post
Is it completely impossible to use a Source wich sends all Items at arrivaltime 0?
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  
Old 02-02-2011
Sebastian Hemmann's Avatar
Sebastian Hemmann Sebastian Hemmann is offline
Flexsim User
 
Join Date: Sep 2009
Location: Braunschweig (Germany)
Posts: 439
Downloads: 52
Uploads: 0
Thanks: 472
Thanked 217 Times in 154 Posts
Rep Power: 319
Sebastian Hemmann is a splendid one to beholdSebastian Hemmann is a splendid one to beholdSebastian Hemmann is a splendid one to beholdSebastian Hemmann is a splendid one to beholdSebastian Hemmann is a splendid one to beholdSebastian Hemmann is a splendid one to beholdSebastian Hemmann is a splendid one to behold
Default

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  
Old 02-02-2011
Jens Mühlheimer Jens Mühlheimer is offline
Flexsim User
 
Join Date: Jul 2008
Location: Stuttgart, Germany
Posts: 140
Downloads: 8
Uploads: 0
Thanks: 40
Thanked 35 Times in 27 Posts
Rep Power: 174
Jens Mühlheimer will become famous soon enoughJens Mühlheimer will become famous soon enough
Default

Quote:
Originally Posted by Sebastian Hemmann View Post
Is it completely impossible to use a Source wich sends all Items at arrivaltime 0?
But you cannot create several different classes with this. Only the same FlowItem class with different itemtypes. Of course, this would be the easiest way to realize it.

----

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  
Old 02-03-2011
Jens Mühlheimer Jens Mühlheimer is offline
Flexsim User
 
Join Date: Jul 2008
Location: Stuttgart, Germany
Posts: 140
Downloads: 8
Uploads: 0
Thanks: 40
Thanked 35 Times in 27 Posts
Rep Power: 174
Jens Mühlheimer will become famous soon enoughJens Mühlheimer will become famous soon enough
Default

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  
Old 07-18-2012
Peter Walters Peter Walters is offline
Process Engineer
 
Join Date: Jun 2012
Location: San Diego, CA, USA
Posts: 6
Downloads: 0
Uploads: 0
Thanks: 3
Thanked 0 Times in 0 Posts
Rep Power: 0
Peter Walters is on a distinguished road
Default

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!
Attached Files
File Type: fsm 18Jul12_Test.fsm (60.3 KB, 98 views)
  #16  
Old 07-18-2012
Peter Walters Peter Walters is offline
Process Engineer
 
Join Date: Jun 2012
Location: San Diego, CA, USA
Posts: 6
Downloads: 0
Uploads: 0
Thanks: 3
Thanked 0 Times in 0 Posts
Rep Power: 0
Peter Walters is on a distinguished road
Default

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


All times are GMT -6.
Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2020, vBulletin Solutions Inc.
Copyright 1993-2018 FlexSim Software Products, Inc.