Application: RoutingPreferenceTools
Revit Platform: MEP
Revit Version: 2013.0
First Released For: 2013.0
Programming Language: C#
Skill Level: Medium
Category: MEP
Type: ExternalCommand

Subject: Tools for routing preferences
Summary: 
This sample contains three commands.

[Note] – all samples only work properly when created from MEP document templates, such as “Systems-Default.rte.”

Routing Preference Analysis
Subject: Analyze the routing preferences of a given pipe type to check for common problems.
Summary:  This sample demonstrates how to use the routing preferences API to look at all rules and criteria for a given PipeType and check for several common problems, including:

1)	The first rule in a group (e.g. “Elbows”) has a range of “None.”
2)	All rules in a group have a range of “None.”
3)	A preferred junction type of Tee or Tap is set, but no fittings of that type are assigned to rules.
4)	A segment’s size range is not fully covered by the sizes ranges covered by elbow, junction, or cross fittings.
  
Classes: 
Autodesk.Revit.DB.Plumbing
Autodesk.Revit.DB

Project Files: 
Command.cs
Analyzer.cs
Performs all routing preference analysis and exports an XDocument with XML data reporting any warnings.

PartIdInfo.cs
Contains a routing preference rule group and list of ElementIds that correspond to found segments and fittings that meet criteria specified through a routing preference manager.

Instructions: 
1.	In Revit MEP, open or create a new document, load several pipe fittings, and define several pipe segments for several pipe types.  
2.	In the routing preferences manager for a pipe type, add these fittings and segments with minimum and maximum size ranges.  
3.	Run the Routing Preference Analysis command, and select a pipe type. 
4.	Click the “Find problems” button and read the XML output containing the warnings listed above.

To examine what segments and fittings your routing preferences will use for a give size, select a pipe size from the combo box, click the “Check Specific Size” button, read the output.

Routing Preference Builder (CommandReadPreferences and CommandWritePreferences)
Subject: A tool for setting pipe type, fitting, and routing preferences in a project from data in an XML file and also exporting those same preferences to XML for archival, documentation, and collaboration.
Summary:  These commands allow a user to work with routing preference data in a shareable XML format suitable for reuse in a wide variety of BIM management environments.

Classes: 

Autodesk.Revit.DB.RoutingPreferenceManager –manages routing preference rules and conditions for various MEP curve types.
Autodesk.Revit.DB.RoutingPreferenceRule
Autodesk.Revit.DB.Plumbing.PipeType
Autodesk.Revit.DB.Plumbing.PipeSegment
Autodesk.Revit.DB.Plumbing.PipeScheduleType
Autodesk.Revit.DB.PrimarySizeCriterion
Autodesk.Revit.DB.FamilySymbol
Autodesk.Revit.DB.Material

Project Files: 
CommandReadPreferences.cs
Main command file for the “Read Preferences from XML” command.

CommandWritePreferences.cs 
Main command file for the “Write Preferences to XML” command.

RoutingPreferenceBuilder.cs
Class to read and write XML and routing preference data.

RoutingPreferenceBuilderUtility.cs
Helper classes used by RoutingPreferenceBuilder.

RoutingPreferenceSample.xml 
A sample data file containing families, schedules, pipe types, segments, sizes, rules, and criteria.
RoutingPreferenceBuilderData.xsd –an xml schema used to validate a RoutingPreferenceBuilder xml document.

Instructions: 
1.	Open a Revit project containing at least one PipeType in Revit MEP.   
2.	Examine the pipe, schedule, segment, and routing preference rule data in RoutingPreferenceSample.xml. 
3.	Update any paths to family .rfa files as necessary.
4.	Run the “CommandReadPreferences” command, select the sample RoutingPreferenceSample.xml file, and note all of the pipetypes, schedules, segments, and routing preference rules added to the project.  Run the “CommandWritePreferences” command, select a new file to create, and note the exported routing preference data in the new XML file.  

Note: Place the optional “familypaths.xml” file in your RoutingPreferenceTools.dll folder with additional paths to family files that you use other than the default content path that Revit specifies.  This will allow Revit to search for family files in additional locations when reading and writing routing preferences to and from xml.