示例#1
0
        /// <summary>
        /// Create a RoutingPreferenceRule from Xml
        /// </summary>
        /// <param name="ruleXElement"></param>
        /// <param name="groupType"></param>
        /// <returns></returns>
        private RoutingPreferenceRule ParseRoutingPreferenceRuleFromXML(XElement ruleXElement, out RoutingPreferenceRuleGroupType groupType)
        {
            XAttribute xaDescription = null;
            XAttribute xaPartName    = null;
            XAttribute xaMinSize     = null;
            XAttribute xaMaxSize     = null;
            XAttribute xaGroup       = null;

            xaDescription = ruleXElement.Attribute(XName.Get("description"));
            xaPartName    = ruleXElement.Attribute(XName.Get("partName"));
            xaGroup       = ruleXElement.Attribute(XName.Get("ruleGroup"));
            xaMinSize     = ruleXElement.Attribute(XName.Get("minimumSize"));

            ElementId partId;

            bool r3 = Enum.TryParse <RoutingPreferenceRuleGroupType>(xaGroup.Value, out groupType);

            if (!r3)
            {
                throw new RoutingPreferenceDataException("Could not parse rule group type: " + xaGroup.Value);
            }

            string description = xaDescription.Value;

            if (groupType == RoutingPreferenceRuleGroupType.Segments)
            {
                partId = GetSegmentByName(xaPartName.Value);
            }
            else
            {
                partId = GetFittingByName(xaPartName.Value);
            }

            if (partId == ElementId.InvalidElementId)
            {
                throw new RoutingPreferenceDataException("Could not find MEP Part: " + xaPartName.Value + ".  Is this the correct family name, and is the correct family loaded?");
            }

            RoutingPreferenceRule rule = new RoutingPreferenceRule(partId, description);


            PrimarySizeCriterion sizeCriterion;

            if (string.Compare(xaMinSize.Value, "All", true) == 0) //If "All" or "None" are specified, set min and max values to documented "Max" values.
            {
                sizeCriterion = PrimarySizeCriterion.All();
            }
            else if (string.Compare(xaMinSize.Value, "None", true) == 0)
            {
                sizeCriterion = PrimarySizeCriterion.None();
            }
            else // "maximumSize" attribute is only needed if not specifying "All" or "None."
            {
                try
                {
                    xaMaxSize = ruleXElement.Attribute(XName.Get("maximumSize"));
                }
                catch (System.Exception)
                {
                    throw new RoutingPreferenceDataException("Cannot get maximumSize attribute in: " + ruleXElement.ToString());
                }
                double min, max;
                bool   r1 = double.TryParse(xaMinSize.Value, out min);
                bool   r2 = double.TryParse(xaMaxSize.Value, out max);
                if (!r1 || !r2)
                {
                    throw new RoutingPreferenceDataException("Could not parse size values: " + xaMinSize.Value + ", " + xaMaxSize.Value);
                }
                if (min > max)
                {
                    throw new RoutingPreferenceDataException("Invalid size range.");
                }

                min           = Convert.ConvertValueToFeet(min, m_document);
                max           = Convert.ConvertValueToFeet(max, m_document);
                sizeCriterion = new PrimarySizeCriterion(min, max);
            }

            rule.AddCriterion(sizeCriterion);

            return(rule);
        }
示例#2
0
        /// <summary>
        /// 检测系统中是否有默认连接项,无则进行添加
        /// </summary>
        /// <param name="src"></param>
        /// <param name="type"></param>
        protected FamilySymbol Judge_LoadDefaultFitting(MEPCurve src, MEPCurveConnectTypeENUM type)
        {
            FamilySymbol fs = null;

            switch (type)
            {
            case MEPCurveConnectTypeENUM.Elbow:    //弯头
                fs = src.GetDefaultFittingSymbol(RoutingPreferenceRuleGroupType.Elbows); break;

            case MEPCurveConnectTypeENUM.Tee:    //三通
                fs = src.GetDefaultFittingSymbol(RoutingPreferenceRuleGroupType.Junctions); break;

            case MEPCurveConnectTypeENUM.Cross:    //四通
                fs = src.GetDefaultFittingSymbol(RoutingPreferenceRuleGroupType.Crosses); break;

            case MEPCurveConnectTypeENUM.Transition:    //过渡件
                fs = src.GetDefaultFittingSymbol(RoutingPreferenceRuleGroupType.Transitions); break;

            case MEPCurveConnectTypeENUM.TakeOff:    //侧接
                fs = src.GetDefaultTakeoffFittingSymbol(); break;

            default:
                fs = null;
                break;
            }

            if (fs != null)
            {
                return(fs);
            }

            if (this.IsOnlyUseRevitDefault)
            {
                return(null);
            }

            var familyName = this.GetDefaultFittingName(src, type);

            if (familyName == null)
            {
                return(null);
            }

            fs = FamilyLoadUtils.FindFamilySymbol_SubTransaction(src.Document, familyName, null);
            if (fs == null)
            {
                return(null);
            }
            if (src is Pipe || src is Duct)
            {
                RoutingPreferenceManager rpm = src.GetMEPCurveType().RoutingPreferenceManager;
                var rule = new RoutingPreferenceRule(fs.Id, "");
                rule.AddCriterion(PrimarySizeCriterion.All());

                switch (type)
                {
                case MEPCurveConnectTypeENUM.Elbow:    //弯头
                    rpm.AddRule(RoutingPreferenceRuleGroupType.Elbows, rule); break;

                case MEPCurveConnectTypeENUM.Tee:    //三通
                    rpm.AddRule(RoutingPreferenceRuleGroupType.Junctions, rule); break;

                case MEPCurveConnectTypeENUM.Cross:    //四通
                    rpm.AddRule(RoutingPreferenceRuleGroupType.Crosses, rule); break;

                case MEPCurveConnectTypeENUM.Transition:    //过渡件
                    rpm.AddRule(RoutingPreferenceRuleGroupType.Transitions, rule); break;

                case MEPCurveConnectTypeENUM.TakeOff:    //侧接
                    rpm.AddRule(RoutingPreferenceRuleGroupType.Junctions, rule); break;

                default:
                    break;
                }
            }
            else if (src is Conduit)
            {
                Parameter param = null;

                switch (type)
                {
                case MEPCurveConnectTypeENUM.Elbow:    //弯头
                    param = (src.Document.GetElement(src.GetTypeId())).GetParameters("弯头").FirstOrDefault(); break;

                case MEPCurveConnectTypeENUM.Tee:    //三通
                    param = (src.Document.GetElement(src.GetTypeId())).GetParameters("T 形三通").FirstOrDefault(); break;

                case MEPCurveConnectTypeENUM.Cross:    //四通
                    param = (src.Document.GetElement(src.GetTypeId())).GetParameters("交叉线").FirstOrDefault(); break;

                case MEPCurveConnectTypeENUM.Transition:    //过渡件
                    param = (src.Document.GetElement(src.GetTypeId())).GetParameters("过渡件").FirstOrDefault(); break;

                default:
                    break;
                }

                if (param != null)
                {
                    param.Set(fs.Id);
                }
            }
            else if (src is CableTray)
            {
                Parameter param = null;
                var       t     = new FilteredElementCollector(src.Document).OfClass(typeof(CableTrayType)).FirstOrDefault(p => p.GetParameters("族名称").First().AsString() == "带配件的电缆桥架");
                switch (type)
                {
                case MEPCurveConnectTypeENUM.Elbow:    //弯头
                    param = t.GetParameters("水平弯头").FirstOrDefault(); break;

                case MEPCurveConnectTypeENUM.Tee:    //三通
                    param = t.GetParameters("T 形三通").FirstOrDefault(); break;

                case MEPCurveConnectTypeENUM.Cross:    //四通
                    param = t.GetParameters("交叉线").FirstOrDefault(); break;

                case MEPCurveConnectTypeENUM.Transition:    //过渡件
                    param = t.GetParameters("过渡件").FirstOrDefault(); break;

                default:
                    break;
                }

                if (param != null)
                {
                    param.Set(fs.Id);
                }
            }
            return(fs);
        }