// // (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 { /// /// 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. /// public class PartIdInfo { // List of part Ids private List m_ids; // group type private RoutingPreferenceRuleGroupType m_groupType; /// /// Id /// public List Id { get { return m_ids; } } /// /// Group type /// public RoutingPreferenceRuleGroupType GroupType { get { return m_groupType; } } /// /// Constructor /// /// /// public PartIdInfo(RoutingPreferenceRuleGroupType groupType, IList ids) { m_ids = new List(); m_groupType = groupType; m_ids.AddRange(ids); } /// /// Build XML information of document /// /// /// 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; } /// /// Fitting name /// /// /// 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); } } }