/// <summary> /// 获取所有楼层 /// </summary> /// <param name="doc"></param> /// <param name="model"></param> /// <param name="units"></param> private static void GetLevels(Document doc, ProjectModel model, UnitConversionFactors units) { var levels = doc.GetElements <Level>(); foreach (var l in levels) { var ll = l.GetLevel(units); model.Levels.Add(ll); } }
/// <summary> /// /// </summary> /// <param name="level"></param> /// <param name="units"></param> /// <returns></returns> public static LevelElement GetLevel(this Level level, UnitConversionFactors units) { var dLevel = new LevelElement { Id = level.Id.IntegerValue, Name = level.Name, Guid = level.UniqueId, Elevation = Math.Round(units.LengthRatio * level.Elevation, 0) + "mm", ProjectElevation = Math.Round(units.LengthRatio * level.ProjectElevation, 0) + "mm" }; return(dLevel); }
/// <summary> /// 从构件上获取楼层信息 /// </summary> /// <param name="e"></param> /// <param name="doc"></param> /// <param name="units"></param> /// <returns></returns> public static LevelElement GetLevel(this Autodesk.Revit.DB.Element e, Document doc, UnitConversionFactors units) { if (!e.LevelId.Equals(ElementId.InvalidElementId)) { var level = (Level)ElementFilterUtils.GetElement(doc, e.LevelId); return(level.GetLevel(units)); } var l = GetLevelFromParam(doc, e); if (l != null) { return(l.GetLevel(units)); } return(null); }
private static void GetElements(Document doc, ProjectModel model, UnitConversionFactors units) { ElementId viewId = null; if (doc.ActiveView != null) { viewId = doc.ActiveView.Id; } var elems = doc.GetAllElements(viewId); foreach (var e in elems) { if (e is Level || e is View || e is Material || e is Family || e is RevitLinkInstance) { continue; } var elem = e.GetElement(doc); if (elem == null) { continue; } //类别 if (elem.Category == null)//过滤没有类别的构件 { continue; } if (!model.Categories.Contains(elem.Category)) { model.Categories.Add(elem.Category); } //类型 var type = e.GetElementType(doc); if (type == null) //过滤没有类型的构件 { continue; } var t = model.Types.FirstOrDefault(c => c.Id == type.Id.IntegerValue); if (t == null) { t = type.GetElementType(doc); model.Types.Add(t); } elem.ElemType = t.GetKey(); //族 var famInst = e as FamilyInstance; if (famInst != null) { var fam = model.Families.FirstOrDefault(c => c.Id == famInst.Symbol.Family.Id.IntegerValue);// if (fam == null) { fam = famInst.Symbol.Family.GetFamily(doc); model.Families.Add(fam); } elem.Family = fam.GetKey(); } //楼层 var l = e.GetLevel(doc, units); if (l != null) { elem.Level = l.GetKey(); var ll = model.Levels.FirstOrDefault(c => c.Id == l.Id); if (ll == null) { model.Levels.Add(l); } } //材料 var mat = MaterialUtils.GetMaterial(e, doc); if (mat != null) { var mm = model.Materials.FirstOrDefault(c => c.Id == mat.Id.IntegerValue);// if (mm == null) { mm = GetMat(doc, mat); model.Materials.Add(mm); } elem.Material = mm.GetKey(); } model.Elements.Add(elem); } }