title: MEP System traversal - cannot find BaseEquipment or Openconnector
body: <h2>Intro</h2>
  <p>I'm working on a project where I need to traverse though all elements in a MEPSystem from the starting Mechanical Equipment. I found the 2 articles below by Jeremy Tammik which suggest a way to do this:</p>
  <ol>
  <li><a href="https://thebuildingcoder.typepad.com/blog/2016/06/traversing-and-exporting-all-mep-system-graphs.html" rel="nofollow noreferrer">Traversing and Exporting all MEP System Graphs</a></li>
  <li><a href="https://thebuildingcoder.typepad.com/blog/2016/06/store-mep-systems-in-hierarchical-json-graph.html" rel="nofollow noreferrer">MEP System Structure in Hierarchical JSON Graph</a></li>
  </ol>
  <p>One of the reference I found in this articles in to the GitHub repository for <a href="https://github.com/jeremytammik/TraverseAllSystems" rel="nofollow noreferrer">TraverseAllSystems</a> and found that the release <a href="https://github.com/jeremytammik/TraverseAllSystems/tree/2017.0.0.8" rel="nofollow noreferrer">2017.0.0.8</a> works best for my need to be able to provide the data in a structured json format like below:</p>
  
  MEP System JSON format!
  <pre class="lang-json prettyprint-override"><code>{
    &quot;id&quot;: 392200,
    &quot;name&quot;: &quot;Mitered Elbows / Taps&quot;,
    &quot;children&quot;: [
      {
        &quot;id&quot;: 392203,
        &quot;name&quot;: &quot;Standard&quot;,
        &quot;children&quot;: [
          {
            &quot;id&quot;: 392199,
            &quot;name&quot;: &quot;Mitered Elbows / Taps&quot;,
            &quot;children&quot;: [
              {
                &quot;id&quot;: 386552,
                &quot;name&quot;: &quot;450 x 200&quot;,
                &quot;children&quot;: []
              },
              {
                &quot;id&quot;: 386555,
                &quot;name&quot;: &quot;450 x 200&quot;,
                &quot;children&quot;: []
              }
            ]
          }
        ]
      }
    ]
  }
  
  </code></pre>
  
  <h2>Problem</h2>
  <p>Now the problem is that this seems to be working fine in the <a href="https://knowledge.autodesk.com/support/revit/getting-started/caas/CloudHelp/cloudhelp/2022/ENU/Revit-GetStarted/files/GUID-61EF2F22-3A1F-4317-B925-1E85F138BE88-htm.html" rel="nofollow noreferrer">Sample Revit models</a> provided by Autodesk. But when I try this out in my project, I found that its working as expected.</p>
  <p>After debugging for quite some time, I found that the <a href="https://github.com/jeremytammik/TraverseAllSystems/blob/2017.0.0.8/TraverseAllSystems/TraversalTree.cs#L400" rel="nofollow noreferrer"><code>m_system.BaseEquipment</code></a> &amp; <a href="https://github.com/jeremytammik/TraverseAllSystems/blob/2017.0.0.8/TraverseAllSystems/TraversalTree.cs#L444" rel="nofollow noreferrer"><code>openConnector</code></a> in the <a href="https://github.com/jeremytammik/TraverseAllSystems/blob/2017.0.0.8/TraverseAllSystems/TraversalTree.cs" rel="nofollow noreferrer"><code>TraversalTree.cs</code></a> class both return null and that's where the code is breaking because its not able to find the starting element which is the Mechanical Equipment. Does anyone know why this is happening and how to solve this?</p>
  <p>Below is the starting part of the respective code that is causing this issue:</p>
  
  Code that breaks
  <p>m_system.BaseEquipment</p>
  <pre class="lang-cs prettyprint-override"><code>private TreeNode GetStartingElementNode()
  {
      TreeNode startingElementNode = null;
  
      FamilyInstance equipment = m_system.BaseEquipment; // returns null
  
  // ...
  </code></pre>
  <p>openConnector</p>
  <pre class="lang-cs prettyprint-override"><code>private Element GetOwnerOfOpenConnector()
  {
      Element element = null;
  
      //
      // Get an element from the system's terminals
      ElementSet elements = m_system.Elements;
      foreach (Element ele in elements)
      {
          element = ele;
          break;
      }
  
      // Get the open connector recursively
      Connector openConnector = GetOpenConnector(element, null); // returns null
  
      return null != openConnector
          ? openConnector.Owner
          : null;
  }
  </code></pre>
  
  <h3>Other useful resources:</h3>
  <ul>
  <li><a href="https://forums.autodesk.com/t5/revit-api-forum/how-to-iterate-over-elements-by-mep-system-name/td-p/7386520" rel="nofollow noreferrer">How to Iterate over elements by MEP System Name</a></li>
  <li><a href="https://thebuildingcoder.typepad.com/files/cp4108_rme_api-1.pdf" rel="nofollow noreferrer">Revit MEP Programming: All Systems Go</a></li>
  </ul>