public static IEnumerable <Core.SAMObject> ToSAM(this Document document, System.Type type, Core.Revit.ConvertSettings convertSettings, Transform transform = null, Phase phase = null) { if (document == null || type == null) { return(null); } if (transform == null) { transform = Transform.Identity; } FilteredElementCollector filteredElementCollector = Query.FilteredElementCollector(document, type); List <Element> elements = filteredElementCollector?.ToList(); if (elements == null) { return(null); } if (phase != null) { for (int i = elements.Count - 1; i >= 0; i--) { ElementOnPhaseStatus elementOnPhaseStatus = elements[i].GetPhaseStatus(phase.Id); if (elementOnPhaseStatus == ElementOnPhaseStatus.Past || elementOnPhaseStatus == ElementOnPhaseStatus.Demolished || elementOnPhaseStatus == ElementOnPhaseStatus.Future) { elements.RemoveAt(i); } } } List <Core.SAMObject> result = new List <Core.SAMObject>(); for (int i = 0; i < elements.Count; i++) { IEnumerable <Core.SAMObject> sAMObjects = ToSAM(elements[i], convertSettings); if (sAMObjects == null || sAMObjects.Count() == 0) { continue; } foreach (Core.SAMObject sAMObject in sAMObjects) { result.Add(sAMObject); } } ; if (transform != null && transform != Transform.Identity) { Parallel.For(0, result.Count, (int i) => { result[i] = Query.Transform(transform, result[i]); }); } return(result); }
public override void InitializeList() { this.m_phases = APIObjectList.ActiveDocument.Phases.OfType <Phase>(); foreach (FamilyInstance current in base.GetFamilyInstance(new BuiltInCategory[] { (BuiltInCategory)(-2000023), (BuiltInCategory)(-2000014) })) { if (current != null) { foreach (Phase current2 in this.m_phases) { ElementOnPhaseStatus phaseStatus = current.GetPhaseStatus(current2.Id); if (phaseStatus == (ElementOnPhaseStatus)4 || phaseStatus == (ElementOnPhaseStatus)2) { object obj = this.CreateListItem(current, current2); if (obj != null) { this.m_list.Add(obj); } } } } } }
internal static string GetPhaseStatus(ElementId element, ElementId phaseID) { var doc = DocumentManager.Instance.CurrentDBDocument; Autodesk.Revit.DB.Element elemId = doc.GetElement(element) as Autodesk.Revit.DB.Element; ElementOnPhaseStatus elemStat = elemId.GetPhaseStatus(phaseID); string phaseStatus = elemStat.ToString(); return(phaseStatus); }
public override void InitializeList() { this.m_phases = APIObjectList.ActiveDocument.Phases.OfType <Phase>(); System.Collections.Generic.IEnumerable <FamilyInstance> familyInstance = base.GetFamilyInstance(new BuiltInCategory[] { (BuiltInCategory)(-2001000), (BuiltInCategory)(-2001040), (BuiltInCategory)(-2001060), (BuiltInCategory)(-2000080), (BuiltInCategory)(-2001100), (BuiltInCategory)(-2000151), (BuiltInCategory)(-2001120), (BuiltInCategory)(-2001140), (BuiltInCategory)(-2001160), (BuiltInCategory)(-2001350), (BuiltInCategory)(-2008013), (BuiltInCategory)(-2008075), (BuiltInCategory)(-2008077), (BuiltInCategory)(-2008079), (BuiltInCategory)(-2008081), (BuiltInCategory)(-2008083), (BuiltInCategory)(-2008085), (BuiltInCategory)(-2008087), (BuiltInCategory)(-2008099) }); foreach (FamilyInstance current in familyInstance) { if (current != null) { foreach (Phase current2 in this.m_phases) { ElementOnPhaseStatus phaseStatus = current.GetPhaseStatus(current2.Id); if (phaseStatus == (ElementOnPhaseStatus)4 || phaseStatus == (ElementOnPhaseStatus)2) { object obj = this.CreateListItem(current, current2); if (obj != null) { if (Command.ConfigFile.Debug) { object[] array = obj as object[]; Log.WriteLine("Id: {0}, Phase: {1}, SpatialEle: {2}, DesignOption: {3}", new object[] { array[0], array[1], array[2], array[3] }); } this.m_list.Add(obj); } } } } } }
public static Room DetermineRoom(Element el) { FamilyInstance fi = el as FamilyInstance; if (fi == null) { return(null); } // As simple as that? try { if (fi.Room != null) { //Debug.WriteLine("fi.Room != null"); return(fi.Room); } } catch { } // Try phasing Room r = null; foreach (Phase p in el.Document.Phases) { try { // TODO should check fi.GetPhaseStatus // instead of provoking an exception ElementOnPhaseStatus eops = fi.GetPhaseStatus(p.Id); // now what??? r = fi.get_Room(p); if (r != null) { //Debug.WriteLine("fi.get_Room( " + p.Name + ") != null"); return(r); } } catch { } } LocationPoint lp = el.Location as LocationPoint; if (lp != null) { // Try design options //List<Element> roomlst = get_Elements( el.Document, typeof(Room)); List <Element> roomlst = new FilteredElementCollector(el.Document).OfCategory(BuiltInCategory.OST_Rooms).ToElements().ToList(); // Try rooms from primary design option foreach (Element roomel in roomlst) { Room priroom = roomel as Room; if (priroom == null) { continue; } if (priroom.DesignOption == null) { continue; } if (priroom.DesignOption.IsPrimary) { // TODO should check whether priroom // and el phasing overlaps if (priroom.IsPointInRoom(lp.Point)) { //Debug.WriteLine( "priroom.IsPointInRoom != null"); return(priroom); } } } // Emergency: try any room foreach (Element roomel in roomlst) { Room room = roomel as Room; if (room == null) { continue; } // TODO should check whether room // and el phasing overlaps if (room.IsPointInRoom(lp.Point)) { //Debug.WriteLine("room.IsPointInRoom != null"); return(room); } } } // Nothing found //System.Windows.Forms.MessageBox.Show("Nothing found" ); return(null); }
public static List <FamilyInstance> FamilyInstanceCategoryInThisRoom(Room _room, BuiltInCategory bic, Document _Doc, Phase phsBasis) { ProjectLocation projectLocation = _Doc.ActiveProjectLocation; XYZ origin = new XYZ(0, 0, 0); ProjectPosition position = projectLocation.get_ProjectPosition(origin); Double zOffset = position.Elevation; // will correct all z values with this value zOffset = 0; // leaving it this way for the time being 12/6/16 bool debugMsg = false; if (debugMsg) { TaskDialog.Show("Have position.Elevation", zOffset.ToString()); } #region Explanation // Typical code examples use the familyintance boundingbox values for passing a point to the Revit // Room IsPointInRoom function. // The problem here is that Revit's IsPointInRoom function operates on the "Room's" limits. // The room's upper limit might actually be set lower than the ceiling or where the familyinstance // might be. So instead we shall set the family instance's z value to 1 foot, taking the // chance that the room Base Offset is not higher than 1 foot. // At this point the Room IsPointInRoom function will consider all familyinstances that are vertically within // the room's footprint to be in the room. The tactic here is to guess the elevation of the next floor level // above the room and then use that to make sure only those family instances within the floor to floor range // are passed to the Room IsPointInRoom function. #endregion //TaskDialog.Show("Lookin for next level", "Lookin for next level " + _room.Name); // Together, the Upper Limit and Limit Offset parameters define the // upper boundary of the room. Often the limitoffset is negative. Double roomElev = _room.Level.Elevation + zOffset; Double roomElevTop = _room.Level.Elevation + zOffset + 7.5; // call this default room height Double aSmallDist = 0.1; // When the UpperLimit is then next floor level and the LimitOffset happens to be zero // then we need to subtract aSmallDist so that the next level algoritim finds the UpperLimit // floor level as the next level and not the next level higher. if (_room.UpperLimit != null) { roomElevTop = _room.UpperLimit.Elevation + zOffset + _room.LimitOffset - aSmallDist; } else { // go with default - for some reason there can be nulls } if (debugMsg) { string strDBMsg = "Room Level Name=" + _room.Level.Name + "\nRoom Elev=" + roomElev.ToString(); if (_room.UpperLimit != null) { strDBMsg = strDBMsg + "\n" + "Room Upper Limit Elev=" + _room.UpperLimit.Elevation.ToString(); } strDBMsg = strDBMsg + "\n" + "Room LimitOffset=" + _room.LimitOffset.ToString(); strDBMsg = strDBMsg + "\n" + "Calc Room Top Elev=" + roomElevTop.ToString(); System.Windows.MessageBox.Show(strDBMsg, "Data About The Room Object"); } Double topRangeElevation = roomElevTop; if (debugMsg) { TaskDialog.Show("Have elevations", "TopRangeElev " + roomElevTop.ToString() + "\nRoomElev " + roomElev.ToString()); } #region Guess The Next Higher Level // given an elevation, get the elevation for the next higher level elevation FilteredElementCollector collector = new FilteredElementCollector(_Doc); ICollection <Element> collection = collector.OfClass(typeof(Level)).ToElements(); Level nextHigherLevel = null; Double minDelta = 1000.0; string strDebugLMsg = ""; foreach (Element e in collection) { Level level = e as Level; if (null != level) { if (debugMsg) { strDebugLMsg = strDebugLMsg + "Level Name=" + level.Name + "\nLevel Elev=" + level.Elevation.ToString() + "\n\n"; } if (level.Elevation > roomElevTop) { double delta = level.Elevation - roomElevTop; if (delta < minDelta) { minDelta = delta; nextHigherLevel = level; } } } } if (debugMsg) { System.Windows.MessageBox.Show(strDebugLMsg, "Levels in Doc =" + Path.GetFileName(_Doc.PathName)); } #endregion if (null != nextHigherLevel) { topRangeElevation = nextHigherLevel.Elevation; if (debugMsg) { System.Windows.MessageBox.Show("Next higher Level above room's LimitOffset \nName =" + nextHigherLevel.Name.ToString() + "\nelev =" + topRangeElevation.ToString(), "Next higher Level Results"); } } //TaskDialog.Show("have next level" , "have next level " + _room.Name); List <FamilyInstance> familyInstancesLST = new List <FamilyInstance>(); try { // Create a LightingFixture/FamilyIntance collection that exist in the active document FilteredElementCollector filteredElemCol = new FilteredElementCollector(_Doc) .WhereElementIsNotElementType() .WhereElementIsViewIndependent() .OfCategory(bic) .OfClass(typeof(FamilyInstance)); // Iterate through each instance bool warnMSGNotSeenYet = true; foreach (FamilyInstance fi in filteredElemCol) { try { // Get the bounding box of the instance BoundingBoxXYZ boundingBoxXYZ = fi.get_BoundingBox(null); if (boundingBoxXYZ == null) { continue; } Double z = 0.0; z = _room.Level.Elevation + 1.0 + zOffset; LocationPoint fi_LocPt = fi.Location as LocationPoint; Double actual_Z = fi_LocPt.Point.Z + zOffset; //TaskDialog.Show("Debug", "The room Base Offset: " + _room.BaseOffset.ToString() + "\nRoomLevelBasisZ: " + _room.Level.Elevation.ToString()); if (_room.BaseOffset > 1.0) { if (warnMSGNotSeenYet) { TaskDialog.Show("Warning", "The room Base Offset is set higher than 1 foot. Some lights will not be counted."); warnMSGNotSeenYet = false; } } // Get the center point of the instance (except Z) XYZ centerPT = new XYZ((boundingBoxXYZ.Min.X + boundingBoxXYZ.Max.X) / 2, (boundingBoxXYZ.Min.Y + boundingBoxXYZ.Max.Y) / 2, (z)); // exclude fi element when it is not present for the phase basis ElementOnPhaseStatus elPhs = fi.GetPhaseStatus(phsBasis.Id); if (elPhs == ElementOnPhaseStatus.Past || elPhs == ElementOnPhaseStatus.Demolished || elPhs == ElementOnPhaseStatus.Temporary || elPhs == ElementOnPhaseStatus.Future) { continue; } // include only items having actual_Z within this floor level range // _room.Level.Elevation >= z <= topRangeElevation if (actual_Z >= (_room.Level.Elevation + zOffset) && actual_Z <= (topRangeElevation + zOffset)) { //Determine if the point exists within the bounding box/room if (_room.IsPointInRoom(centerPT) == true) { familyInstancesLST.Add(fi); } } } catch (Exception ex) { System.Windows.Forms.MessageBox.Show(ex.Message); // continue processing } } //TaskDialog.Show("done with", "done with " + _room.Name); return(familyInstancesLST); } catch { return(familyInstancesLST = new List <FamilyInstance>()); } }
private List <ConnectionNode> getRelatedDoors(List <Room> rooms, Dictionary <ElementId, Models.RoomWithTransitLines> transitRooms) { // get the doors (either by view or in general) List <ConnectionNode> doorNodes = new List <ConnectionNode>(); FilteredElementCollector coll = null; if (_view != null) { coll = new FilteredElementCollector(_doc, _view.Id); } else { coll = new FilteredElementCollector(_doc); } coll.OfCategory(BuiltInCategory.OST_Doors).WhereElementIsNotElementType(); List <FamilyInstance> doors = coll.Cast <FamilyInstance>().ToList(); // now, for the phase that's appropriate, figure out what rooms they come to/from. if (doors.Count == 0) { return(doorNodes); } ElementId phaseId = rooms[0].get_Parameter(BuiltInParameter.ROOM_PHASE).AsElementId(); Phase phase = _doc.GetElement(phaseId) as Phase; // get the list of room elements we care about List <ElementId> roomIds = rooms.Select(s => s.Id).ToList(); foreach (var pair in transitRooms) { roomIds.Add(pair.Key); } foreach (FamilyInstance door in doors) { ElementOnPhaseStatus status = door.GetPhaseStatus(phaseId); switch (status) { case ElementOnPhaseStatus.Existing: case ElementOnPhaseStatus.New: // do nothing. break; default: continue; // ignore this } Room from = door.get_FromRoom(phase); Room to = door.get_ToRoom(phase); if ( ((from != null) && roomIds.Contains(from.Id)) || ((to != null) && roomIds.Contains(to.Id)) ) { // we have a room we care about! LocationPoint lp = (door.Location as LocationPoint); XYZ location = null; if ((lp != null) && (lp.Point != null)) { location = lp.Point; } else { // fallback! BoundingBoxXYZ box = door.get_BoundingBox(null); Level lev = _doc.GetElement(door.LevelId) as Level; location = new XYZ((box.Min.X + box.Max.X) / 2.0, (box.Min.Y + box.Max.Y) / 2.0, (lev != null) ? (lev.ProjectElevation) : (box.Min.Z)); } string mark = ""; Parameter markParam = door.get_Parameter(BuiltInParameter.ALL_MODEL_MARK); if (markParam != null) { mark = markParam.AsString(); } ConnectionNode node = new ConnectionNode() { ConnectionType = ConnectionNode.ConnectionTypeEnum.Door, NodeType = Node.NodeTypeEnum.Door, RevitId = door.Id, LevelId = door.LevelId, Location = location, Name = mark }; if (from != null) { node.RoomId = from.Id; } if (to != null) { node.Room2 = to.Id; } if ((from == null) && (to != null)) { node.RoomId = to.Id; } Parameter egress = door.GetParameters(EgressParameter).FirstOrDefault(); if ((egress != null) && (egress.AsInteger() == 1)) { node.IsEgress = true; } doorNodes.Add(node); } } return(doorNodes); }