FrameWall(Autodesk.Revit.ApplicationServices.Application rvtApp, Autodesk.Revit.DB.Wall wall, double spacing, FamilySymbol columnType) { Document rvtDoc = wall.Document; LocationCurve loc = (LocationCurve)wall.Location; XYZ startPt = loc.Curve.GetEndPoint(0); XYZ endPt = loc.Curve.GetEndPoint(1); UV wallVec = new UV(endPt.X - startPt.X, endPt.Y - startPt.Y); UV axis = new UV(1.0, 0.0); ElementId baseLevelId = wall.get_Parameter(BuiltInParameter.WALL_BASE_CONSTRAINT).AsElementId(); ElementId topLevelId = wall.get_Parameter(BuiltInParameter.WALL_HEIGHT_TYPE).AsElementId(); double wallLength = VecLength(wallVec); wallVec = VecNormalise(wallVec); int nmax = (int)(wallLength / spacing); MessageBox.Show("Wall Length = " + wallLength + "\nSpacing = " + spacing + "\nMax Number = " + nmax, "Structural Sample", MessageBoxButtons.OK, MessageBoxIcon.Information); double angle = VecAngle(wallVec, axis); XYZ loc2 = startPt; double dx = wallVec.U * spacing; double dy = wallVec.V * spacing; for (int i = 0; i < nmax; i++) { PlaceColumn(rvtApp, rvtDoc, loc2, angle, columnType, baseLevelId, topLevelId); loc2 = new XYZ(startPt.X + dx, startPt.Y + dy, startPt.Z); } PlaceColumn(rvtApp, rvtDoc, endPt, angle, columnType, baseLevelId, topLevelId); }
private double GetOffsetForLocationCurve(DB.Wall wall) { var wallType = GetApplicableType(wall); var cstruct = wallType.GetCompoundStructure(); if (cstruct != null) { int wallLocationLine = wall.get_Parameter(DB.BuiltInParameter.WALL_KEY_REF_PARAM).AsInteger(); return(cstruct.GetOffsetForLocationLine( (DB.WallLocationLine)Enum.ToObject(typeof(DB.WallLocationLine), wallLocationLine) )); } else { return(0); } }
// TODO: Wall to Speckle // TODO: Set levels, heights, etc. // Does not go through nicely from revit to revit public static SpeckleElementsClasses.Wall ToSpeckle(this Autodesk.Revit.DB.Wall myWall) { var speckleWall = new SpeckleElementsClasses.Wall(); speckleWall.baseCurve = SpeckleCore.Converter.Serialise(((LocationCurve)myWall.Location).Curve) as SpeckleObject; var heightParam = myWall.get_Parameter(BuiltInParameter.WALL_USER_HEIGHT_PARAM); var heightValue = heightParam.AsDouble(); var height = UnitUtils.ConvertFromInternalUnits(heightValue, heightParam.DisplayUnitType); speckleWall.height = heightValue / Scale; var offsetParam = myWall.get_Parameter(BuiltInParameter.WALL_BASE_OFFSET); var offsetValue = offsetParam.AsDouble(); var offset = UnitUtils.ConvertFromInternalUnits(offsetValue, offsetParam.DisplayUnitType); speckleWall.offset = offsetValue / Scale; speckleWall.wallType = myWall.WallType.Name; var level = (Level)Doc.GetElement(myWall.get_Parameter(BuiltInParameter.WALL_BASE_CONSTRAINT).AsElementId()); speckleWall.baseLevel = level.ToSpeckle(); try { var topLevel = (Level)Doc.GetElement(myWall.get_Parameter(BuiltInParameter.WALL_HEIGHT_TYPE).AsElementId()); speckleWall.topLevel = topLevel.ToSpeckle(); } catch (Exception e) { } speckleWall.parameters = GetElementParams(myWall); speckleWall.typeParameters = GetElementTypeParams(myWall); var grid = myWall.CurtainGrid; // TODO: Should move maybe in base class defintion speckleWall.Properties["__flipped"] = myWall.Flipped; speckleWall.ApplicationId = myWall.UniqueId; speckleWall.elementId = myWall.Id.ToString(); speckleWall.GenerateHash(); // meshing for walls in case they are curtain grids if (grid != null) { var mySolids = new List <Solid>(); foreach (ElementId panelId in grid.GetPanelIds()) { mySolids.AddRange(GetElementSolids(Doc.GetElement(panelId))); } foreach (ElementId mullionId in grid.GetMullionIds()) { mySolids.AddRange(GetElementSolids(Doc.GetElement(mullionId))); } (speckleWall.Faces, speckleWall.Vertices) = GetFaceVertexArrFromSolids(mySolids); } else { (speckleWall.Faces, speckleWall.Vertices) = GetFaceVertexArrayFromElement(myWall, new Options() { DetailLevel = ViewDetailLevel.Fine, ComputeReferences = false }); } return(speckleWall); }
public static HostObject ToRevit(this Panel panel, Document document, Core.Revit.ConvertSettings convertSettings) { Geometry.Spatial.Face3D face3D = panel?.GetFace3D(); if (face3D == null) { return(null); } HostObject result = convertSettings?.GetObject <HostObject>(panel.Guid); if (result != null) { return(result); } PanelType panelType = panel.PanelType; Geometry.Spatial.Vector3D normal = panel.Normal; HostObjAttributes hostObjAttributes = panel.Construction.ToRevit(document, panelType, normal, convertSettings); if (hostObjAttributes == null) { hostObjAttributes = Analytical.Query.DefaultConstruction(panelType)?.ToRevit(document, panelType, normal, convertSettings); //Default Construction } BuiltInParameter[] builtInParameters = null; if (hostObjAttributes is Autodesk.Revit.DB.WallType) { double lowElevation = panel.LowElevation(); Level level = document.LowLevel(lowElevation); Autodesk.Revit.DB.Wall wall = ToRevit_Wall(face3D, document, (Autodesk.Revit.DB.WallType)hostObjAttributes, level); if (wall == null) { return(result); } //List<Curve> curveList = new List<Curve>(); //foreach (Geometry.Spatial.IClosedPlanar3D closedPlanar3D in face3D.GetEdge3Ds()) //{ // if (Geometry.Spatial.Query.Clockwise(closedPlanar3D)) // closedPlanar3D.Reverse(); // List<Line> lines = closedPlanar3D.ToRevit(); // if (lines == null) // continue; // curveList.AddRange(lines); //} //if (curveList == null || curveList.Count == 0) // return null; //double lowElevation = panel.LowElevation(); //Level level = document.LowLevel(lowElevation); //if (level == null) // return null; //Wall wall = Wall.Create(document, curveList, hostObjAttributes.Id, level.Id, false, panel.Normal.ToRevit(false)); Parameter parameter = null; parameter = wall.get_Parameter(BuiltInParameter.WALL_HEIGHT_TYPE); if (parameter != null) { parameter.Set(ElementId.InvalidElementId); } parameter = wall.get_Parameter(BuiltInParameter.WALL_USER_HEIGHT_PARAM); if (parameter != null) { #if Revit2017 || Revit2018 || Revit2019 || Revit2020 double height = UnitUtils.ConvertToInternalUnits((panel.HighElevation() - lowElevation), DisplayUnitType.DUT_METERS); #else double height = UnitUtils.ConvertToInternalUnits((panel.HighElevation() - lowElevation), UnitTypeId.Meters); #endif parameter.Set(height); } #if Revit2017 || Revit2018 || Revit2019 || Revit2020 double levelElevation = UnitUtils.ConvertFromInternalUnits(level.Elevation, DisplayUnitType.DUT_METERS); #else double levelElevation = UnitUtils.ConvertFromInternalUnits(level.Elevation, UnitTypeId.Meters); #endif if (Math.Abs(lowElevation - levelElevation) > Core.Tolerance.MacroDistance) { parameter = wall.get_Parameter(BuiltInParameter.WALL_BASE_OFFSET); if (parameter != null) { #if Revit2017 || Revit2018 || Revit2019 || Revit2020 parameter.Set(UnitUtils.ConvertToInternalUnits(lowElevation - levelElevation, DisplayUnitType.DUT_METERS)); #else parameter.Set(UnitUtils.ConvertToInternalUnits(lowElevation - levelElevation, UnitTypeId.Meters)); #endif } } builtInParameters = new BuiltInParameter[] { BuiltInParameter.WALL_BASE_CONSTRAINT, BuiltInParameter.WALL_BASE_OFFSET, BuiltInParameter.WALL_HEIGHT_TYPE, BuiltInParameter.WALL_USER_HEIGHT_PARAM, BuiltInParameter.WALL_KEY_REF_PARAM }; result = wall; } else if (hostObjAttributes is Autodesk.Revit.DB.FloorType) { Geometry.Spatial.IClosedPlanar3D closedPlanar3D_External = face3D.GetExternalEdge3D(); if (!(closedPlanar3D_External is Geometry.Spatial.ICurvable3D)) { return(null); } double elevation = panel.LowElevation(); Level level = document.HighLevel(elevation); Geometry.Spatial.Plane plane = new Geometry.Spatial.Plane(new Geometry.Spatial.Point3D(0, 0, elevation), Geometry.Spatial.Vector3D.WorldZ); CurveArray curveArray_Sloped = new CurveArray(); CurveArray curveArray_Plane = new CurveArray(); Geometry.Spatial.IClosedPlanar3D closedPlanar3D = face3D.GetExternalEdge3D(); if (!(closedPlanar3D is Geometry.Spatial.ICurvable3D)) { return(null); } List <Geometry.Spatial.Segment3D> segment3Ds = Geometry.Revit.Query.Segment3Ds(closedPlanar3D); if (segment3Ds == null || segment3Ds.Count == 0) { return(null); } foreach (Geometry.Spatial.Segment3D segment3D in segment3Ds) { curveArray_Sloped.Append(segment3D.ToRevit_Line()); Geometry.Spatial.Segment3D segment3D_Temp = Geometry.Spatial.Query.Project(plane, segment3D); if (segment3D_Temp == null) { continue; } curveArray_Plane.Append(segment3D_Temp.ToRevit_Line()); } #if Revit2017 || Revit2018 || Revit2019 || Revit2020 || Revit2021 Autodesk.Revit.DB.Floor floor = document.Create.NewFloor(curveArray_Plane, hostObjAttributes as Autodesk.Revit.DB.FloorType, level, false); #else CurveLoop curveLoop = new CurveLoop(); foreach (Curve curve in curveArray_Plane) { curveLoop.Append(curve); } Autodesk.Revit.DB.Floor floor = Autodesk.Revit.DB.Floor.Create(document, new CurveLoop[] { curveLoop }, hostObjAttributes.Id, level.Id); #endif if (floor != null) { floor.ChangeTypeId(hostObjAttributes.Id); List <Geometry.Spatial.IClosedPlanar3D> closedPlanar3Ds_Internal = face3D.GetInternalEdge3Ds(); if (closedPlanar3Ds_Internal != null && closedPlanar3Ds_Internal.Count > 0) { //Requires to be regenerated before inserting openings //https://thebuildingcoder.typepad.com/blog/2013/07/create-a-floor-with-an-opening-or-complex-boundary.html document.Regenerate(); foreach (Geometry.Spatial.IClosedPlanar3D closedPlanar3D_Internal in face3D.GetInternalEdge3Ds()) { List <Geometry.Spatial.Segment3D> segment3Ds_Internal = Geometry.Revit.Query.Segment3Ds(closedPlanar3D_Internal); if (segment3Ds_Internal == null || segment3Ds_Internal.Count == 0) { continue; } curveArray_Plane = new CurveArray(); //foreach (Geometry.Spatial.Segment3D segment3D in segment3Ds) foreach (Geometry.Spatial.Segment3D segment3D in segment3Ds_Internal) { curveArray_Sloped.Append(segment3D.ToRevit_Line()); Geometry.Spatial.Segment3D segment3D_Temp = Geometry.Spatial.Query.Project(plane, segment3D); if (segment3D_Temp == null) { continue; } curveArray_Plane.Append(segment3D_Temp.ToRevit_Line()); } Opening opening = document.Create.NewOpening(floor, curveArray_Plane, true); } } } if (floor != null) { document.Regenerate(); SlabShapeEditor slabShapeEditor = floor.SlabShapeEditor; if (slabShapeEditor != null) { slabShapeEditor.ResetSlabShape(); foreach (Curve curve in curveArray_Sloped) { XYZ xYZ = curve.GetEndPoint(0); slabShapeEditor.DrawPoint(xYZ); } } } builtInParameters = new BuiltInParameter[] { BuiltInParameter.LEVEL_PARAM }; result = floor; } else if (hostObjAttributes is Autodesk.Revit.DB.RoofType) { CurveArray curveArray = new CurveArray(); foreach (Geometry.Spatial.IClosedPlanar3D closedPlanar3D in face3D.GetEdge3Ds()) { List <Geometry.Spatial.Segment3D> segment3Ds = Geometry.Revit.Query.Segment3Ds(closedPlanar3D); if (segment3Ds == null || segment3Ds.Count == 0) { return(null); } segment3Ds.ForEach(x => curveArray.Append(x.ToRevit_Line())); } Level level = document.HighLevel(panel.LowElevation()); double levelElevation = level.Elevation; ModelCurveArray modelCurveArray = new ModelCurveArray(); RoofBase roofBase = document.Create.NewFootPrintRoof(curveArray, level, hostObjAttributes as Autodesk.Revit.DB.RoofType, out modelCurveArray); Parameter parameter = roofBase.get_Parameter(BuiltInParameter.ROOF_UPTO_LEVEL_PARAM); if (parameter != null) { parameter.Set(ElementId.InvalidElementId); } SlabShapeEditor slabShapeEditor = roofBase.SlabShapeEditor; if (slabShapeEditor != null) { slabShapeEditor.ResetSlabShape(); foreach (Curve curve in curveArray) { XYZ xYZ = curve.GetEndPoint(0); //if (Math.Abs(xYZ.Z - levelElevation) > Core.Tolerance.MicroDistance) slabShapeEditor.DrawPoint(xYZ); } } builtInParameters = new BuiltInParameter[] { BuiltInParameter.ROOF_LEVEL_OFFSET_PARAM, BuiltInParameter.ROOF_BASE_LEVEL_PARAM, BuiltInParameter.ROOF_UPTO_LEVEL_PARAM }; result = roofBase; } if (result == null) { return(null); } List <Aperture> apertures = panel.Apertures; if (apertures != null) { if (result is Autodesk.Revit.DB.Wall && ((Autodesk.Revit.DB.Wall)result).WallType.Kind == WallKind.Curtain) { } else { foreach (Aperture aperture in apertures) { Geometry.Spatial.Plane plane_Aperture = aperture?.PlanarBoundary3D?.Plane; if (plane_Aperture == null) { continue; } //bool flipHand = !plane_Panel.AxisX.SameHalf(plane_Aperture.AxisX); //bool flipFacing = !plane_Panel.Normal.SameHalf(plane_Aperture.Normal); FamilyInstance failyInstance_Aperture = aperture.ToRevit(document, result, convertSettings); } } } if (convertSettings.ConvertParameters) { Core.Revit.Modify.SetValues(result, panel, builtInParameters); Core.Revit.Modify.SetValues(result, panel, ActiveSetting.Setting); Core.Revit.Modify.SetJson(result, panel.ToJObject()?.ToString()); } //TODO: Implement proper log //System.IO.File.AppendAllText(@"C:\Users\DengusiakM\Desktop\SAM\2020-04-16 floorbug\LOG.txt", string.Format("{0}\t{1}\t{2}\n", DateTime.Now.ToString(), panel.Guid, panel.Name)); convertSettings?.Add(panel.Guid, result); return(result); }
private static Autodesk.Revit.DB.Wall CopyWall(Autodesk.Revit.DB.WallType wallType, Autodesk.Revit.DB.Wall Wall, Level level_Bottom, Level level_Top, Dictionary <ElementId, List <FamilyInstance> > dictionary_Hosts, Dictionary <BuiltInCategory, FamilySymbol> dictionary_Symbols) { if (wallType == null || Wall == null) { return(null); } if (!(Wall.Location is LocationCurve)) { return(null); } LocationCurve locationCurve = Wall.Location as LocationCurve; Document document = wallType.Document; Autodesk.Revit.DB.Wall result = Autodesk.Revit.DB.Wall.Create(wallType.Document, locationCurve.Curve, level_Bottom.Id, false); result.WallType = wallType; //FamilyInstance aFamilyInstance = aDocument.Create.NewFamilyInstance(aLocationCurve.Curve, ElementType, Level_Bottom, Autodesk.Revit.DB.Structure.StructuralType.NonStructural); if (result == null) { return(null); } if (Wall.Flipped != result.Flipped) { result.Flip(); } Parameter parameter = null; if (level_Top.Elevation > level_Bottom.Elevation) { parameter = result.get_Parameter(BuiltInParameter.WALL_HEIGHT_TYPE); if (parameter != null) { parameter.Set(level_Top.Id); } } else { parameter = result.get_Parameter(BuiltInParameter.WALL_USER_HEIGHT_PARAM); if (parameter != null && !parameter.IsReadOnly) { #if Revit2017 || Revit2018 || Revit2019 || Revit2020 parameter.Set(UnitUtils.ConvertToInternalUnits(2000, DisplayUnitType.DUT_MILLIMETERS)); #else parameter.Set(UnitUtils.ConvertToInternalUnits(2000, UnitTypeId.Millimeters)); #endif } } parameter = result.get_Parameter(BuiltInParameter.ALL_MODEL_INSTANCE_COMMENTS); if (parameter != null) { parameter.Set(Wall.Id.IntegerValue.ToString()); } document.Regenerate(); AddHosts(result, Wall.Id, dictionary_Hosts, dictionary_Symbols); 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; } Element element = null; index = Params.IndexOfInputParam("_element"); if (index == -1 || !dataAccess.GetData(index, ref element)) { return; } Transform transform; if (element == null) { AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Invalid data"); return; } StartTransaction(element.Document); bool successful = false; if (element is Autodesk.Revit.DB.Wall) { List <Level> levels = new FilteredElementCollector(element.Document).OfClass(typeof(Level)).Cast <Level>().ToList(); if (levels != null && levels.Count != 0) { BoundingBoxXYZ boundingBoxXYZ = element.get_BoundingBox(null); if (boundingBoxXYZ != null) { Level level = levels.Find(x => x.Elevation.AlmostEqual(boundingBoxXYZ.Max.Z, Tolerance.MacroDistance)); if (level != null) { Autodesk.Revit.DB.Wall wall = (Autodesk.Revit.DB.Wall)element; Parameter parameter = wall.get_Parameter(BuiltInParameter.WALL_HEIGHT_TYPE); if (parameter != null) { successful = parameter.Set(level.Id); } } } } } else if (element is Autodesk.Revit.DB.Mechanical.Space) { List <Level> levels = new FilteredElementCollector(element.Document).OfClass(typeof(Level)).Cast <Level>().ToList(); if (levels != null && levels.Count != 0) { Autodesk.Revit.DB.Mechanical.Space space = (Autodesk.Revit.DB.Mechanical.Space)element; double elevation = space.UnboundedHeight + levels.Find(x => x.Id == space.LevelId).Elevation; Level level = levels.Find(x => x.Elevation.AlmostEqual(elevation, Tolerance.MacroDistance)); if (level != null) { Parameter parameter = space.get_Parameter(BuiltInParameter.ROOM_UPPER_LEVEL); if (parameter != null) { if (parameter.AsElementId() != level.Id) { successful = parameter.Set(level.Id); parameter = space.get_Parameter(BuiltInParameter.ROOM_UPPER_OFFSET); if (parameter != null) { parameter.Set(0.0); } } } } } } index = Params.IndexOfOutputParam("element"); if (index != -1) { dataAccess.SetData(index, element); } index = Params.IndexOfOutputParam("successful"); if (index != -1) { dataAccess.SetData(index, successful); } }