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

Subject: Obstruction detects and resolve.
Summary: 
This sample will demonstrate how to detect and resolve the obstructions of Pipe with Pipe, Pipe with Beam, or Pipe with Duct.

Classes: 
Autodesk.Revit.UI.IExternalCommand
Autodesk.Revit.DB.Document
Autodesk.Revit.Creation.Document
Autodesk.Revit.DB.Plumbing.Pipe
Autodesk.Revit.DB.Mechanical.Duct

Project Files: 
Command.cs
This file contains a class Command and it implements interface IExternalCommand of Revit API.

Detector.cs
This file contains a class Detector and it is used to detect the obstructions of a Line or a ray.

Resolver.cs
This file contains a class Resolver and it implements the algorithm to detect the obstruction and resolve it.

Section.cs
This file contains a class Section and it presents an obstruction of a Pipe.

Description: 
This sample provides following functionalities.
-	 It will detect and resolve the obstructions of pipes.
-	Just detect the obstructions of Pipe with Pipe, Pipe with Beam, or Pipe with Duct. Others such as Pipe with Wall (Stairs, Floor, etc) will be ignored.
-	We just use pipe’s centerline to detect obstructions, and don’t consider the radius of the pipe.
-	Just re-route the pipes, don’t change the others (Beam, Duct).
-	How to resolve the obstructions:
n	Keep the Pipe’s original direction not change.
n	Split the Pipe’s line to some segments according to the obstructions detected.
n	Re-route the Pipes to avoid the obstructions.

Limitation:
Ø	This sample can work well if all the elements (Pipes, Ducts, and Beams) located in the same plane (no need to be horizontal or vertical), it may not work well in other cases. 
Ø	In order to simplify the problem, just use the pipe centerline to detect the obstruction, using pipe centerline to detect the obstruction will fail in following case:

Ø	The pipe’s length should be long enough to round the obstructions, otherwise, there will be error dialog when route the pipe. If the obstruction is too closer to the pipe’s ends, reroute the pipes to round the obstruction will show error dialog from Revit.

Instructions: 
1.	Open Revit MEP application and then open the project file “AvoidObstruction.rvt” locates in sample directory. Then execute the command.
2.	After running this command, the result will be reflected to the current file.