public static List <Segment3D> ToSAM_Segment3Ds(this Curve curve) { if (curve == null) { return(null); } if (curve is Line) { return new List <Segment3D>() { ToSAM((Line)curve) } } ; ISegmentable3D segmentable3D = ToSAM(curve) as ISegmentable3D; if (segmentable3D == null) { return(null); } List <Segment3D> result = segmentable3D.GetSegments(); if (!curve.IsBound && result.Count > 1 && result[0][0] != result[result.Count - 1][1]) { result.Add(new Segment3D(result[result.Count - 1][1], result[0][0])); } return(result); //List<Point3D> point3Ds = curve.Tessellate()?.ToList().ConvertAll(x => x.ToSAM()); //if (point3Ds == null || point3Ds.Count() == 0) // return new List<Segment3D>() { ToSAM_Segment3D(curve) }; //for (int i = 0; i < point3Ds.Count - 1; i++) // result.Add(new Segment3D(point3Ds[i], point3Ds[i + 1])); //if (!curve.IsBound && point3Ds.Count > 2) // result.Add(new Segment3D(point3Ds.Last(), point3Ds.First())); } }
private static List <Face3D> Profiles_CurtainSystem(this CurtainSystem curtainSystem) { Document document = curtainSystem?.Document; if (document == null) { return(null); } CurtainGridSet curtainGridSet = curtainSystem?.CurtainGrids; if (curtainGridSet == null) { return(null); } List <Face3D> result = new List <Face3D>(); foreach (CurtainGrid curtainGrid in curtainGridSet) { IEnumerable <CurtainCell> curtainCells = curtainGrid.GetCurtainCells(); if (curtainCells == null || curtainCells.Count() == 0) { continue; } List <CurveArrArray> curveArrArrays = new List <CurveArrArray>(); foreach (CurtainCell curtainCell in curtainCells) { CurveArrArray curveArrArray = curtainCell?.PlanarizedCurveLoops; if (curveArrArray == null || curveArrArray.Size == 0) { continue; } curveArrArrays.Add(curveArrArray); } List <Segment3D> segment3Ds = new List <Segment3D>(); List <ISegmentable3D> segmentable3Ds_U = new List <ISegmentable3D>(); List <ISegmentable3D> segmentable3Ds_V = new List <ISegmentable3D>(); ICollection <ElementId> elementIds = null; elementIds = curtainGrid.GetUGridLineIds(); if (elementIds != null) { foreach (ElementId elementId in elementIds) { CurtainGridLine curtainGridLine = document.GetElement(elementId) as CurtainGridLine; if (curtainGridLine == null) { continue; } ISegmentable3D segmentable3D = curtainGridLine.FullCurve.ToSAM() as ISegmentable3D; if (segmentable3D == null) { continue; } segmentable3Ds_U.Add(segmentable3D); segment3Ds.AddRange(segmentable3D.GetSegments()); } } elementIds = curtainGrid.GetVGridLineIds(); if (elementIds != null) { foreach (ElementId elementId in elementIds) { CurtainGridLine curtainGridLine = document.GetElement(elementId) as CurtainGridLine; if (curtainGridLine == null) { continue; } ISegmentable3D segmentable3D = curtainGridLine.FullCurve.ToSAM() as ISegmentable3D; if (segmentable3D == null) { continue; } segmentable3Ds_V.Add(segmentable3D); segment3Ds.AddRange(segmentable3D.GetSegments()); } } List <ISegmentable3D> segmentable3Ds = null; segmentable3Ds = ExtremeSegmentable3Ds(segmentable3Ds_U, segmentable3Ds_V); if (segmentable3Ds != null && segmentable3Ds.Count > 0) { foreach (ISegmentable3D segmentable3D in segmentable3Ds) { List <Segment3D> segment3Ds_Temp = segmentable3D?.GetSegments(); if (segment3Ds_Temp != null && segment3Ds_Temp.Count != 0) { segment3Ds.AddRange(segment3Ds_Temp); } } } segmentable3Ds = ExtremeSegmentable3Ds(segmentable3Ds_V, segmentable3Ds_U); if (segmentable3Ds != null && segmentable3Ds.Count > 0) { foreach (ISegmentable3D segmentable3D in segmentable3Ds) { List <Segment3D> segment3Ds_Temp = segmentable3D?.GetSegments(); if (segment3Ds_Temp != null && segment3Ds_Temp.Count != 0) { segment3Ds.AddRange(segment3Ds_Temp); } } } List <List <Face3D> > face3Ds = Enumerable.Repeat <List <Face3D> >(null, curveArrArrays.Count).ToList(); Parallel.For(0, curveArrArrays.Count, (int i) => { CurveArrArray curveArrArray = curveArrArrays[i]; if (curveArrArray == null || curveArrArray.Size == 0) { return; } face3Ds[i] = new List <Face3D>(); foreach (CurveArray curveArray in curveArrArray) { Polygon3D polygon3D = curveArray?.ToSAM_Polygon3D(); if (polygon3D == null && !polygon3D.IsValid()) { continue; } Spatial.Plane plane = polygon3D.GetPlane(); if (plane == null) { continue; } Polygon2D polygon2D = plane.Convert(polygon3D); if (polygon2D != null) { List <Segment2D> segment2Ds = segment3Ds.ConvertAll(x => plane.Convert(plane.Project(x))); segment2Ds.RemoveAll(x => x == null || x.GetLength() < Core.Tolerance.MacroDistance); segment2Ds = segment2Ds.Split(); List <Polygon2D> polygon2Ds = Planar.Create.Polygon2Ds(segment2Ds); if (polygon2Ds != null) { polygon2Ds = polygon2Ds.FindAll(x => x.Inside(polygon2D)); if (polygon2Ds != null && polygon2Ds.Count > 0) { polygon2Ds.Sort((x, y) => y.GetArea().CompareTo(x.GetArea())); polygon3D = plane.Convert(polygon2Ds[0]); } } } face3Ds[i].Add(new Face3D(polygon3D)); } }); foreach (List <Face3D> face3Ds_Temp in face3Ds) { if (face3Ds_Temp != null && face3Ds_Temp.Count > 0) { result.AddRange(face3Ds_Temp); } } } return(result); }
protected override void TrySolveInstance(IGH_DataAccess dataAccess) { int index = -1; bool run = false; index = Params.IndexOfInputParam("_run"); if (index == -1 || !dataAccess.GetData(index, ref run) || !run) { return; } double maxDistance = 0.2; index = Params.IndexOfInputParam("_maxDistance"); if (index == -1 || !dataAccess.GetData(index, ref maxDistance)) { return; } RhinoInside.Revit.GH.Types.Level level_GH = null; index = Params.IndexOfInputParam("_level"); if (index == -1 || !dataAccess.GetData(index, ref level_GH)) { AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Invalid data"); return; } RhinoInside.Revit.GH.Types.Level referenceLevel_GH = null; index = Params.IndexOfInputParam("_referenceLevel"); if (index == -1 || !dataAccess.GetData(index, ref referenceLevel_GH)) { AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Invalid data"); return; } Level level = level_GH.Value; if (level == null) { AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Invalid data"); return; } Level referenceLevel = referenceLevel_GH.Value; if (level == null) { AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Invalid data"); return; } #if Revit2017 || Revit2018 || Revit2019 || Revit2020 double elevation = UnitUtils.ConvertFromInternalUnits(level.Elevation, DisplayUnitType.DUT_METERS); double referenceElevation = UnitUtils.ConvertFromInternalUnits(referenceLevel.Elevation, DisplayUnitType.DUT_METERS); #else double elevation = UnitUtils.ConvertFromInternalUnits(level.Elevation, UnitTypeId.Meters); double referenceElevation = UnitUtils.ConvertFromInternalUnits(referenceLevel.Elevation, UnitTypeId.Meters); #endif Document document = level.Document; IEnumerable <Autodesk.Revit.DB.Wall> walls_All = new FilteredElementCollector(document).OfClass(typeof(Autodesk.Revit.DB.Wall)).Cast <Autodesk.Revit.DB.Wall>(); if (walls_All == null || walls_All.Count() == 0) { return; } StartTransaction(document); ConvertSettings convertSettings = new ConvertSettings(true, true, true); List <Panel> panels = new List <Panel>(); List <Panel> panels_Reference = new List <Panel>(); foreach (Autodesk.Revit.DB.Wall wall in walls_All) { List <Panel> panels_Temp = Analytical.Revit.Convert.ToSAM(wall, convertSettings); foreach (Panel panel in panels_Temp) { double max = panel.MaxElevation(); double min = panel.MinElevation(); if (Math.Abs(min - elevation) < Core.Tolerance.Distance || (min - Core.Tolerance.Distance < elevation && max - Core.Tolerance.Distance > elevation)) { panels.Add(panel); } if (Math.Abs(min - referenceElevation) < Core.Tolerance.Distance || (min - Core.Tolerance.Distance < referenceElevation && max - Core.Tolerance.Distance > referenceElevation)) { panels_Reference.Add(panel); } } } IEnumerable <ElementId> elementIds = panels.ConvertAll(x => x.ElementId()).Distinct(); IEnumerable <ElementId> elementIds_Reference = panels_Reference.ConvertAll(x => x.ElementId()).Distinct(); Geometry.Spatial.Plane plane = new Geometry.Spatial.Plane(new Point3D(0, 0, elevation), Vector3D.WorldZ); Dictionary <Segment2D, HostObjAttributes> dictionary_Reference = new Dictionary <Segment2D, HostObjAttributes>(); foreach (ElementId elementId in elementIds_Reference) { Element element = document.GetElement(elementId); if (element == null) { continue; } HostObjAttributes hostObjAttributes = document.GetElement(element.GetTypeId()) as HostObjAttributes; if (hostObjAttributes == null) { continue; } LocationCurve locationCurve = element.Location as LocationCurve; ISegmentable3D segmentable3D = locationCurve.ToSAM() as ISegmentable3D; if (segmentable3D == null) { continue; } List <Segment3D> segment3Ds = segmentable3D.GetSegments(); if (segment3Ds == null || segment3Ds.Count == 0) { continue; } segment3Ds.ForEach(x => dictionary_Reference[plane.Convert(x)] = hostObjAttributes); } Dictionary <Segment2D, ElementId> dictionary = new Dictionary <Segment2D, ElementId>(); foreach (ElementId elementId in elementIds) { LocationCurve locationCurve = document.GetElement(elementId).Location as LocationCurve; Segment3D segment3D = locationCurve.ToSAM() as Segment3D; if (segment3D == null) { continue; } dictionary[plane.Convert(plane.Project(segment3D))] = elementId; } Dictionary <Segment2D, ElementId> dictionary_Result = new Dictionary <Segment2D, ElementId>(); foreach (KeyValuePair <Segment2D, ElementId> keyValuePair in dictionary) { Segment2D segment2D = keyValuePair.Key; List <Segment2D> segment2Ds_Temp = dictionary_Reference.Keys.ToList().FindAll(x => x.Collinear(segment2D) && x.Distance(segment2D) <= maxDistance + Core.Tolerance.MacroDistance && x.Distance(segment2D) > Core.Tolerance.MacroDistance); if (segment2Ds_Temp == null || segment2Ds_Temp.Count == 0) { continue; } Element element = document.GetElement(keyValuePair.Value); if (element == null) { continue; } HostObjAttributes hostObjAttributes = document.GetElement(element.GetTypeId()) as HostObjAttributes; if (hostObjAttributes == null) { continue; } segment2Ds_Temp.Sort((x, y) => segment2D.Distance(x).CompareTo(segment2D.Distance(y))); Segment2D segment2D_Reference = null; foreach (Segment2D segment2D_Temp in segment2Ds_Temp) { HostObjAttributes hostObjAttributes_Temp = dictionary_Reference[segment2D_Temp]; if (hostObjAttributes.Name.Equals(hostObjAttributes_Temp.Name)) { segment2D_Reference = segment2D_Temp; break; } } if (segment2D_Reference == null) { HashSet <PanelType> panelTypes = new HashSet <PanelType>(); panelTypes.Add(Analytical.Revit.Query.PanelType(hostObjAttributes)); switch (panelTypes.First()) { case PanelType.CurtainWall: panelTypes.Add(PanelType.WallExternal); break; case PanelType.UndergroundWall: panelTypes.Add(PanelType.WallExternal); break; case PanelType.Undefined: panelTypes.Add(PanelType.WallInternal); break; } foreach (Segment2D segment2D_Temp in segment2Ds_Temp) { HostObjAttributes hostObjAttributes_Temp = dictionary_Reference[segment2D_Temp]; PanelType panelType_Temp = Analytical.Revit.Query.PanelType(hostObjAttributes_Temp); if (panelTypes.Contains(panelType_Temp)) { segment2D_Reference = segment2D_Temp; break; } } } if (segment2D_Reference == null) { segment2D_Reference = segment2Ds_Temp.First(); } Segment2D segment2D_Project = segment2D_Reference.Project(segment2D); if (segment2D_Project == null) { continue; } dictionary_Result[segment2D_Project] = dictionary[segment2D]; } List <HostObject> result = new List <HostObject>(); foreach (KeyValuePair <Segment2D, ElementId> keyValuePair in dictionary_Result) { Autodesk.Revit.DB.Wall wall = document.GetElement(keyValuePair.Value) as Autodesk.Revit.DB.Wall; if (wall == null || !wall.IsValidObject) { continue; } Segment2D segment2D = keyValuePair.Key; bool pinned = wall.Pinned; if (wall.Pinned) { using (SubTransaction subTransaction = new SubTransaction(document)) { subTransaction.Start(); wall.Pinned = false; subTransaction.Commit(); } } Segment3D segment3D = plane.Convert(segment2D); LocationCurve locationCurve = wall.Location as LocationCurve; using (SubTransaction subTransaction = new SubTransaction(document)) { subTransaction.Start(); document.Regenerate(); locationCurve.Curve = Geometry.Revit.Convert.ToRevit(segment3D); subTransaction.Commit(); } if (wall.Pinned != pinned) { using (SubTransaction subTransaction = new SubTransaction(document)) { subTransaction.Start(); wall.Pinned = pinned; subTransaction.Commit(); } } result.Add(wall); } index = Params.IndexOfOutputParam("walls"); if (index != -1) { dataAccess.SetDataList(index, result); } }