public PlanarFace GetFace(Element element) { Options opt = new Options(); // Get geometry element of the selected element GeometryElement geoElement = element.get_Geometry(opt); PlanarFace pf = null; // Get geometry object foreach (GeometryObject geoObject in geoElement) { // Get the geometry instance which contains the geometry information Autodesk.Revit.DB.GeometryInstance instance = geoObject as Autodesk.Revit.DB.GeometryInstance; if (null != instance) { GeometryElement instanceGeometryElement = instance.GetInstanceGeometry(); foreach (GeometryObject instObj in instanceGeometryElement) { Solid solid = instObj as Solid; if (null == solid || 0 == solid.Faces.Size || 0 == solid.Edges.Size) { continue; } // Get the faces and edges from solid, and transform the formed points foreach (Face face in solid.Faces) { //face.ComputeNormal(new UV(0.5, 0.5)); pf = face as PlanarFace; } } } } return(pf); }
private static IEnumerable <Autodesk.Revit.DB.Face> GetFaces(Autodesk.Revit.DB.GeometryInstance geomInst) { return(geomInst.GetInstanceGeometry() .OfType <Autodesk.Revit.DB.Solid>() .SelectMany(x => x.Faces.Cast <Autodesk.Revit.DB.Face>())); }
private String GetRooms() { String tString = ""; spaces = new FilteredElementCollector(doc) .OfClass(typeof(SpatialElement)).WhereElementIsNotElementType() .Where(X => X.Category.Name == "Spaces" || X.Category.Name == "Rooms").ToList <Element>(); int interfaceCounter = 1; int virtualElementCounter = 1; foreach (Element e in spaces) { //string URI = Parameters.GenerateURIifNotExist(doc, e).Replace(Namespace, "inst:"); string URI = Util.CreateURI(e, Namespace).Replace(Namespace, "inst:"); ElementDict.Add(e.Id, URI); //URItranslater.Add(URI,"inst:") if (e.Category.Name == "Spaces") { Space space = e as Space; String properties = GetProperties(space); String typeProperties = GetTypeProperties(space); tString += NL + NL + $"{URI}" + NLT + "a bot:Space "; tString += ";" + NLT + $"props:revitId \"{space.Id}\" ;" + NLT + $"props:ifcGuid \"{space.GetGUID()}\" ;" + NLT + $"props:uuid \"{space.GetUUID()}\" ;" + NLT + $"props:number \"{space.Number}\"^^xsd:string " + properties + typeProperties + ";"; tString += NLT + $"bot:hasSimple3DModel \"\"\"{Util.GetFacesAndEdges(space, true)}\"\"\" ." + NL; IList <IList <Autodesk.Revit.DB.BoundarySegment> > segments = space.GetBoundarySegments(new SpatialElementBoundaryOptions()); if (null != segments) //the room may not be bound { foreach (IList <Autodesk.Revit.DB.BoundarySegment> segmentList in segments) { foreach (Autodesk.Revit.DB.BoundarySegment boundarySegment in segmentList) { Element boundingEl = doc.GetElement(boundarySegment.ElementId); if (boundingEl == null) { Console.Out.WriteLine("Found null buildingEl: " + boundarySegment.ToString()); continue; } //-2000066 //String eln = boundingEl.Name; if (boundingEl.Category.Name == "<Room Separation>") // == BuiltInCategory.OST_RoomSeparationLines { String virtualElement = "inst:VirtualElement_" + virtualElementCounter; if (virtualelements.ContainsKey(boundingEl.Id)) { virtualElement = virtualelements[boundingEl.Id]; } else { tString += NL + "inst:VirtualElement_" + virtualElementCounter + NLT + "a bot:VirtualElement ." + NL; virtualelements.Add(boundingEl.Id, "inst:VirtualElement_" + virtualElementCounter); } tString += NL + "inst:Interface_" + interfaceCounter + NLT + "a bot:Interface ;" + NLT + "bot:interfaceOf " + URI + ", " + virtualElement + " ;" + NLT + "fog:asSfa_v2-wkt \"LINESTRING (" + (boundarySegment.GetCurve().GetEndPoint(0).X * 12 * 25.4).ToString().Replace(',', '.') + " " + (boundarySegment.GetCurve().GetEndPoint(0).Y * 12 * 25.4).ToString().Replace(',', '.') + ", " + (boundarySegment.GetCurve().GetEndPoint(1).X * 12 * 25.4).ToString().Replace(',', '.') + " " + (boundarySegment.GetCurve().GetEndPoint(1).Y * 12 * 25.4).ToString().Replace(',', '.') + ")\" ." + NL; interfaceCounter++; virtualElementCounter++; } else { string boundingElURI = Util.CreateURI(boundingEl, Namespace).Replace(Namespace, "inst:"); tString += NL + "inst:Interface_" + interfaceCounter + NLT + "a bot:Interface ;" + NLT + "bot:interfaceOf " + URI + ", " + boundingElURI + " ;" + NLT + "fog:asSfa_v2-wkt \"LINESTRING (" + (boundarySegment.GetCurve().GetEndPoint(0).X * 12 * 25.4).ToString().Replace(',', '.') + " " + (boundarySegment.GetCurve().GetEndPoint(0).Y * 12 * 25.4).ToString().Replace(',', '.') + ", " + (boundarySegment.GetCurve().GetEndPoint(1).X * 12 * 25.4).ToString().Replace(',', '.') + " " + (boundarySegment.GetCurve().GetEndPoint(1).Y * 12 * 25.4).ToString().Replace(',', '.') + ")\" ." + NL; interfaceCounter++; } } } } } if (e.Category.Name == "Rooms") { Room room = e as Room; String properties = GetProperties(room); String typeProperties = GetTypeProperties(room); tString += NL + NL + $"{URI}" + NLT + "a bot:Space "; tString += ";" + NLT + $"props:revitId \"{room.Id}\" ;" + NLT + $"props:ifcGuid \"{room.GetGUID()}\" ;" + NLT + $"props:uuid \"{room.GetUUID()}\" ;" + NLT + $"props:number \"{room.Number}\"^^xsd:string " + properties + typeProperties + ";"; tString += NLT + $"bot:hasSimple3DModel \"\"\"{Util.GetFacesAndEdges(room,true)}\"\"\" ." + NL; IList <IList <Autodesk.Revit.DB.BoundarySegment> > segments = room.GetBoundarySegments(new SpatialElementBoundaryOptions()); if (null != segments) //the room may not be bound { foreach (IList <Autodesk.Revit.DB.BoundarySegment> segmentList in segments) { foreach (Autodesk.Revit.DB.BoundarySegment boundarySegment in segmentList) { Element boundingEl = doc.GetElement(boundarySegment.ElementId); if (boundingEl == null) { continue; } //String eln = boundingEl.Name; if (boundingEl.Category.Name == "Walls" && boundingEl.Category.Id == new ElementId(BuiltInCategory.OST_Walls) && !(boundingEl is FamilyInstance)) { Wall x = (Wall)boundingEl; IList <ElementId> inserts = x.FindInserts(true, false, false, false); foreach (ElementId id in inserts) { Element eli = doc.GetElement(id); if (eli.Category.Name == "Doors") { FamilyInstance d = (FamilyInstance)eli; GeometryElement ge = d.get_Geometry(new Options()); // Get geometry object foreach (GeometryObject geoObject in ge) { // Get the geometry instance which contains the geometry information Autodesk.Revit.DB.GeometryInstance instance = geoObject as Autodesk.Revit.DB.GeometryInstance; if (null != instance) { GeometryElement instanceGeometryElement = instance.GetInstanceGeometry(); foreach (GeometryObject o in instanceGeometryElement) { // Try to find curves Curve curve = o as Curve; if (curve != null) { string eliURI = Util.CreateURI(eli, Namespace).Replace(Namespace, "inst:"); // The curve is already transformed into the project coordinate system tString += NL + "inst:Interface_" + interfaceCounter + NLT + "a bot:Interface ;" + NLT + "bot:interfaceOf " + URI + ", " + eliURI + " ;" + NLT + "fog:asSfa_v2-wkt \"LINESTRING (" + (curve.GetEndPoint(0).X * 12 * 25.4).ToString().Replace(',', '.') + " " + (curve.GetEndPoint(0).Y * 12 * 25.4).ToString().Replace(',', '.') + ", " + (curve.GetEndPoint(1).X * 12 * 25.4).ToString().Replace(',', '.') + " " + (curve.GetEndPoint(1).Y * 12 * 25.4).ToString().Replace(',', '.') + ")\" ." + NL; interfaceCounter++; break; } } } } } } } else if (boundingEl.Category.Name == "<Room Separation>") // == BuiltInCategory.OST_RoomSeparationLines { String virtualElement = "inst:VirtualElement_" + virtualElementCounter; if (virtualelements.ContainsKey(boundingEl.Id)) { virtualElement = virtualelements[boundingEl.Id]; } else { tString += NL + "inst:VirtualElement_" + virtualElementCounter + NLT + "props:revitId " + boundingEl.Id + " ;" + NLT + "a bot:VirtualElement ." + NL; virtualelements.Add(boundingEl.Id, "inst:VirtualElement_" + virtualElementCounter); } tString += NL + "inst:Interface_" + interfaceCounter + NLT + "a bot:Interface ;" + NLT + "bot:interfaceOf " + URI + ", " + virtualElement + " ;" + NLT + "fog:asSfa_v2-wkt \"LINESTRING (" + (boundarySegment.GetCurve().GetEndPoint(0).X * 12 * 25.4).ToString().Replace(',', '.') + " " + (boundarySegment.GetCurve().GetEndPoint(0).Y * 12 * 25.4).ToString().Replace(',', '.') + ", " + (boundarySegment.GetCurve().GetEndPoint(1).X * 12 * 25.4).ToString().Replace(',', '.') + " " + (boundarySegment.GetCurve().GetEndPoint(1).Y * 12 * 25.4).ToString().Replace(',', '.') + ")\" ." + NL; interfaceCounter++; virtualElementCounter++; } else { string boundingElURI = Util.CreateURI(boundingEl, Namespace).Replace(Namespace, "inst:"); tString += NL + "inst:Interface_" + interfaceCounter + NLT + "a bot:Interface ;" + NLT + "bot:interfaceOf " + URI + ", " + boundingElURI + " ;" + NLT + "fog:asSfa_v2-wkt \"LINESTRING (" + (boundarySegment.GetCurve().GetEndPoint(0).X * 12 * 25.4).ToString().Replace(',', '.') + " " + (boundarySegment.GetCurve().GetEndPoint(0).Y * 12 * 25.4).ToString().Replace(',', '.') + ", " + (boundarySegment.GetCurve().GetEndPoint(1).X * 12 * 25.4).ToString().Replace(',', '.') + " " + (boundarySegment.GetCurve().GetEndPoint(1).Y * 12 * 25.4).ToString().Replace(',', '.') + ")\" ." + NL; interfaceCounter++; } } } } } } return(tString); }