question

Maryam H2 avatar image
0 Likes"
Maryam H2 asked Maryam H2 commented

Subnodes Query Based on Item Labels

Hi,

How can I write a query to access the number of subnodes within a Location object, based on a label recorded on the Item that resides within the Location object? For instance, if there is a box labeled Type A placed on a specific floor spot, how can I query to determine the count of Type A boxes present at the Floor Spot location?

FlexSim 23.2.0
querylocationsubnodes
· 2
5 |100000

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

Jason Lightfoot avatar image Jason Lightfoot ♦♦ commented ·

What is your location object - a rack/storage object or a fixed resource?

0 Likes 0 ·
Maryam H2 avatar image Maryam H2 Jason Lightfoot ♦♦ commented ·
A Location object, a floor spot. I attached the model below.
0 Likes 0 ·
Logan Gold avatar image
0 Likes"
Logan Gold answered Maryam H2 commented

We were able to figure this out over the phone. The best option for this particular case was to use an Expression Field (with the following custom code) in a Resource that checks for if each resource (the Location objects) contain an item with a specific label value.

for (int index = 1; index <= value.subnodes.length; index++) {
   Object item = value.subnodes[index];

   if (item.labelName == "SpecificLabelValue")
      return 1;
}

return 0;

So if a resource does contain at least one item with the specific label value, then a 1 is returned. If the resource does not contain any items with the label value, a 0 is returned.

And in an Acquire activity, you can query for a resource that does not already contain a specific type of item, or query for a resource that already has a specific type of item, depending on the situation.

· 1
5 |100000

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

Maryam H2 avatar image Maryam H2 commented ·
yeah, worked perfectly, thanks!
0 Likes 0 ·
Abhay Bajpai avatar image
0 Likes"
Abhay Bajpai answered Maryam H2 commented

Run your model and click on "Stop". Right click on the floor spot object you want to query about and click on "Designate This Node (so)". That will choose that object as the "so".1695830386663.png


Now type this script in the user command

"Array TypeAParts=so().subnodes.toArray();

print(TypeAParts.length); "

It should give the number of Type A parts saved in the array



1695830386663.png (44.8 KiB)
· 1
5 |100000

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

Maryam H2 avatar image Maryam H2 commented ·

I want to write a query in the Acquire activity and I want it to be a dynamic feature not actually to stop and check every time. Please see asimple model attached.

query_subnodes.fsm

0 Likes 0 ·
query-subnodes.fsm (84.8 KiB)