Application: TraverseSystem
Revit Platform: MEP
Revit Version: 2011.0
First Released For: 2010.0 
Programming Language: C#
Skill Level: Medium
Category: MEP
Type: ExternalCommand

Subject: Traverse a well-connected mechanical or piping system in the direction of flow.
Summary: 
This sample shows how to traverse a well-connected mechanical or piping system in the direction of flow and dump the traversal into an XML file.

Classes: 
Autodesk.Revit.UI.IExternalCommand
Autodesk.Revit.DB

Project Files: 
Command.cs
It contains the class Command which inherits from interface IExternalCommand and implements the Execute method. It also retrieves the well-connected mechanical or piping system from user selection.

TraversalTree.cs
It contains two classes TreeNode and TraversalTree. A TreeNode object represents an element in the system and it contains connection clues for the traversal. Class TraversalTree traverses the specified system in the direction of flow by generating a tree-like structure of TreeNode objects.

Description: 
This sample provides following functionalities.
-	Retrieve the well-connected mechanical or piping systems from the selected element which can be the system itself or any element in the system. If the selected element belongs to more than one well-connected system, the system has the most elements will be chosen.
-	Start to traverse the system from the base equipment of the system. If the system has no base equipment, it will have an open connector which is the only point that can connect to a base equipment. The owner of the open connector will be chosen as the starting point.
-	Analyze the relationships of connected elements in the system by their connectors’ flow directions and generate the traversal tree-like structure.
-	Dump the traversal into an XML file.

Instructions: 
1.	Open Revit MEP application, then open a project which contains well-connected systems or draw well-connected systems in a new project; select a well-connected mechanical or piping system or an element in a well-connected system. Then execute the command.
2.	The sample will traverse the system in the direction of flow. Finally it will dump the traversal into the XML file “traversal.xml” in the same folder as file “TraverseSystem.dll”.