Consolidate Multiple LCD Panels into “one” 5/5 (1)

posted in: Information, LCD Panels, Scripts | 0

I have a bunch of LCD Panels on my base, using the various scripts you find on this site. I have one that shows me my raw ore inventory in all my containers, one that shows me refined ore inventory in all my containers, etc. They all use the Consolidated Inventory script from this site.

I wanted to have an overall status of everything that I could just look at in my command center, instead of having the various panels spread out around my base.

So the script below takes the contents of various LCD panels, specified in the readonly array at the beginning of the script and puts them all together on a “single” panel. The “single” is in quotes because what I did was place 6 small LCD panels all next to each other and numbered them as shown below:

    +---------------+---------------+---------------+
    |               |               |               |
    |               |               |               |
    |       1       |       3       |       5       |
    |               |               |               |
    |               |               |               |
    +---------------+---------------+---------------+
    |               |               |               |
    |               |               |               |
    |       2       |       4       |       6       |
    |               |               |               |
    |               |               |               |
    +---------------+---------------+---------------+

So what the script does is take the current text from all the panels specified in “PANELS”, and duplicates the text on the “Consolidated” panels filling each one in sequence.

For this to work, all the consolidated panels must be named the same, with a numeric suffix. In my case they are “Consolidated Panel 1”, “Consolidated Panel 2”, etc.

You specify the common part of your consolidated panel names in the CONSOLIDATED constant at the beginning of the script (note the space at the end, if you are using spaces before the number like I am).

The consolidated panels MUST start at number 1, and have no gaps in the numbering (i.e. you can’t have 1 and 3 and not have a 2).

If you want this information displayed in multiple locations, just create multiples of your “Consolidated Panel #” panels (i.e. I can have “Consolidated Panel 1” through “Consolidated Panel 6” in my command center, but I can also have another set of “Consolidated Panel 1” through “Consolidated Panel 6” in some other location and the script will update both sets). But the two sets have to all share the same common name (“Consolidated Panel “, in my case).

Also note that you may have to adjust the PANEL_LINES constant to reflect how many lines of text fit on a single panel. The value of 22 works perfectly if you are using font size 0.8. If you use a larger, or smaller, font, adjust his number accordingly.

Enjoy!

  1. public readonly string[] PANELS = {"Status Panel",
  2.                                    "Refinery Panel",
  3.                                    "Assembler Panel",
  4.                                    "Raw Ore Panel",
  5.                                    "Refined Ore Panel",
  6.                                    "Components Panel"
  7.                                   };
  8. const string CONSOLIDATED = "Consolidated Panel ";
  9. const int PANEL_LINES = 22;
  10.  
  11. void Main()
  12. {
  13.     String fullText = "";    
  14.     for (int i = 0; i < PANELS.Length; i++)  
  15.     {  
  16.         IMyTextPanel panel = GridTerminalSystem.GetBlockWithName(PANELS&#91;i]) as IMyTextPanel;
  17.         if (panel is IMyTextPanel) {
  18.             fullText += panel.GetPublicText();
  19.             if (!fullText.EndsWith("\n\n")) {
  20.                 fullText += "\n\n";
  21.             }
  22.         }
  23.     }
  24.     String&#91;] linesArray = fullText.Split(new string[] {"\n", "\r\n"}, StringSplitOptions.None);
  25.     List<IMyTerminalBlock> work = new List<IMyTerminalBlock>();
  26.     GridTerminalSystem.SearchBlocksOfName(CONSOLIDATED, work);      
  27.     for (int i = 1; i <= work.Count; i++)  
  28.     {  
  29.         List<IMyTerminalBlock> panels = new List<IMyTerminalBlock>();
  30.         GridTerminalSystem.SearchBlocksOfName(CONSOLIDATED + i, panels);
  31.         for (int p = 0; p < panels.Count; p++)  
  32.         {  
  33.             IMyTextPanel panel = (IMyTextPanel)panels&#91;p];
  34.             panel.WritePublicText(String.Join("\n", SubArray(linesArray,(i-1)*PANEL_LINES,PANEL_LINES)), false);
  35.             panel.ShowTextureOnScreen();  
  36.             panel.ShowPublicTextOnScreen();
  37.         }
  38.     }
  39. }
  40.  
  41. String&#91;] SubArray(String[] data, int index, int length)
  42. {
  43.     String&#91;] result = new String[length];
  44.     if (index < data.Length) {
  45.         while (index + length > data.Length) {
  46.               length--;
  47.         }
  48.         Array.Copy(data, index, result, 0, length);
  49.     }
  50.     return result;
  51. }

Please rate this post

Leave a Reply