Welcome to Keen Software House Forums! Log in or Sign up to interact with the KSH community.
  1. You are currently browsing our forum as a guest. Create your own forum account to access all forum functionality.

Finding sub-grids on rotors

Discussion in 'Programming Questions and Suggestions' started by Wicorel, Dec 5, 2016.

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

    How do I go about finding sub-grids attached to rotors?

    I want to find the orientation of thrusters attached to rotors. I need to know which rotor they are attached to because their grid orientation is relative to the rotor orientation on the main grid. Even just the six-sided up/down/left/right/top/bottom would help (rather than the more complete angular orientation).
  2. d4rky1989 Apprentice Engineer

    I think this thread covers a very similar topic and may help you
  3. Wicorel Senior Engineer

    Yes, that should help.

    I'll work on that when I get back from work tonight.
  4. Lynnux Junior Engineer

    This simple solution will find all thrusters on a subgrid connected to Motor. Beware that this will only work if the position of the rotor head on the subgrid is at 0,0,0. This is normally the case if you place a motor (stator) on a grid and begin to build a new subgrid, means the rotor head was the very first block on this grid. Or vice versa it likely won't work if you place a rotor head onto an existing grid and attach it to the stator.
    List<IMyTerminalBlock> thrusters;
    IMyTerminalBlock Motor;
    Vector3I zeroPos = new Vector3I(0,0,0);
          for(int i=0; i < thrusters.Count; i++) {
              if(thrusters[i].IsFunctional) {
                IMySlimBlock slim = Motor.CubeGrid.GetCubeBlock(
                if((slim!=null)&&(slim.FatBlock == Motor)) {
                      // thruster is on subgrid of Motor
    some explanation:
    thrusters.CubeGrid.GridIntegerToWorld(zeroPos) converts the subgrid position where the rotor head should be into world coordinates.
    Motor.CubeGrid.WorldToGridInteger( takes these world coordinates and converts them to the grid position on its own (parent) grid.
    Motor.CubeGrid.GetCubeBlock( returns the slim block at this grid position (null if there is none).
    FatBlock is of type IMyCubeBlock and therefore can be compared to a terminal block (the Slimblock can't).

    Basically take a look to the IMyCubeGrid class and be a bit creative how to use its methods ;-)
    I call it a geometrical method to find blocks compared to the methods using block names. The advantage of the geometrical method is that you can rename the blocks as you want (mods often use(d) the CustomName).
    --- Automerge ---
    Or how about that ?

    Didn't try it. But this one should (always) work. Just came into my mind ;)
    Last edited: Dec 18, 2016
Thread Status:
This last post in this thread was made more than 31 days old.