public static List <Spatial.Face3D> BottomProfiles(this HostObject hostObject) { List <Spatial.Face3D> result = new List <Spatial.Face3D>(); foreach (Reference reference in HostObjectUtils.GetBottomFaces(hostObject)) { GeometryObject geometryObject = hostObject.GetGeometryObjectFromReference(reference); if (geometryObject == null) { continue; } Autodesk.Revit.DB.Face face = geometryObject as Autodesk.Revit.DB.Face; if (face == null) { continue; } List <Spatial.Face3D> face3Ds = face.ToSAM(); if (face3Ds == null || face3Ds.Count == 0) { continue; } result.AddRange(face3Ds); } return(result); }
/// <summary> /// This node will return the bottom face or faces for the input host object. This particular method works for ceilings, roofs, or floors. /// </summary> /// <param name="hostObject">The host object to retrieve bottom faces for.</param> /// <returns></returns> public static IEnumerable <List <Surface> > BottomSurface(global::Revit.Elements.Element hostObject) { Autodesk.Revit.DB.HostObject internalHost = hostObject.InternalElement as Autodesk.Revit.DB.HostObject; IList <Reference> sideRefs = HostObjectUtils.GetBottomFaces(internalHost); List <Autodesk.Revit.DB.Face> exteriorGeometryObjects = new List <Autodesk.Revit.DB.Face>(sideRefs.Select(r => internalHost.GetGeometryObjectFromReference(r)).Cast <Autodesk.Revit.DB.Face>()); return(exteriorGeometryObjects.Select(g => g.ToProtoType(true).ToList())); }
static internal IList <EdgeInfo> GetRoofEdgeInfoList(FootPrintRoof currentRoof, bool topFaces = true) { //TODO see if theres any segmented curves (segmented sketch lines) on the footprint of the roof //If yes, ask the user to correct then OR exit the command OR merge the sketchlines IList <EdgeInfo> resultingEdgeInfoList = new List <EdgeInfo>(); IList <EdgeInfo> tempEdgeInfoList = new List <EdgeInfo>(); IList <Reference> currentListOfReferences = new List <Reference>(); if (topFaces) { currentListOfReferences = HostObjectUtils.GetTopFaces(currentRoof); } else { currentListOfReferences = HostObjectUtils.GetBottomFaces(currentRoof); } IList <PlanarFace> currentListOfFaces = new List <PlanarFace>(); IsListOfPlanarFaces(currentListOfReferences, currentRoof, out currentListOfFaces); IList <Curve> nonDuplicatedEdgeList = GetNonDuplicatedCurvesFromListOfFaces(currentListOfFaces); foreach (Curve currentCurve in nonDuplicatedEdgeList) { tempEdgeInfoList.Add(GetCurveInformation(currentRoof, currentCurve, currentListOfFaces)); } foreach (EdgeInfo currentEdgeInfo in tempEdgeInfoList) { EdgeInfo newEdgeInfo = currentEdgeInfo; newEdgeInfo.RelatedRidgeEaves = GetRidgeInfoList(newEdgeInfo.Edges[0], tempEdgeInfoList); resultingEdgeInfoList.Add(newEdgeInfo); } resultingEdgeInfoList = MergeEdgeCurves(resultingEdgeInfoList); //foreach (EdgeInfo currentEdgeInfo in resultingEdgeInfoList) //{ // if (currentEdgeInfo.Edges.Count > 1) // System.Diagnostics.Debug.WriteLine("Merged Edge"); // Document doc = currentEdgeInfo.CurrentRoof.Document; // PlanarFace pfce = currentEdgeInfo.GetRelatedPanels()[0] as PlanarFace; // Plane pl = new Plane(pfce.FaceNormal, pfce.Origin); // SketchPlane skp = SketchPlane.Create(doc, pl); // doc.Create.NewModelCurve(currentEdgeInfo.Curve, skp); //} return(resultingEdgeInfoList); }
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) { UIDocument uidoc = commandData.Application.ActiveUIDocument; Document doc = uidoc.Document; if ((uidoc.ActiveView as View3D) == null) { message = "Por favor, rode este comando em uma vista 3d"; return(Result.Failed); } ISelectionFilter ridgeSelectionFilter = new RoofClasses.SelectionFilters.StraightLinesAndFacesRidgeSelectionFilter(doc); Reference currentReference = uidoc.Selection.PickObject(ObjectType.Edge, ridgeSelectionFilter); FootPrintRoof currentFootPrintRoof = doc.GetElement(currentReference) as FootPrintRoof; Edge edge = Support.GetEdgeFromReference(currentReference, currentFootPrintRoof); IList <PlanarFace> pfaces = new List <PlanarFace>(); Support.IsListOfPlanarFaces(HostObjectUtils.GetBottomFaces(currentFootPrintRoof) , currentFootPrintRoof, out pfaces); IList <RoofClasses.EdgeInfo> currentEdgeInfoList = Support.GetRoofEdgeInfoList(currentFootPrintRoof, false); Curve currentCurve = Support.GetMostSimilarCurve(edge.AsCurve(), currentEdgeInfoList); RoofClasses.EdgeInfo currentInfo = Support.GetCurveInformation(currentFootPrintRoof, currentCurve, pfaces); TaskDialog.Show("fac", currentInfo.RoofLineType.ToString()); Element tTypeElement = new FilteredElementCollector(doc).OfClass(typeof(FamilySymbol)).Where(fsy => fsy is TrussType).ToList().FirstOrDefault(); if (tTypeElement == null) { message = "Nenhum tipo de treliça foi encontrada no projeto, por favor, carregue um tipo e rode este comando novamente"; return(Result.Failed); } TrussType tType = tTypeElement as TrussType; Managers.TrussRidgeManager currentTrussManager = new Managers.TrussRidgeManager(); IList <RoofClasses.TrussInfo> currentTrussInfoList = currentTrussManager.CreateTrussesFromRidgeInfo(currentInfo, tType); TaskDialog tDialog = new TaskDialog("Trusses"); tDialog.MainInstruction = currentTrussInfoList.Count.ToString(); tDialog.Show(); return(Result.Succeeded); }
/***************************************************/ public static List <Plane> PanelPlanes(this Ceiling ceiling) { List <Plane> result = new List <Plane>(); foreach (Reference reference in HostObjectUtils.GetBottomFaces(ceiling)) { PlanarFace pf = ceiling.GetGeometryObjectFromReference(reference) as PlanarFace; if (pf != null) { result.Add(Plane.CreateByNormalAndOrigin(pf.FaceNormal, pf.Origin)); } } return(result); }
/***************************************************/ public static List <Face> LinkPanelFaces(this Ceiling ceiling, RevitSettings settings) { List <Face> result = new List <Face>(); foreach (Reference reference in HostObjectUtils.GetBottomFaces(ceiling)) { PlanarFace pf = ceiling.GetGeometryObjectFromReference(reference) as PlanarFace; if (pf != null) { result.Add(pf); } } return(result); }
static internal EdgeInfo GetMostSimilarEdgeInfo(Reference currentReference, Document targetDoc) { FootPrintRoof currentFootPrintRoof = targetDoc.GetElement(currentReference) as FootPrintRoof; Edge edge = Support.GetEdgeFromReference(currentReference, currentFootPrintRoof); IList <PlanarFace> pfaces = new List <PlanarFace>(); Support.IsListOfPlanarFaces(HostObjectUtils.GetBottomFaces(currentFootPrintRoof) , currentFootPrintRoof, out pfaces); IList <RoofClasses.EdgeInfo> currentEdgeInfoList = GetRoofEdgeInfoList(currentFootPrintRoof, false); Curve currentCurve = GetMostSimilarCurve(edge.AsCurve(), currentEdgeInfoList); RoofClasses.EdgeInfo currentRidgeInfo = GetCurveInformation(currentFootPrintRoof, currentCurve, pfaces); return(currentRidgeInfo); }
protected override void SolveInstance(IGH_DataAccess DA) { Autodesk.Revit.DB.HostObject host = null; if (!DA.GetData("Host", ref host) || host is null) { return; } var doc = Revit.ActiveDBDocument; try { var bottom = HostObjectUtils.GetBottomFaces(host).Select(reference => new Types.Face(reference, doc)); DA.SetDataList("Bottom", bottom); } catch (Autodesk.Revit.Exceptions.ArgumentException) { } try { var top = HostObjectUtils.GetTopFaces(host).Select(reference => new Types.Face(reference, doc)); DA.SetDataList("Top", top); } catch (Autodesk.Revit.Exceptions.ArgumentException) { } try { var interior = HostObjectUtils.GetSideFaces(host, ShellLayerType.Interior).Select(reference => new Types.Face(reference, doc)); DA.SetDataList("Interior", interior); } catch (Autodesk.Revit.Exceptions.ArgumentException) { } try { var exterior = HostObjectUtils.GetSideFaces(host, ShellLayerType.Exterior).Select(reference => new Types.Face(reference, doc)); DA.SetDataList("Exterior", exterior); } catch (Autodesk.Revit.Exceptions.ArgumentException) { } }
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) { UIDocument uidoc = commandData.Application.ActiveUIDocument; Document doc = uidoc.Document; if ((uidoc.ActiveView as View3D) == null) { message = "Por favor, rode este comando em uma vista 3d"; return(Result.Failed); } Reference currentReference = uidoc.Selection.PickObject(ObjectType.Edge); FootPrintRoof currentFootPrintRoof = doc.GetElement(currentReference.ElementId) as FootPrintRoof; Edge edge = currentFootPrintRoof.GetGeometryObjectFromReference(currentReference) as Edge; IList <PlanarFace> pfaces = new List <PlanarFace>(); Support.IsListOfPlanarFaces(HostObjectUtils.GetBottomFaces(currentFootPrintRoof).Union(HostObjectUtils.GetTopFaces(currentFootPrintRoof)).ToList() , currentFootPrintRoof, out pfaces); RoofClasses.EdgeInfo currentInfo = Support.GetCurveInformation(currentFootPrintRoof, edge.AsCurve(), pfaces); using (Transaction t = new Transaction(doc, "Test")) { t.Start(); FamilySymbol fs = new FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_GenericModel).WhereElementIsElementType().Where(type => type.Name.Contains("DebugPoint")).FirstOrDefault() as FamilySymbol; fs.Activate(); doc.Create.NewFamilyInstance((currentInfo.Curve as Line).Direction, fs, Autodesk.Revit.DB.Structure.StructuralType.NonStructural); doc.Create.NewFamilyInstance(((currentInfo.Curve as Line).Direction).Rotate(-90), fs, Autodesk.Revit.DB.Structure.StructuralType.NonStructural); doc.Create.NewFamilyInstance(((currentInfo.Curve as Line).Direction).Rotate(45), fs, Autodesk.Revit.DB.Structure.StructuralType.NonStructural); t.Commit(); } return(Result.Succeeded); }
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) { UIApplication uiapp = commandData.Application; UIDocument uidoc = uiapp.ActiveUIDocument; Document doc = uidoc.Document; Selection sel = uidoc.Selection; var acview = doc.ActiveView; var IsAlignTopFAce = false; //根据设置确定 var IsAlignBottomFAce = true; //根据设置确定 var selectedIds = sel.GetElementIds(); var selectionCollector = new FilteredElementCollector(doc, selectedIds);//选择集集合 var beamFilter = new ElementCategoryFilter(BuiltInCategory.OST_StructuralFraming); var roofFilter = new ElementCategoryFilter(BuiltInCategory.OST_Roofs); var floorFilter = new ElementCategoryFilter(BuiltInCategory.OST_Floors); var rampFilter = new ElementCategoryFilter(BuiltInCategory.OST_Ramps); var structuralFoundationFilter = new ElementCategoryFilter(BuiltInCategory.OST_StructuralFoundation); var roofcollector = new FilteredElementCollector(doc, selectedIds).WhereElementIsNotElementType().WherePasses(roofFilter); var floorCollector = new FilteredElementCollector(doc, selectedIds).WhereElementIsNotElementType().WherePasses(floorFilter); var rampCollector = new FilteredElementCollector(doc, selectedIds).WhereElementIsNotElementType().WherePasses(rampFilter); var strFoundationCollector = new FilteredElementCollector(doc, selectedIds).WhereElementIsNotElementType().WherePasses(structuralFoundationFilter); var beamCollector = new FilteredElementCollector(doc, selectedIds).WhereElementIsNotElementType().WherePasses(beamFilter); //(1.梁随屋面)将与屋面在同一层的梁进行处理 使之紧贴屋面 // -1. 获取屋面顶面或底面边界线 var floorfaces = default(IList <Reference>); foreach (Floor floor in floorCollector) { if (IsAlignBottomFAce) { floorfaces = HostObjectUtils.GetBottomFaces(floor); } else if (IsAlignTopFAce) { floorfaces = HostObjectUtils.GetTopFaces(floor); } //排除空引用 floorfaces = floorfaces.Where(m => floor.GetGeometryObjectFromReference(m) as Face != null).ToList(); //for test #region test weather face is null //foreach (var reference in floorfaces) //{ // //var type = roof.GetGeometryObjectFromReference(reference).GetType().ToString(); // //MessageBox.Show(type); // var face = floor.GetGeometryObjectFromReference(reference) as Face; // if (face != null) // { // var edgeloops = face.GetEdgesAsCurveLoops(); // foreach (var edgeloop in edgeloops) // { // foreach (Curve c in edgeloop) // { // doc.NewLine(c as Line); // } // } // } // else // { // //var face1 = roof.GetGeometryObjectFromReference(reference); // //MessageBox.Show("null"); // } //} #endregion if (floorfaces.Count == 0 || floorfaces == null) { continue; } //用屋面边线切断所有 投影相交的梁 foreach (FamilyInstance beam in beamCollector) { } } return(Result.Succeeded); }
static internal IList <Face> GetEdgeRelatedPanels(Edge targetEdge, FootPrintRoof targetRoof) { IList <Face> resultingListOfFaces = new List <Face>(); Face targetFace0 = targetEdge.GetFace(0); Face targetFace1 = targetEdge.GetFace(1); IList <Reference> currentListOfReferences = HostObjectUtils.GetTopFaces(targetRoof).Union(HostObjectUtils.GetBottomFaces(targetRoof)).ToList(); IList <PlanarFace> targetRoofPlanarFaces = new List <PlanarFace>(); IsListOfPlanarFaces(currentListOfReferences, targetRoof, out targetRoofPlanarFaces); if (targetRoofPlanarFaces.Contains(targetFace0)) { resultingListOfFaces.Add(targetFace0); } if (targetRoofPlanarFaces.Contains(targetFace1)) { resultingListOfFaces.Add(targetFace1); } return(resultingListOfFaces); }
private static List <Polygon> GetProfile(this Autodesk.Revit.DB.Element element) { Document doc = element.Document; List <Polygon> polygons = new List <Polygon>(); IList <Reference> firstSideFaces = null; IList <Reference> secondSideFaces = null; switch (element) { case Wall revitWall: //use host object utils to get the outside face firstSideFaces = HostObjectUtils.GetSideFaces(revitWall, ShellLayerType.Exterior); secondSideFaces = HostObjectUtils.GetSideFaces(revitWall, ShellLayerType.Interior); break; case Autodesk.Revit.DB.Floor revitFloor: firstSideFaces = HostObjectUtils.GetTopFaces(revitFloor); secondSideFaces = HostObjectUtils.GetBottomFaces(revitFloor); break; } Element faceElement = doc.GetElement(firstSideFaces[0]); if (!(faceElement.GetGeometryObjectFromReference(firstSideFaces[0]) is Face exteriorFace) || !(faceElement.GetGeometryObjectFromReference(secondSideFaces[0]) is Face interiorFace)) { return(null); } //this lets us pick the biggest face of the two sides. This is important because we want the shapes to close. 😁 Face face = exteriorFace.Area > interiorFace.Area ? exteriorFace : interiorFace; // get the edges as curve loops and use the IFCUtils to sort them // credit: https://thebuildingcoder.typepad.com/blog/2015/01/getting-the-wall-elevation-profile.html IList <CurveLoop> curveLoops = face.GetEdgesAsCurveLoops(); //this does the sorting so outside is the first item IList <CurveLoop> loops = ExporterIFCUtils.SortCurveLoops(curveLoops)[0]; for (int i = 0; i < loops.Count; i++) { //here for outermost loop if (i == 0) { var outer = loops[i]; List <Vector3> vertices = new List <Vector3>(); foreach (Autodesk.Revit.DB.Curve c in outer) { vertices.Add(c.GetEndPoint(0).ToVector3()); } polygons.Add(new Polygon(vertices)); } //here for the inner loops (voids) else { var inner = loops[i]; List <Vector3> vertices = new List <Vector3>(); foreach (Autodesk.Revit.DB.Curve c in inner) { vertices.Add(c.GetEndPoint(0).ToVector3()); } Polygon innerPolygon = new Polygon(vertices); polygons.Add(innerPolygon); } } return(polygons); }
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) { var uidoc = commandData.Application.ActiveUIDocument; var doc = uidoc.Document; var sel = uidoc.Selection; //选择管线 var mep = sel.PickObject(ObjectType.Element, doc.GetSelectionFilter(m => m is MEPCurve && !(m is InsulationLiningBase)), "选择管线").GetElement(doc) as MEPCurve; //选择楼板 var floor = sel.PickObject(ObjectType.Element, doc.GetSelectionFilter(m => m is Floor), "选择楼板").GetElement(doc) as Floor; var bottomfaceref = HostObjectUtils.GetBottomFaces(floor).First(); var bottomface = floor.GetGeometryObjectFromReference(bottomfaceref) as Face; var planarFace = (bottomface as PlanarFace); var planeNorm = planarFace.FaceNormal; var planeOrigin = planarFace.Origin; var plane = Plane.CreateByNormalAndOrigin(planeNorm, planeOrigin); Transform trs = Transform.Identity; trs.Origin = planeOrigin; trs.BasisX = planarFace.XVector; trs.BasisY = planarFace.YVector; trs.BasisZ = planeNorm; var inputboxStr = Microsoft.VisualBasic.Interaction.InputBox("输入距离楼板距离", "距离", "0"); var distance = default(double); var parseresult = double.TryParse(inputboxStr, out distance); if (!parseresult) { return(Result.Cancelled); } distance = distance.MetricToFeet(); var locationline = mep.LocationLine(); var startpo = locationline.StartPoint(); var endpo = locationline.EndPoint(); var startpo_intrans = trs.Inverse.OfPoint(startpo); var endpo_intrans = trs.Inverse.OfPoint(endpo); var startpo_proj = new XYZ(startpo_intrans.X, startpo_intrans.Y, 0); var endpo_proj = new XYZ(endpo_intrans.X, endpo_intrans.Y, 0);; startpo_proj = trs.OfPoint(startpo_proj); endpo_proj = trs.OfPoint(endpo_proj); var dir = (endpo - endpo_proj).Normalize(); var newstart = startpo_proj + dir * distance; var newend = endpo_proj + dir * distance; Transaction ts = new Transaction(doc, "更改管线到楼板距离"); ts.Start(); (mep.Location as LocationCurve).Curve = Line.CreateBound(newstart, newend); ts.Commit(); return(Result.Succeeded); }