private void calculateOppositeRooms(RoomObject ro, IList <RoomObject> allRooms, Level refLevel, Phase targetPhase) { foreach (var seg in ro.Boundaries) { Transform t = seg.Curve.ComputeDerivatives(0.5, true); XYZ alongDir = t.BasisX.Normalize(); XYZ normalDir = XYZ.BasisZ.CrossProduct(alongDir).Normalize(); seg.OutsideRoomVector = normalDir; // what room is outside? XYZ testPoint1 = t.Origin.Add(normalDir.Multiply(_outsideRoomTestDist)); XYZ testPoint2 = t.Origin.Add(normalDir.Negate().Multiply(_outsideRoomTestDist)); XYZ origin = t.Origin; if (ro.LevelId != refLevel.Id) { origin = new XYZ(t.Origin.X, t.Origin.Y, t.Origin.Z); } testPoint1 = new XYZ(testPoint1.X, testPoint1.Y, refLevel.ProjectElevation + 1.0); // one foot off the floor, just for safety... testPoint2 = new XYZ(testPoint2.X, testPoint2.Y, refLevel.ProjectElevation + 1.0); List <Document> all = new List <Document>(RoomDocs); all.Remove(ro.Document); all.Insert(0, ro.Document); // find the opposite room... Autodesk.Revit.DB.Architecture.Room opposite = null; foreach (Document testDoc in all) { var revitRoom1 = testDoc.GetRoomAtPoint(testPoint1, targetPhase); var revitRoom2 = testDoc.GetRoomAtPoint(testPoint2, targetPhase); if ((revitRoom1 != null) && (revitRoom2 != null)) { if ((revitRoom1.Id != ro.Id)) { opposite = revitRoom1; } if ((revitRoom2.Id != ro.Id)) { opposite = revitRoom2; seg.OutsideRoomVector = normalDir.Negate(); testPoint1 = testPoint2; // reset } } else { if (revitRoom1 != null) { seg.OutsideRoomVector = normalDir.Negate(); testPoint1 = testPoint2; } if (revitRoom2 != null) { // do nothing. } } if (opposite != null) { break; } } // Turn on for debugging line sides from rooms. //GeometryHelper.DrawLine(origin, testPoint1); if (opposite != null) { // see if we can find it in the room list. var match = allRooms.FirstOrDefault(r => r.Id == opposite.Id); if (match == null) { log("NOTE: Found a matching room for a segment in " + ro.Number + " that points to Room Num: " + opposite.Number + "(" + opposite.Id + ") but we don't have that in our list!?!"); } else { seg.OppositeRoom = match; } } } }
private void adjustByRules(RoomObject ro) { // remove any column type boundaries var columns = ro.Boundaries.Where(b => b.ElementType == "Columns").ToList(); foreach (var col in columns) { ro.Boundaries.Remove(col); } bool isCorridor = (ro.Name.ToUpper().Contains("CORR")); if (isCorridor) { ignoreRoom(ro); return; } // go through the boundaries and offset. foreach (var seg in ro.Boundaries) { if (isCorridor) { // we skip it unless it doesn't have an opposite if (seg.OppositeRoom != null) { continue; } } OffsetDir offset = OffsetDir.None; // determine whether to offset inwards, outwards, or leave if (seg.IsExterior) { if (seg.WallKind != WallKind.Curtain) { offset = OffsetDir.Inward; } } else { // compare against an opposite room if (seg.OppositeRoom != null) { if (seg.OppositeRoom.Score > ro.Score) { offset = OffsetDir.Inward; } if (seg.OppositeRoom.Score < ro.Score) { offset = OffsetDir.Outward; } } } // offset the segment: if (offset != OffsetDir.None) { offsetSegment(seg, offset); } } }