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); } }
/// <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); }
/// <summary> /// Create Xml from a RoutingPreferenceManager /// </summary> /// <param name="routingPreferenceManager"></param> /// <returns></returns> private XElement CreateXmlFromRoutingPreferenceManager(RoutingPreferenceManager routingPreferenceManager) { XElement xRoutingPreferenceManager = new XElement(XName.Get("RoutingPreferenceManager")); xRoutingPreferenceManager.Add(new XAttribute(XName.Get("pipeTypeName"), GetPipeTypeNameById(routingPreferenceManager.OwnerId))); xRoutingPreferenceManager.Add(new XAttribute(XName.Get("preferredJunctionType"), routingPreferenceManager.PreferredJunctionType.ToString())); for (int indexCrosses = 0; indexCrosses != routingPreferenceManager.GetNumberOfRules(RoutingPreferenceRuleGroupType.Crosses); indexCrosses++) { xRoutingPreferenceManager.Add(createXmlFromRoutingPreferenceRule(routingPreferenceManager.GetRule(RoutingPreferenceRuleGroupType.Crosses, indexCrosses), RoutingPreferenceRuleGroupType.Crosses)); } for (int indexElbows = 0; indexElbows != routingPreferenceManager.GetNumberOfRules(RoutingPreferenceRuleGroupType.Elbows); indexElbows++) { xRoutingPreferenceManager.Add(createXmlFromRoutingPreferenceRule(routingPreferenceManager.GetRule(RoutingPreferenceRuleGroupType.Elbows, indexElbows), RoutingPreferenceRuleGroupType.Elbows)); } for (int indexSegments = 0; indexSegments != routingPreferenceManager.GetNumberOfRules(RoutingPreferenceRuleGroupType.Segments); indexSegments++) { xRoutingPreferenceManager.Add(createXmlFromRoutingPreferenceRule(routingPreferenceManager.GetRule(RoutingPreferenceRuleGroupType.Segments, indexSegments), RoutingPreferenceRuleGroupType.Segments)); } for (int indexJunctions = 0; indexJunctions != routingPreferenceManager.GetNumberOfRules(RoutingPreferenceRuleGroupType.Junctions); indexJunctions++) { xRoutingPreferenceManager.Add(createXmlFromRoutingPreferenceRule(routingPreferenceManager.GetRule(RoutingPreferenceRuleGroupType.Junctions, indexJunctions), RoutingPreferenceRuleGroupType.Junctions)); } for (int indexTransitions = 0; indexTransitions != routingPreferenceManager.GetNumberOfRules(RoutingPreferenceRuleGroupType.Transitions); indexTransitions++) { xRoutingPreferenceManager.Add(createXmlFromRoutingPreferenceRule(routingPreferenceManager.GetRule(RoutingPreferenceRuleGroupType.Transitions, indexTransitions), RoutingPreferenceRuleGroupType.Transitions)); } for (int indexUnions = 0; indexUnions != routingPreferenceManager.GetNumberOfRules(RoutingPreferenceRuleGroupType.Unions); indexUnions++) { xRoutingPreferenceManager.Add(createXmlFromRoutingPreferenceRule(routingPreferenceManager.GetRule(RoutingPreferenceRuleGroupType.Unions, indexUnions), RoutingPreferenceRuleGroupType.Unions)); } for (int indexMechanicalJoints = 0; indexMechanicalJoints != routingPreferenceManager.GetNumberOfRules(RoutingPreferenceRuleGroupType.MechanicalJoints); indexMechanicalJoints++) { xRoutingPreferenceManager.Add(createXmlFromRoutingPreferenceRule(routingPreferenceManager.GetRule(RoutingPreferenceRuleGroupType.MechanicalJoints, indexMechanicalJoints), RoutingPreferenceRuleGroupType.MechanicalJoints)); } return(xRoutingPreferenceManager); }
/// <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(UnitType.UT_PipeSize).DisplayUnits.ToString())); xSegmentNotCovered.Add(new XAttribute(XName.Get("groupType"), groupType.ToString())); return(xSegmentNotCovered); } } return(null); }
/// <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); }