1. This forum is obsolete and read-only. Feel free to contact us at support.keenswh.com

How do I create a list of all battery blocks on a grid except those in a certain group?

Discussion in 'Programming Questions and Suggestions' started by Sticky32, Jul 29, 2019.

Thread Status:
This last post in this thread was made more than 31 days old.
  1. Sticky32

    Sticky32 Trainee Engineer

    I've currently gotten around the problem by using "Reserve Power" as a block name instead of a group name, but it's not exactly an ideal solution because the script uses groups for everything else.

    // Get Batteries
    List<IMyBatteryBlock> ListBattery = new List<IMyBatteryBlock>();
    GridTerminalSystem.GetBlocksOfType<IMyBatteryBlock>(ListBattery, l => !l.CustomName.Contains(strReservePower));

    // Get Reserve Power
    List<IMyBatteryBlock> ListReservePower = new List<IMyBatteryBlock>();
    GridTerminalSystem.GetBlocksOfType<IMyBatteryBlock>(ListReservePower, l => l.CustomName.Contains(strReservePower));
  2. mojomann71

    mojomann71 Senior Engineer

  3. Mollymawk

    Mollymawk Apprentice Engineer

    List<IMyTerminalBlock> BadBatteries = new List<IMyTerminalBlock>();
    List<IMyBatteryBlock> GoodBatteries = new List<IMyBatteryBlock>();

    GridTerminalSystem.GetBlockGroupWithName("NameOfGroup").GetBlocks(BadBatteries) ;

    GridTerminalSystem.GetBlocksOfType<IMyBatteryBlock>( GoodBatteries, blk => !BadBatteries.Contains(blk)) ;

    not saying its the best way, as you are wasting time processing unwanted stuff.

    are there other ways to identify the blocks you do want? like blk => blk.CubeGrid.IsSameConstructAs( Me.CubeGrid )
    Me.CubeGrid == blk.CubeGrid
    you could then put your reserve batteries on a sub grid or connected construct.
    Last edited: Jul 31, 2019
Thread Status:
This last post in this thread was made more than 31 days old.