/// <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 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> /// 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); }
void SelectAndPlaceTakeOffFitting(Document doc) { ElementId mainDuctId = ElementId.InvalidElementId; // Get DuctType - we need this for its // RoutingPreferenceManager. This is how we assign // our tap object to be used. This is the settings // for the duct object we attach our tap to. Duct duct = doc.GetElement(mainDuctId) as Duct; DuctType ductType = duct.DuctType; RoutingPreferenceManager routePrefManager = ductType.RoutingPreferenceManager; // Set Junction Prefernce to Tap. routePrefManager.PreferredJunctionType = PreferredJunctionType.Tap; // For simplicity sake, I remove all previous rules // for taps so I can just add what I want here. // This will probably vary. int initRuleCount = routePrefManager.GetNumberOfRules( RoutingPreferenceRuleGroupType.Junctions); for (int i = 0; i != initRuleCount; ++i) { routePrefManager.RemoveRule( RoutingPreferenceRuleGroupType.Junctions, 0); } // Get FamilySymbol for Tap I want to use. FamilySymbol tapSym = null; doc.LoadFamilySymbol("C:/FamilyLocation/MyTap.rfa", "MyTap", out tapSym); // Symbol needs to be activated before use. if ((!tapSym.IsActive) && (tapSym != null)) { tapSym.Activate(); doc.Regenerate(); } // Create Rule that utilizes the Tap. Use the argument // MEPPartId = ElementId for the desired FamilySymbol. RoutingPreferenceRule newRule = new RoutingPreferenceRule(tapSym.Id, "MyTap"); routePrefManager.AddRule( RoutingPreferenceRuleGroupType.Junctions, newRule); // To create a solid tap, we need to use the Revit // doc.Create.NewTakeoffFitting routine. For this, // we need a connector. If we don't have one, we // just create a temporary object with a connector // where we want it. Connector tmpConn = CreateTemporaryConnectorForTap(); // Create our tap. FamilyInstance tapInst = doc.Create.NewTakeoffFitting(tmpConn, duct); }