added Revit 2022 SDK minus except *rvt and *rfa

This commit is contained in:
Jeremy Tammik
2021-04-20 11:36:21 +02:00
parent 1133a82dc5
commit 7e327986e8
3034 changed files with 1245318 additions and 0 deletions
@@ -0,0 +1,410 @@
//
// (C) Copyright 2003-2019 by Autodesk, Inc.
//
// Permission to use, copy, modify, and distribute this software in
// object code form for any purpose and without fee is hereby granted,
// provided that the above copyright notice appears in all copies and
// that both that copyright notice and the limited warranty and
// restricted rights notice below appear in all supporting
// documentation.
//
// AUTODESK PROVIDES THIS PROGRAM "AS IS" AND WITH ALL FAULTS.
// AUTODESK SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTY OF
// MERCHANTABILITY OR FITNESS FOR A PARTICULAR USE. AUTODESK, INC.
// DOES NOT WARRANT THAT THE OPERATION OF THE PROGRAM WILL BE
// UNINTERRUPTED OR ERROR FREE.
//
// Use, duplication, or disclosure by the U.S. Government is subject to
// restrictions set forth in FAR 52.227-19 (Commercial Computer
// Software - Restricted Rights) and DFAR 252.227-7013(c)(1)(ii)
// (Rights in Technical Data and Computer Software), as applicable.
//
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
using System.Xml.Linq;
using Autodesk.Revit.DB;
using Autodesk.Revit.DB.Plumbing;
namespace Revit.SDK.Samples.RoutingPreferenceTools.CS
{
/// <summary>
/// Queries all routing preferences and reports potential problems in the form of an XDocument.
/// </summary>
internal class Analyzer
{
#region Data
private Autodesk.Revit.DB.Document m_document;
private Autodesk.Revit.DB.RoutingPreferenceManager m_routingPreferenceManager;
private double m_mepSize;
#endregion
#region Public interface
/// <summary>
/// Constructor
/// </summary>
/// <param name="routingPreferenceManager"></param>
/// <param name="document"></param>
public Analyzer(RoutingPreferenceManager routingPreferenceManager, Document document)
{
m_routingPreferenceManager = routingPreferenceManager;
m_document = document;
m_mepSize = 0;
}
/// <summary>
/// Constructor
/// </summary>
/// <param name="routingPreferenceManager"></param>
/// <param name="mepSize"></param>
/// <param name="document"></param>
public Analyzer(RoutingPreferenceManager routingPreferenceManager, double mepSize, Document document)
{
m_routingPreferenceManager = routingPreferenceManager;
m_document = document;
m_mepSize = Convert.ConvertValueToFeet(mepSize, m_document);
}
/// <summary>
/// Get specific size query
/// </summary>
/// <returns></returns>
public XDocument GetSpecificSizeQuery()
{
XDocument xReportDoc = new XDocument();
XElement xroot = new XElement(XName.Get("RoutingPreferenceAnalysisSizeQuery"));
xroot.Add(GetHeaderInformation());
foreach (PartIdInfo partId in GetPreferredFittingsAndSegments())
{
xroot.Add(partId.GetXml(m_document));
}
xReportDoc.Add(xroot);
return xReportDoc;
}
/// <summary>
/// Get all segments from a the currently selected pipe type, get each size from each segment,
/// collect, sort, and return.
/// </summary>
public static List<double> GetAvailableSegmentSizes(RoutingPreferenceManager routingPreferenceManager, Autodesk.Revit.DB.Document document)
{
System.Collections.Generic.HashSet<double> sizes = new HashSet<double>();
int segmentCount = routingPreferenceManager.GetNumberOfRules(RoutingPreferenceRuleGroupType.Segments);
for (int index = 0; index != segmentCount; ++index)
{
RoutingPreferenceRule segmentRule = routingPreferenceManager.GetRule(RoutingPreferenceRuleGroupType.Segments, index);
Segment segment = document.GetElement(segmentRule.MEPPartId) as Segment;
foreach (MEPSize size in segment.GetSizes())
{
sizes.Add(size.NominalDiameter);
}
}
List<double> sizesSorted = sizes.ToList();
sizesSorted.Sort();
return sizesSorted;
}
/// <summary>
/// Returns XML data for a variety of potential routing-preference problems.
/// </summary>
/// <returns></returns>
public XDocument GetWarnings()
{
XDocument xReportDoc = new XDocument();
XElement xroot = new XElement(XName.Get("RoutingPreferenceAnalysis"));
xroot.Add(GetHeaderInformation());
XElement xWarnings = new XElement(XName.Get("Warnings"));
//None-range-warnings
foreach (RoutingPreferenceRuleGroupType groupType in Enum.GetValues(typeof(RoutingPreferenceRuleGroupType)).Cast<RoutingPreferenceRuleGroupType>())
{
if (IsRuleSetToRangeNone(m_routingPreferenceManager, groupType, 0))
{
XElement xNoRangeSet = new XElement(XName.Get("NoRangeSet"));
xNoRangeSet.Add(new XAttribute(XName.Get("groupType"), groupType.ToString()));
if (IsGroupSetToRangeNone(m_routingPreferenceManager, groupType))
{
xNoRangeSet.Add(new XAttribute(XName.Get("rule"), "allRules"));
}
else
{
xNoRangeSet.Add(new XAttribute(XName.Get("rule"), "firstRule"));
}
xWarnings.Add(xNoRangeSet);
}
}
//tee/tap warnings
if (!IsPreferredJunctionTypeValid(m_routingPreferenceManager))
{
XElement xJunctionFittingsNotDefined = new XElement(XName.Get("FittingsNotDefinedForPreferredJunction"));
xWarnings.Add(xJunctionFittingsNotDefined);
}
//size range warnings for elbow, Junction, and Cross
XElement xSegmentElbowWarning = GetSegmentRangeNotCoveredWarning(m_routingPreferenceManager, RoutingPreferenceRuleGroupType.Elbows);
if (xSegmentElbowWarning != null)
xWarnings.Add(xSegmentElbowWarning);
XElement xSegmentTeeWarning = GetSegmentRangeNotCoveredWarning(m_routingPreferenceManager, RoutingPreferenceRuleGroupType.Junctions);
if (xSegmentTeeWarning != null)
xWarnings.Add(xSegmentTeeWarning);
XElement xSegmentCrossWarning = GetSegmentRangeNotCoveredWarning(m_routingPreferenceManager, RoutingPreferenceRuleGroupType.Crosses);
if (xSegmentCrossWarning != null)
xWarnings.Add(xSegmentCrossWarning);
xroot.Add(xWarnings);
xReportDoc.Add(xroot);
return xReportDoc;
}
#endregion
#region Analyis helper methods
/// <summary>
/// Get basic information about the PipeType
/// </summary>
private XElement GetHeaderInformation()
{
XElement xHeader = new XElement(XName.Get("PipeType"));
string pipeTypeName = m_document.GetElement(m_routingPreferenceManager.OwnerId).Name;
xHeader.Add(new XAttribute(XName.Get("name"), pipeTypeName));
xHeader.Add(new XAttribute(XName.Get("elementId"), m_routingPreferenceManager.OwnerId.ToString()));
return xHeader;
}
/// <summary>
/// Checks to see if any segments in the routing preference manager have sizes that cannot be fitted with fittings defined in a rule group type, such as "Elbow."
/// For example, if a segment rule defines a segment be used from sizes 2" to 12", and there are three elbows rules defined to be used from ranges
/// 2"-4", 4"-7", and 9"-14", this method will return warning information specifying the sizes (8", 8.5", etc...) not covered by elbow fittings.
/// </summary>
private XElement GetSegmentRangeNotCoveredWarning(RoutingPreferenceManager routingPreferenceManager, RoutingPreferenceRuleGroupType groupType)
{
for (int index = 0; index != routingPreferenceManager.GetNumberOfRules(RoutingPreferenceRuleGroupType.Segments); ++index)
{
RoutingPreferenceRule rule = routingPreferenceManager.GetRule(RoutingPreferenceRuleGroupType.Segments, index);
if (rule.MEPPartId == ElementId.InvalidElementId)
continue;
if (rule.NumberOfCriteria == 0) //double check all/none
continue;
PrimarySizeCriterion psc = rule.GetCriterion(0) as PrimarySizeCriterion;
PipeSegment segment = m_document.GetElement(rule.MEPPartId) as PipeSegment;
List<double> sizesNotCovered = new List<double>();
bool isCovered = CheckSegmentForValidCoverage(routingPreferenceManager, psc.MinimumSize, psc.MaximumSize, rule.MEPPartId, groupType, sizesNotCovered);
if (!isCovered)
{
XElement xSegmentNotCovered = new XElement(XName.Get("SegmentRangeNotCovered"));
xSegmentNotCovered.Add(new XAttribute(XName.Get("name"), segment.Name));
StringBuilder sBuilder = new StringBuilder();
foreach (double size in sizesNotCovered)
{
double roundedSize = Convert.ConvertValueDocumentUnits(size, m_document);
sBuilder.Append(roundedSize.ToString() + " ");
}
sBuilder.Remove(sBuilder.Length - 1, 1);
xSegmentNotCovered.Add(new XAttribute(XName.Get("sizes"), sBuilder.ToString()));
xSegmentNotCovered.Add(new XAttribute(XName.Get("unit"), m_document.GetUnits().GetFormatOptions(SpecTypeId.PipeSize).GetUnitTypeId().TypeId));
xSegmentNotCovered.Add(new XAttribute(XName.Get("groupType"), groupType.ToString()));
return xSegmentNotCovered;
}
}
return null;
}
private bool CheckSegmentForValidCoverage(RoutingPreferenceManager routingPreferenceManager, double lowerBound, double upperBound, ElementId segmentId, RoutingPreferenceRuleGroupType groupType, List<double> sizesNotCovered)
{
bool retval = true;
if (segmentId == ElementId.InvalidElementId)
throw new Exception("Invalid segment ElementId");
PipeSegment segment = this.m_document.GetElement(segmentId) as PipeSegment;
foreach (MEPSize size in segment.GetSizes())
{
//skip sizes outside of rp bounds
if (size.NominalDiameter < lowerBound)
continue;
if (size.NominalDiameter > upperBound)
break;
RoutingConditions conditions = new RoutingConditions(RoutingPreferenceErrorLevel.None);
conditions.AppendCondition(new RoutingCondition(size.NominalDiameter));
ElementId foundFitting = routingPreferenceManager.GetMEPPartId(groupType, conditions);
if (foundFitting == ElementId.InvalidElementId)
{
sizesNotCovered.Add(size.NominalDiameter);
retval = false;
}
}
return retval;
}
private bool IsRuleSetToRangeNone(RoutingPreferenceManager routingPreferenceManager, RoutingPreferenceRuleGroupType groupType, int index)
{
if (routingPreferenceManager.GetNumberOfRules(groupType) == 0)
{
return false;
}
RoutingPreferenceRule rule = routingPreferenceManager.GetRule(groupType, index);
if (rule.NumberOfCriteria == 0)
{
return false;
}
PrimarySizeCriterion psc = rule.GetCriterion(0) as PrimarySizeCriterion;
if (psc.IsEqual(PrimarySizeCriterion.None()))
{
return true;
}
else
return false;
}
private bool IsGroupSetToRangeNone(RoutingPreferenceManager routingPreferenceManager, RoutingPreferenceRuleGroupType groupType)
{
bool retval = true;
if (routingPreferenceManager.GetNumberOfRules(groupType) == 0)
{
return false;
}
for (int index = 0; index != routingPreferenceManager.GetNumberOfRules(groupType); ++index)
{
if (!(IsRuleSetToRangeNone(routingPreferenceManager, groupType, index)))
retval = false;
}
return retval;
}
/// <summary>
/// Check to see if the routing preferences specify a preferred junction type but do not have any
/// rules with valid fittings for that type (e.g, "Tee" is the preferred junction type, but only "Tap" fittings
/// are specified in junction rules.)
/// </summary>
/// <param name="routingPreferenceManager"></param>
/// <returns></returns>
private bool IsPreferredJunctionTypeValid(RoutingPreferenceManager routingPreferenceManager)
{
PreferredJunctionType preferredJunctionType = routingPreferenceManager.PreferredJunctionType;
if (routingPreferenceManager.GetNumberOfRules(RoutingPreferenceRuleGroupType.Junctions) == 0)
return false;
bool teeDefined = false;
bool tapDefined = false;
for (int index = 0; index != routingPreferenceManager.GetNumberOfRules(RoutingPreferenceRuleGroupType.Junctions); ++index)
{
RoutingPreferenceRule rule = routingPreferenceManager.GetRule(RoutingPreferenceRuleGroupType.Junctions, index);
if (rule.MEPPartId == ElementId.InvalidElementId)
continue;
FamilySymbol familySymbol = this.m_document.GetElement(rule.MEPPartId) as FamilySymbol;
Parameter paramPartType = familySymbol.Family.get_Parameter(BuiltInParameter.FAMILY_CONTENT_PART_TYPE);
if (paramPartType == null)
throw new Exception("Null partType parameter.");
PartType partType = (PartType)paramPartType.AsInteger();
if ((partType == PartType.Tee))
teeDefined = true;
else if (
(partType == PartType.TapAdjustable) ||
(partType == PartType.TapPerpendicular) ||
(partType == PartType.SpudPerpendicular) ||
(partType == PartType.SpudAdjustable)
)
tapDefined = true;
}
if ((preferredJunctionType == PreferredJunctionType.Tap) && !tapDefined)
return false;
if ((preferredJunctionType == PreferredJunctionType.Tee) && !teeDefined)
return false;
return true;
}
private string GetFittingName(ElementId id)
{
if (id == ElementId.InvalidElementId)
throw new Exception("Invalid ElementId");
FamilySymbol symbol = m_document.GetElement(id) as FamilySymbol;
return symbol.Family.Name + " " + symbol.Name;
}
private string GetSegmentName(ElementId id)
{
if (id == ElementId.InvalidElementId)
throw new Exception("Invalid ElementId");
PipeSegment segment = m_document.GetElement(id) as PipeSegment;
return segment.Name;
}
/// <summary>
///Using routing preferences, display found segment and fitting info from the size and pipe type specified in the dialog.
/// </summary>
private List<PartIdInfo> GetPreferredFittingsAndSegments()
{
List<PartIdInfo> partIdInfoList = new List<PartIdInfo>();
RoutingConditions conditions = new RoutingConditions(RoutingPreferenceErrorLevel.None);
conditions.AppendCondition(new RoutingCondition(m_mepSize));
foreach (RoutingPreferenceRuleGroupType groupType in Enum.GetValues(typeof(RoutingPreferenceRuleGroupType)))
{
if (groupType == RoutingPreferenceRuleGroupType.Undefined)
continue;
IList<ElementId> preferredTypes = new List<ElementId>();
ElementId preferredType = m_routingPreferenceManager.GetMEPPartId(groupType, conditions);
//GetMEPPartId is the main "query" method of the
//routing preferences API that evaluates conditions and criteria and returns segment and fitting elementIds that meet
//those criteria.
if (groupType != RoutingPreferenceRuleGroupType.Segments)
{
preferredTypes.Add(preferredType);
}
else //Get all segments that support a given size, not just the first segment.
{
preferredTypes = m_routingPreferenceManager.GetSharedSizes(m_mepSize, ConnectorProfileType.Round);
}
partIdInfoList.Add(new PartIdInfo(groupType, preferredTypes)); //Collect a PartIdInfo object for each group type.
}
return partIdInfoList;
}
#endregion
}
}
@@ -0,0 +1,72 @@
//
// (C) Copyright 2003-2019 by Autodesk, Inc.
//
// Permission to use, copy, modify, and distribute this software in
// object code form for any purpose and without fee is hereby granted,
// provided that the above copyright notice appears in all copies and
// that both that copyright notice and the limited warranty and
// restricted rights notice below appear in all supporting
// documentation.
//
// AUTODESK PROVIDES THIS PROGRAM "AS IS" AND WITH ALL FAULTS.
// AUTODESK SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTY OF
// MERCHANTABILITY OR FITNESS FOR A PARTICULAR USE. AUTODESK, INC.
// DOES NOT WARRANT THAT THE OPERATION OF THE PROGRAM WILL BE
// UNINTERRUPTED OR ERROR FREE.
//
// Use, duplication, or disclosure by the U.S. Government is subject to
// restrictions set forth in FAR 52.227-19 (Commercial Computer
// Software - Restricted Rights) and DFAR 252.227-7013(c)(1)(ii)
// (Rights in Technical Data and Computer Software), as applicable.
//
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Autodesk.Revit.DB;
namespace Revit.SDK.Samples.RoutingPreferenceTools.CS
{
/// <summary>
/// Main Revit command
/// </summary>
[Autodesk.Revit.Attributes.Transaction(Autodesk.Revit.Attributes.TransactionMode.ReadOnly)]
public class Command : Autodesk.Revit.UI.IExternalCommand
{
/// <summary>
/// Implement this method as an external command for Revit.
/// </summary>
/// <param name="commandData">An object that is passed to the external application
/// which contains data related to the command,
/// such as the application object and active view.</param>
/// <param name="message">A message that can be set by the external application
/// which will be displayed if a failure or cancellation is returned by
/// the external command.</param>
/// <param name="elements">A set of elements to which the external application
/// can add elements that are to be highlighted in case of failure or cancellation.</param>
/// <returns>Return the status of the external command.
/// A result of Succeeded means that the API external method functioned as expected.
/// Cancelled can be used to signify that the user cancelled the external operation
/// at some point. Failure should be returned if the application is unable to proceed with
/// the operation.</returns>
public Autodesk.Revit.UI.Result Execute(Autodesk.Revit.UI.ExternalCommandData commandData, ref string message, Autodesk.Revit.DB.ElementSet elements)
{
if (!Validation.ValidateMep(commandData.Application.Application))
{
Validation.MepWarning();
return Autodesk.Revit.UI.Result.Succeeded;
}
if (!Validation.ValidatePipesDefined(commandData.Application.ActiveUIDocument.Document))
{
Validation.PipesDefinedWarning();
return Autodesk.Revit.UI.Result.Succeeded;
}
MainWindow mainWindow = new MainWindow(commandData.Application);
mainWindow.ShowDialog();
return Autodesk.Revit.UI.Result.Succeeded;
}
}
}
@@ -0,0 +1,31 @@
<Window x:Class="Revit.SDK.Samples.RoutingPreferenceTools.CS.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
mc:Ignorable="d"
Height="325" Width="500" Title="Routing Preference Analysis">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition></ColumnDefinition>
<ColumnDefinition></ColumnDefinition>
<ColumnDefinition></ColumnDefinition>
<ColumnDefinition></ColumnDefinition>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="30"></RowDefinition>
<RowDefinition Height="30"></RowDefinition>
<RowDefinition Height="30"></RowDefinition>
<RowDefinition Height="30"></RowDefinition>
<RowDefinition Height="30"></RowDefinition>
<RowDefinition Height="200"></RowDefinition>
</Grid.RowDefinitions>
<Label Grid.Row="0" Name="label_SelectPipeType">Select a pipe type.</Label>
<ComboBox Grid.Row="0" Grid.Column="1" Grid.ColumnSpan="3" Name="comboBox_PipeTypes" SelectionChanged="comboBox_PipeTypes_SelectionChanged"></ComboBox>
<Button Grid.Row="2" Grid.ColumnSpan="2" Name="button_CheckWarnings" Click="button_CheckWarnings_Click">Check All Routing Preferences</Button>
<Button Grid.Row="2" Grid.Column="2" Name="button_CheckSpecificSize" Click="button_CheckSpecificSize_Click">Check Specific Size</Button>
<ComboBox Grid.Row="2" Grid.Column="3" Name="comboBox_Sizes"></ComboBox>
<Label Grid.Row="3" Name="label_Warnings">Output</Label>
<TextBox Grid.Row="4" Grid.ColumnSpan="4" Grid.RowSpan="2" Name="textBox_output"></TextBox>
</Grid>
</Window>
@@ -0,0 +1,181 @@
//
// (C) Copyright 2003-2019 by Autodesk, Inc.
//
// Permission to use, copy, modify, and distribute this software in
// object code form for any purpose and without fee is hereby granted,
// provided that the above copyright notice appears in all copies and
// that both that copyright notice and the limited warranty and
// restricted rights notice below appear in all supporting
// documentation.
//
// AUTODESK PROVIDES THIS PROGRAM "AS IS" AND WITH ALL FAULTS.
// AUTODESK SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTY OF
// MERCHANTABILITY OR FITNESS FOR A PARTICULAR USE. AUTODESK, INC.
// DOES NOT WARRANT THAT THE OPERATION OF THE PROGRAM WILL BE
// UNINTERRUPTED OR ERROR FREE.
//
// Use, duplication, or disclosure by the U.S. Government is subject to
// restrictions set forth in FAR 52.227-19 (Commercial Computer
// Software - Restricted Rights) and DFAR 252.227-7013(c)(1)(ii)
// (Rights in Technical Data and Computer Software), as applicable.
//
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using Autodesk.Revit.DB;
using Autodesk.Revit.DB.Plumbing;
using System.Xml;
using System.Xml.Linq;
namespace Revit.SDK.Samples.RoutingPreferenceTools.CS
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
/// <summary>
/// Constructor
/// </summary>
/// <param name="application"></param>
public MainWindow(Autodesk.Revit.UI.UIApplication application)
{
InitializeComponent();
m_application = application;
if (m_application.ActiveUIDocument == null)
{
Autodesk.Revit.UI.TaskDialog.Show("RP Analysis", "Null Document");
this.Close();
}
PopulatePipeTypeList();
PopulateSizeList();
}
/// <summary>
/// Get the selected pipe size (in inches) from the dialog
/// </summary>
private double GetSelectedSize()
{
return double.Parse(comboBox_Sizes.SelectedItem.ToString());
}
/// <summary>
/// Display all sizes available in given pipe type in the dialog.
/// </summary>
private void PopulateSizeList()
{
comboBox_Sizes.Items.Clear();
List<double> sizes = Analyzer.GetAvailableSegmentSizes(GetSelectedPipeType().RoutingPreferenceManager, m_application.ActiveUIDocument.Document);
foreach (double size in sizes)
{
double unitAdjustedSize = Convert.ConvertValueDocumentUnits(size, m_application.ActiveUIDocument.Document);
comboBox_Sizes.Items.Add(unitAdjustedSize.ToString());
}
comboBox_Sizes.SelectedIndex = 0;
}
/// <summary>
/// Get all the PipeTypes in the document and display them in the window's combo box.
/// </summary>
private void PopulatePipeTypeList()
{
FilteredElementCollector collector = new FilteredElementCollector(m_application.ActiveUIDocument.Document);
collector.OfClass(typeof(PipeType));
foreach (PipeType pipeType in collector.ToElements().Cast<PipeType>())
{
comboBox_PipeTypes.Items.Add(pipeType.Name + ", Id: " + pipeType.Id);
}
comboBox_PipeTypes.SelectedIndex = 0;
}
/// <summary>
/// Look up a pipe type by ElementId string and return it.
/// </summary>
/// <returns></returns>
private PipeType GetSelectedPipeType()
{
string selectedString = comboBox_PipeTypes.SelectedItem.ToString();
string[] selectedsplit = selectedString.Split(':');
if (selectedsplit.Length != 2)
throw new ArgumentException();
ElementId id = new ElementId(int.Parse(selectedsplit[1]));
return m_application.ActiveUIDocument.Document.GetElement(id) as PipeType;
}
/// <summary>
/// Get the selected PipeType from the combo box in the window, get its RoutingPreferenceManager, and analyze it for problems.
/// Write all potential problems to the window's text field as formatted XML.
/// </summary>
private void button_CheckWarnings_Click(object sender, RoutedEventArgs e)
{
Analyzer routingPrefernceAnalyzer = new Analyzer(GetSelectedPipeType().RoutingPreferenceManager, this.m_application.ActiveUIDocument.Document);
XDocument results = routingPrefernceAnalyzer.GetWarnings();
XmlWriterSettings xmlWriterSettings = new XmlWriterSettings();
xmlWriterSettings.Indent = true;
xmlWriterSettings.NewLineOnAttributes = false;
StringBuilder output = new StringBuilder();
XmlWriter writer = XmlWriter.Create(output, xmlWriterSettings);
results.WriteTo(writer);
writer.Flush();
writer.Close();
this.textBox_output.Text = output.ToString();
}
/// <summary>
/// Button CheckSpecificSize click event handler
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void button_CheckSpecificSize_Click(object sender, RoutedEventArgs e)
{
Analyzer routingPrefernceAnalyzer = new Analyzer(GetSelectedPipeType().RoutingPreferenceManager, GetSelectedSize(), this.m_application.ActiveUIDocument.Document);
XDocument results = routingPrefernceAnalyzer.GetSpecificSizeQuery();
XmlWriterSettings xmlWriterSettings = new XmlWriterSettings();
xmlWriterSettings.Indent = true;
xmlWriterSettings.NewLineOnAttributes = false;
StringBuilder output = new StringBuilder();
XmlWriter writer = XmlWriter.Create(output, xmlWriterSettings);
results.WriteTo(writer);
writer.Flush();
writer.Close();
this.textBox_output.Text = output.ToString();
}
/// <summary>
/// ComboBox PipeTypes selection changed event handler
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void comboBox_PipeTypes_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
PopulateSizeList();
}
private Autodesk.Revit.UI.UIApplication m_application;
}
}
@@ -0,0 +1,133 @@
//
// (C) Copyright 2003-2019 by Autodesk, Inc.
//
// Permission to use, copy, modify, and distribute this software in
// object code form for any purpose and without fee is hereby granted,
// provided that the above copyright notice appears in all copies and
// that both that copyright notice and the limited warranty and
// restricted rights notice below appear in all supporting
// documentation.
//
// AUTODESK PROVIDES THIS PROGRAM "AS IS" AND WITH ALL FAULTS.
// AUTODESK SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTY OF
// MERCHANTABILITY OR FITNESS FOR A PARTICULAR USE. AUTODESK, INC.
// DOES NOT WARRANT THAT THE OPERATION OF THE PROGRAM WILL BE
// UNINTERRUPTED OR ERROR FREE.
//
// Use, duplication, or disclosure by the U.S. Government is subject to
// restrictions set forth in FAR 52.227-19 (Commercial Computer
// Software - Restricted Rights) and DFAR 252.227-7013(c)(1)(ii)
// (Rights in Technical Data and Computer Software), as applicable.
//
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Autodesk.Revit.DB;
using Autodesk.Revit.DB.Plumbing;
using System.Xml.Linq;
namespace Revit.SDK.Samples.RoutingPreferenceTools.CS
{
/// <summary>
/// This class 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.
/// </summary>
public class PartIdInfo
{
// List of part Ids
private List<ElementId> m_ids;
// group type
private RoutingPreferenceRuleGroupType m_groupType;
/// <summary>
/// Id
/// </summary>
public List<ElementId> Id
{
get { return m_ids; }
}
/// <summary>
/// Group type
/// </summary>
public RoutingPreferenceRuleGroupType GroupType
{
get { return m_groupType; }
}
/// <summary>
/// Constructor
/// </summary>
/// <param name="groupType"></param>
/// <param name="ids"></param>
public PartIdInfo(RoutingPreferenceRuleGroupType groupType, IList<ElementId> ids)
{
m_ids = new List<ElementId>();
m_groupType = groupType;
m_ids.AddRange(ids);
}
/// <summary>
/// Build XML information of document
/// </summary>
/// <param name="document"></param>
/// <returns></returns>
public XElement GetXml(Autodesk.Revit.DB.Document document)
{
XElement xPartInfo = new XElement(XName.Get("PartInfo"));
xPartInfo.Add(new XAttribute(XName.Get("groupType"), m_groupType.ToString()));
xPartInfo.Add(new XAttribute(XName.Get("partNames"), GetFittingNames(document)));
return xPartInfo;
}
private string GetFittingName(Document document, ElementId id)
{
string fittingName = " None ";
if (id != ElementId.InvalidElementId)
{
Element element = document.GetElement(id);
if (element is Segment)
{
fittingName = element.Name;
}
else
{
FamilySymbol familySymbol = element as FamilySymbol;
fittingName = familySymbol.Family.Name + " " + familySymbol.Name;
}
}
return fittingName;
}
/// <summary>
/// Fitting name
/// </summary>
/// <param name="document"></param>
/// <returns></returns>
private string GetFittingNames(Document document)
{
string fittingNames = "";
if (m_ids.Count == 0)
{
fittingNames += "None -1";
}
foreach (ElementId id in m_ids)
{
fittingNames += GetFittingName(document, id) + " " + id.ToString() + ", ";
}
return fittingNames.Remove(fittingNames.Length - 2, 2);
}
}
}