void GetPipePiameter() { ElementClassFilter instanceFilter = new ElementClassFilter(typeof(FamilyInstance)); ElementClassFilter hostFilter = new ElementClassFilter(typeof(HostObject)); LogicalOrFilter andFilter = new LogicalOrFilter(instanceFilter, hostFilter); FilteredElementCollector collector = new FilteredElementCollector(m_uIDocument.Document); collector.WherePasses(andFilter); Dictionary <string, float> m_dic = new Dictionary <string, float>(); List <Element> eles = new List <Element>(); float piameter = 0; MtCommon.WriteStringIntoText("总共:" + collector.Count().ToString()); int index = 0; foreach (var ele in collector) { if (m_IsCreateFile) { var content = MtCommon.ReadStringFromText(); content += "\r\n" + $"索引{index}:" + ele.Id.ToString(); MtCommon.WriteStringIntoText(content); index++; } string eleID = ele.Id.ToString(); //判断是否是设备,通过设备编码参数,判断是否为设备,设备的直径默认设置为10000 var equipCode = MtCommon.GetOneParameter(ele, MtCommon.GetStringValue(Parameters.EquipmentCode)); if (!string.IsNullOrEmpty(equipCode)) { piameter = 10000f; } else { //获取管道直径参数:只要包含“直径”二字的选择一个作为直径参数 var paramter = GetParameterWithPiameterParam(ele, "直径"); if (paramter != null && paramter.Count != 0) { foreach (var item in paramter) { var value = GetMultiNumbers(item.AsValueString()).FirstOrDefault(); piameter += value; } piameter = (int)(piameter / paramter.Count); } else { //没有直径参数的,利用宽高等参数判断,取中值 var width = GetParameterWithPiameterParam(ele, "风管宽度").FirstOrDefault();; var height = GetParameterWithPiameterParam(ele, "风管高度").FirstOrDefault(); if (width != null && height != null) { var widthValue = GetMultiNumbers(width.AsValueString()).FirstOrDefault(); var heightValue = GetMultiNumbers(height.AsValueString()).FirstOrDefault(); piameter = (int)((widthValue + heightValue) / 2); } else { //利用尺寸200x100,200x100200x100,只取前后两位计算 var size = MtCommon.GetOneParameter(ele, "尺寸"); if (!string.IsNullOrEmpty(size)) { var result = GetMultiNumbers(size); if (result.Count >= 2) { piameter = (int)((result[0] + result[result.Count - 1]) / 2); } else if (result.Count == 1) { piameter = result[0]; } else { piameter = 0; } } else { piameter = 0f; } } } } var campus = MtCommon.GetOneParameter(ele, MtCommon.GetStringValue(Parameters.Campus)); var build = MtCommon.GetOneParameter(ele, MtCommon.GetStringValue(Parameters.Building)); var level = MtCommon.GetOneParameter(ele, MtCommon.GetStringValue(Parameters.MtLevel)); var verticalPipe = MtCommon.GetOneParameter(ele, MtCommon.GetStringValue(Parameters.VerticalPipe)); string pipeCode = string.Empty; if (verticalPipe.Equals("1-1")) { pipeCode = campus + "-" + build + "-" + level + "_" + m_SystemCode + "_" + ele.Id + "#L"; } else { pipeCode = campus + "-" + build + "-" + level + "_" + m_SystemCode + "_" + ele.Id; } if (!m_dic.ContainsKey(pipeCode)) { m_dic.Add(pipeCode, piameter); eles.Add(ele); } piameter = 0; } MtCommon.HideElements(m_uIDocument.Document, eles); m_sqlite = new MtSQLite(m_sqliteFilePath); List <string> quarays = new List <string>(); foreach (var item in m_dic) { quarays.Add($"Update Facility_Pipe Set diameter = '{item.Value}' where code = '{item.Key}'"); //quarays.Add($"Insert into Pipe (code,diameter) values ('{item.Key}','{item.Value}')"); } m_sqlite.ExecuteNoneQuery(quarays.ToArray()); }