Hello,
I have a queue with multiple items. Each item has its labels, and I would want to know the number of items that the label "oDepartureTruck" == X. How can I do that?
Thanks!
Hello,
I have a queue with multiple items. Each item has its labels, and I would want to know the number of items that the label "oDepartureTruck" == X. How can I do that?
Thanks!
@Marc R5 There are several solutions possible. Maybe the easiest is using the onentry and onexit triggers and everytime an item enters or exits increase a label on the queue. (or use process flow to do this)
The 2nd option is create a for loop that loop through all the items in the queue and adds up the ones with the correct label. You could for instance put this in a user command
The 3d option is more or less the same as the second but you can use the build in query language to create a query.
Option 1 is the fastest, 3 the slowest
Edit: Originally meant as an answer, but Steven was faster.
There are multiple ways. The best approach is going to depend on personal preference and how many items are in the queue, how many different values are there of the label and how often you want to retrieve that value.
1) Query
You can use the Table.query and have it interpret the queue's subnodes and their labels as a table. All the necessary information can be found in the respective manual page (Querying the contens of a queue is described in "Advaned Query Techniques" about halfway down the page).
A query to retrieve the number of items with "Type" 1 from Queue1 would, for example, look like this:
int itemNum = Table.query("SELECT COUNT($2) AS ItemCount FROM $1 WHERE $3 == $4", Model.find("Queue1"), $iter(1), $iter(1).Type, 1)[1][1];
2) For-Loop
You can also write a simple for-loop that counts the occurence of the given value. (Again, the example counts the occurence of "Type" 1)
Object queue = Model.find("Queue1"); int itemNum = 0; for(int i = 1; i <= queue.subnodes.length; i++) { if(queue.subnodes[i].Type == 1) { itemNum++; } }
3) Map
If there are a lot of items in the queue and you need to read the quantity often, it might be worthwhile to keep a Map of the contents. That way the total of each type is always directly available without needing to count every time.
You can keep the map as a label of the queue, as demonstrated in the attached model. First create any label, then assign a map value to it.
Map map; Model.find("Queue1").labels["ContentMap"].value = map;
Then set this as the reset value, so the map gets cleared on every model reset.
In the "OnEntry" and "OnExit" triggers, the map is updated to always hold the current number of items of each different label value.
17 People are following this question.
FlexSim can help you understand and improve any system or process. Transform your existing data into accurate predictions.
FlexSim is a fully 3D simulation software environment. FlexSim can be used to simulate any process in any industry.
FlexSim®, FlexSim Healthcare™, Problem Solved.®, the FlexSim logo, the FlexSim X-mark, and the FlexSim Healthcare logo with stylized Caduceus mark are trademarks of FlexSim Software Products, Inc. All rights reserved.
Privacy | Do not sell or share my personal information | Cookie preferences | Report noncompliance | Terms of use | Legal | © Autodesk Inc. All rights reserved