Mining - UnloadToHanger issue

Hello,

I tried the following code segment from a different thread.  This does not seem to work.  Items from the ore hold are selected but a destination container cannot be found.  I checked to make sure the label text was correct.  Thank you for the help.

void UnloadToHangar(string DestinationContainerName = "Item Hangar") {     Host.Log("unload to hangar.");      EnsureWindowInventoryOpenOreHold();      for ( ; ; )     {         var    OreHoldItem = WindowInventory?.SelectedRightInventory?.ListView?.Entry?.FirstOrDefault();         var    DestinationContainer =             WindowInventory?.LeftTreeListEntry?.SelectMany(entry => new[]{entry}.Concat(entry.EnumerateChildNodeTransitive()))             ?.FirstOrDefault(entry => string.Equals(entry?.Text, DestinationContainerName, StringComparison.InvariantCultureIgnoreCase));          if (null == DestinationContainer)            Host.Log("error: Inventory entry labeled '" + DestinationContainerName + "' not found");          if(null == OreHoldItem)             break;    //    0 items in OreHold                  Sanderling.MouseDragAndDrop(OreHoldItem, DestinationContainer);     } }

I checked to make sure the label text was correct.

Where was it correct? Where did you find the Label?

Which string did you pass to the method?

I suggest you change the code to let it log all the entries which are actually tested:

         var leftListEntry =              WindowInventory?.LeftTreeListEntry?.SelectMany(entry => new[]{entry}.Concat(entry.EnumerateChildNodeTransitive()))              ?.ToArray();      Host.Log("leftListEntry --->");      foreach(var entry in leftListEntry.EmptyIfNull())         Host.Log("entry?.Text: '" + entry?.Text + "'");            var    DestinationContainer =              leftListEntry?.FirstOrDefault(entry => string.Equals(entry?.Text, DestinationContainerName, StringComparison.InvariantCultureIgnoreCase));  

I figured out the issue.  You are using a string.Equals test and it looks like a “StartsWith” might be more appropriate due to the added text for distance in a POC.  Here is the log entry:

[
{
“TimeDateTimeIntraDayCal”: “11.33.28”,
“TimeDateTimeIntraSecMilliString”: “093”,
“CaptionString”: “entry?.Text: ‘Intensive Reprocessing Array <color=#66FFFFFF>3,123 m’”,
“LineIndex”: 623,
“CharacterIndexInLine”: 12,
“LineIndexInAvalonEdit”: 624,
“CharacterIndexInLineInAvalonEdit”: 13
}
]

Thank you.

1 Like

I figured out the issue.  You are using a string.Equals test and it looks like a “StartsWith” might be more appropriate due to the added text for distance in a POC.  Here is the log entry:

[
{
“TimeDateTimeIntraDayCal”: “11.33.28”,
“TimeDateTimeIntraSecMilliString”: “093”,
“CaptionString”: “entry?.Text: ‘Intensive Reprocessing Array <color=#66FFFFFF>3,123 m’”,
“LineIndex”: 623,
“CharacterIndexInLine”: 12,
“LineIndexInAvalonEdit”: 624,
“CharacterIndexInLineInAvalonEdit”: 13
}
]

Thank you.

Good spot. That is something to consider when I work the script.

Atm I think I will use a regex pattern like this:

"^s*" + Regex.Escape(DestinationContainerName) + "s*($|&lt"

Unlike “StartsWith”, this should stell prevent a unwanted match with a container name which is not the same but starts the same (No idea what container names are to be found out there).