예제 #1
0
        void ReconstructWallByCurve
        (
            DB.Document doc,
            ref DB.Wall element,

            Rhino.Geometry.Curve curve,
            Optional <DB.WallType> type,
            Optional <DB.Level> level,
            Optional <double> height,
            [Optional] DB.WallLocationLine locationLine,
            [Optional] bool flipped,
            [Optional, NickName("J")] bool allowJoins,
            [Optional] DB.Structure.StructuralWallUsage structuralUsage
        )
        {
#if REVIT_2020
            if
            (
                !(curve.IsLinear(Revit.VertexTolerance * Revit.ModelUnits) || curve.IsArc(Revit.VertexTolerance * Revit.ModelUnits) || curve.IsEllipse(Revit.VertexTolerance * Revit.ModelUnits)) ||
                !curve.TryGetPlane(out var axisPlane, Revit.VertexTolerance * Revit.ModelUnits) ||
                axisPlane.ZAxis.IsParallelTo(Rhino.Geometry.Vector3d.ZAxis, Revit.AngleTolerance) == 0
            )
            {
                ThrowArgumentException(nameof(curve), "Curve must be a horizontal line, arc or ellipse curve.");
            }
#else
            if
            (
                !(curve.IsLinear(Revit.VertexTolerance * Revit.ModelUnits) || curve.IsArc(Revit.VertexTolerance * Revit.ModelUnits)) ||
                !curve.TryGetPlane(out var axisPlane, Revit.VertexTolerance * Revit.ModelUnits) ||
                axisPlane.ZAxis.IsParallelTo(Rhino.Geometry.Vector3d.ZAxis, Revit.AngleTolerance) == 0
            )
            {
                ThrowArgumentException(nameof(curve), "Curve must be a horizontal line or arc curve.");
            }
#endif

            SolveOptionalType(ref type, doc, DB.ElementTypeGroup.WallType, nameof(type));

            bool levelIsEmpty = SolveOptionalLevel(doc, curve, ref level, out var bbox);

            // Curve
            var levelPlane = new Rhino.Geometry.Plane(new Rhino.Geometry.Point3d(0.0, 0.0, level.Value.GetHeight() * Revit.ModelUnits), Rhino.Geometry.Vector3d.ZAxis);
            if (!TryGetCurveAtPlane(curve, levelPlane, out var centerLine))
            {
                ThrowArgumentException(nameof(curve), "Failed to project curve in the level plane.");
            }

            // Height
            if (!height.HasValue)
            {
                height = type.GetValueOrDefault()?.GetCompoundStructure()?.SampleHeight *Revit.ModelUnits ?? LiteralLengthValue(6.0);
            }

            if (height.Value < 0.1 * Revit.ModelUnits)
            {
                ThrowArgumentException(nameof(height), $"Height minimum value is {0.1 * Revit.ModelUnits} {Rhino.RhinoDoc.ActiveDoc.ModelUnitSystem}");
            }
            else if (height.Value > 3000 * Revit.ModelUnits)
            {
                ThrowArgumentException(nameof(height), $"Height maximum value is {3000 * Revit.ModelUnits} {Rhino.RhinoDoc.ActiveDoc.ModelUnitSystem}");
            }

            // LocationLine
            if (locationLine != DB.WallLocationLine.WallCenterline)
            {
                double offsetDist        = 0.0;
                var    compoundStructure = type.Value.GetCompoundStructure();
                if (compoundStructure == null)
                {
                    switch (locationLine)
                    {
                    case DB.WallLocationLine.WallCenterline:
                    case DB.WallLocationLine.CoreCenterline:
                        break;

                    case DB.WallLocationLine.FinishFaceExterior:
                    case DB.WallLocationLine.CoreExterior:
                        offsetDist = type.Value.Width / +2.0;
                        break;

                    case DB.WallLocationLine.FinishFaceInterior:
                    case DB.WallLocationLine.CoreInterior:
                        offsetDist = type.Value.Width / -2.0;
                        break;
                    }
                }
                else
                {
                    if (!compoundStructure.IsVerticallyHomogeneous())
                    {
                        compoundStructure = DB.CompoundStructure.CreateSimpleCompoundStructure(compoundStructure.GetLayers());
                    }

                    offsetDist = compoundStructure.GetOffsetForLocationLine(locationLine);
                }

                if (offsetDist != 0.0)
                {
                    centerLine = centerLine.CreateOffset(flipped ? -offsetDist : offsetDist, DB.XYZ.BasisZ);
                }
            }

            // Type
            ChangeElementTypeId(ref element, type.Value.Id);

            DB.Wall newWall = null;
            if (element is DB.Wall previousWall && previousWall.Location is DB.LocationCurve locationCurve && centerLine.IsSameKindAs(locationCurve.Curve))
            {
                newWall = previousWall;

                locationCurve.Curve = centerLine;
            }
예제 #2
0
        public static Autodesk.Revit.DB.WallType UpdateWallType(this Document document, Autodesk.Revit.DB.Wall wall)
        {
            List <Autodesk.Revit.DB.WallType> wallTypes = new FilteredElementCollector(document).OfCategory(BuiltInCategory.OST_Walls).OfClass(typeof(Autodesk.Revit.DB.WallType)).Cast <Autodesk.Revit.DB.WallType>().ToList();

            if (wallTypes == null || wallTypes.Count < 1)
            {
                return(null);
            }

            Autodesk.Revit.DB.WallType wallType = null;
            foreach (Autodesk.Revit.DB.WallType wallType_Temp in wallTypes)
            {
                Parameter parameter = wallType_Temp.LookupParameter("SAM_BuildingElementDescription");
                if (parameter != null)
                {
                    string value = parameter.AsString();
                    if (!string.IsNullOrEmpty(value) && value == wall.Name)
                    {
                        wallType = wallType_Temp;
                        break;
                    }
                }
            }

            if (wallType == null)
            {
                string name = string.Format("ARCH_Wall_{0}", wall.Name);
                wallType = wallTypes.Find(x => x.Name == name);
                if (wallType == null)
                {
                    wallType = wallTypes.Find(x => x.Name == "ARCH_Wall");
                    if (wallType == null)
                    {
                        wallType = wallTypes.First();
                        wallType = wallType.Duplicate(name) as Autodesk.Revit.DB.WallType;
                    }
                }

                if (wallType == null)
                {
                    return(null);
                }

                Element element = wall.Document.GetElement(wall.GetTypeId());
                if (element == null)
                {
                    return(wallType);
                }

                Parameter parameter_Source      = null;
                Parameter parameter_Destination = null;

                parameter_Source = element.get_Parameter(BuiltInParameter.WALL_ATTR_WIDTH_PARAM);
                if (parameter_Source != null)
                {
                    parameter_Destination = wallType.LookupParameter("SAM_BuildingElementThickness");
                    if (parameter_Destination != null)
                    {
                        parameter_Destination.Set(parameter_Source.AsDouble());
                    }
                }

                parameter_Source = element.get_Parameter(BuiltInParameter.FUNCTION_PARAM);
                if (parameter_Source != null)
                {
                    parameter_Destination = wallType.LookupParameter("SAM_BuildingElementDescription");
                    if (parameter_Destination != null)
                    {
                        parameter_Destination.Set(name);
                    }

                    parameter_Destination = wallType.get_Parameter(BuiltInParameter.FUNCTION_PARAM);
                    if (parameter_Destination != null)
                    {
                        parameter_Destination.Set(parameter_Destination.AsInteger());
                    }
                }
            }

            return(wallType);
        }
예제 #3
0
        /// <summary>
        /// Frame a Wall
        /// </summary>
        /// <param name="rvtApp">Revit application></param>
        /// <param name="wall">Wall as host to place column objects</param>
        /// <param name="spacing">spacing between two columns</param>
        /// <param name="columnType">column type</param>
        private void FrameWall(Autodesk.Revit.ApplicationServices.Application rvtApp, Autodesk.Revit.DB.Wall wall,
                               double spacing, Autodesk.Revit.DB.FamilySymbol columnType)
        {
            Autodesk.Revit.DB.Document rvtDoc = wall.Document;

            // get wall location
            Autodesk.Revit.DB.LocationCurve loc     = (Autodesk.Revit.DB.LocationCurve)wall.Location;
            Autodesk.Revit.DB.XYZ           startPt = loc.Curve.GetEndPoint(0);
            Autodesk.Revit.DB.XYZ           endPt   = loc.Curve.GetEndPoint(1);

            // get wall's vector
            Autodesk.Revit.DB.UV wallVec = new Autodesk.Revit.DB.UV(
                endPt.X - startPt.X,
                endPt.Y - startPt.Y);

            // get the axis vector
            Autodesk.Revit.DB.UV axis = new Autodesk.Revit.DB.UV(1.0, 0.0);

            Autodesk.Revit.DB.ElementId baseLevelId = wall.get_Parameter(BuiltInParameter.WALL_BASE_CONSTRAINT).AsElementId();
            Autodesk.Revit.DB.ElementId topLevelId  = wall.get_Parameter(BuiltInParameter.WALL_HEIGHT_TYPE).AsElementId();

            // get wall length and vector
            double wallLength = wallVec.GetLength();

            wallVec = wallVec.Normalize();

            // get # of column
            int nmax = (int)(wallLength / spacing);

            TaskDialog.Show("Revit", "wallLength = " + wallLength + "\r\nspacing = " + spacing.ToString() + "\r\nnmax = " + nmax.ToString());

            // get angle of wall and axis
            double angle = wallVec.AngleTo(axis);

            // place all column
            Autodesk.Revit.DB.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(loc2.X + dx,
                               loc2.Y + dy,
                               loc2.Z);
            }

            // place column at end point of wall
            PlaceColumn(rvtApp, rvtDoc, endPt, angle, columnType, baseLevelId, topLevelId);
        }
예제 #4
0
        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);
            }
        }
예제 #5
0
        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);
        }
예제 #6
0
        public static HostObject HostObject(this Aperture aperture, Document document)
        {
            HostObject result = null;

            PanelGroup panelGroup = Analytical.Query.PanelGroup(Analytical.Query.PanelType(aperture.Plane.Normal));

            switch (panelGroup)
            {
            case PanelGroup.Wall:
                IEnumerable <Autodesk.Revit.DB.Wall> walls = Geometry.Revit.Query.Elements <Autodesk.Revit.DB.Wall>(document, aperture.GetBoundingBox());

                if (walls != null && walls.Count() != 0)
                {
                    Geometry.Spatial.Point3D point3D = Geometry.Spatial.Query.InternalPoint3D(aperture.GetFace3D());
                    double distance             = double.MaxValue;
                    Autodesk.Revit.DB.Wall wall = null;
                    foreach (Autodesk.Revit.DB.Wall wall_Temp in walls)
                    {
                        List <Panel> panels = Convert.ToSAM(wall_Temp, new Core.Revit.ConvertSettings(true, false, false));
                        if (panels != null)
                        {
                            foreach (Panel panel in panels)
                            {
                                double distance_Temp = panel.GetFace3D().Distance(point3D);
                                if (distance_Temp < distance)
                                {
                                    distance = distance_Temp;
                                    wall     = wall_Temp;
                                }
                            }
                        }
                    }
                    result = wall;
                }

                break;

            case PanelGroup.Floor:
                IEnumerable <Element> elements_Floor = Geometry.Revit.Query.Elements(document, aperture.GetBoundingBox(), Autodesk.Revit.DB.BuiltInCategory.OST_Floors);
                if (elements_Floor != null && elements_Floor.Count() != 0)
                {
                    result = elements_Floor.First() as HostObject;
                }
                break;

            case PanelGroup.Roof:
                IEnumerable <Element> elements_Roof = Geometry.Revit.Query.Elements(document, aperture.GetBoundingBox(), Autodesk.Revit.DB.BuiltInCategory.OST_Roofs);
                if (elements_Roof != null && elements_Roof.Count() != 0)
                {
                    result = elements_Roof.First() as HostObject;
                }
                break;
            }

            if (result == null)
            {
                switch (panelGroup)
                {
                case PanelGroup.Roof:
                    IEnumerable <Element> elements_Floor = Geometry.Revit.Query.Elements(document, aperture.GetBoundingBox(), Autodesk.Revit.DB.BuiltInCategory.OST_Floors);
                    if (elements_Floor != null && elements_Floor.Count() != 0)
                    {
                        result = elements_Floor.First() as HostObject;
                    }
                    break;

                case PanelGroup.Floor:
                    IEnumerable <Element> elements_Roof = Geometry.Revit.Query.Elements(document, aperture.GetBoundingBox(), Autodesk.Revit.DB.BuiltInCategory.OST_Roofs);
                    if (elements_Roof != null && elements_Roof.Count() != 0)
                    {
                        result = elements_Roof.First() as HostObject;
                    }
                    break;
                }
            }

            return(result);
        }
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            // 0.import data
            Autodesk.Revit.DB.Wall wall = null;
            Autodesk.Revit.DB.PointCloudInstance element = null;
            double bufferDistance = 0.30; int numPoints = 50000;

            if (!DA.GetData("Revit Wall", ref wall))
            {
                return;
            }
            if (!DA.GetData("Revit Point Cloud Instance", ref element))
            {
                return;
            }
            if (!DA.GetData("bufferDistance", ref bufferDistance))
            {
                return;
            }
            if (!DA.GetData("numPoints", ref numPoints))
            {
                return;
            }

            // 1.Create selection filter
            var width                     = wall.Width + bufferDistance * 2;
            //var width = wall.get_Parameter(BuiltInParameter.WALL_ATTR_WIDTH_PARAM).AsDouble();
            //double width = UnitUtils.ConvertFromInternalUnits(wall.WallType.Width, DisplayUnitType);
            BoundingBoxXYZ boundingBox    = wall.get_BoundingBox(null);

            // 2. Compute boundary U
            LocationCurve locationCurve_u = wall.Location as LocationCurve;
            XYZ           endPoint0_u     = locationCurve_u.Curve.GetEndPoint(0);
            XYZ           endPoint1_u     = locationCurve_u.Curve.GetEndPoint(1);
            var           ux              = endPoint1_u.X - endPoint0_u.X;
            var           uy = endPoint1_u.Y - endPoint0_u.Y;
            XYZ           uxy = new XYZ(ux, uy, 0);

            // 3. Compute boudary V
            XYZ midpoint = endPoint0_u + ((endPoint1_u - endPoint0_u) / 2);
            //var axis =  Autodesk.Revit.DB.Line.CreateUnbound(midpoint, XYZ.BasisZ);
            //var locationCurve_v=locationCurve_u.Rotate(axis, Math.PI * 0.5);

            var endPoint0_v = locationCurve_u.Curve.Evaluate(locationCurve_u.Curve.Length * 0.5 - width * 0.5 * 10 - bufferDistance * 10, false);
            var endPoint1_v = locationCurve_u.Curve.Evaluate(locationCurve_u.Curve.Length * 0.5 + width * 0.5 * 10 + bufferDistance * 10, false);

            // rotate points 90°
            var endPoint0_v_X = (endPoint0_v.X - midpoint.X) * Math.Cos(Math.PI * 0.5) + (endPoint0_v.Y - midpoint.Y) * Math.Sin(Math.PI * 0.5) + midpoint.X;
            var endPoint0_v_Y = (endPoint0_v.X - midpoint.X) * -Math.Sin(Math.PI * 0.5) + (endPoint0_v.Y - midpoint.Y) * Math.Cos(Math.PI * 0.5) + midpoint.Y;
            var endPoint1_v_X = (endPoint1_v.X - midpoint.X) * Math.Cos(Math.PI * 0.5) + (endPoint1_v.Y - midpoint.Y) * Math.Sin(Math.PI * 0.5) + midpoint.X;
            var endPoint1_v_Y = (endPoint1_v.X - midpoint.X) * -Math.Sin(Math.PI * 0.5) + (endPoint1_v.Y - midpoint.Y) * Math.Cos(Math.PI * 0.5) + midpoint.Y;
            XYZ boundary0_v = new XYZ(endPoint0_v_X, endPoint0_v_Y, 0);
            XYZ boundary1_v = new XYZ(endPoint1_v_X, endPoint1_v_Y, 0);
            //XYZ endPoint0_v = locationCurve_u.Curve.GetEndPoint(0);
            //XYZ endPoint1_v = locationCurve_u.Curve.GetEndPoint(1);
            var vx = boundary1_v.X - boundary0_v.X;
            var vy = boundary1_v.Y - boundary0_v.Y;
            XYZ vxy = new XYZ(vx, vy, 0);



            // 4. Create boundary planes
            List <Autodesk.Revit.DB.Plane> planes = new List <Autodesk.Revit.DB.Plane>();

            // U boundaries
            planes.Add(Autodesk.Revit.DB.Plane.CreateByNormalAndOrigin(uxy, endPoint0_u));
            planes.Add(Autodesk.Revit.DB.Plane.CreateByNormalAndOrigin(-uxy, endPoint1_u));

            // V boundaries
            planes.Add(Autodesk.Revit.DB.Plane.CreateByNormalAndOrigin(vxy, boundary0_v));
            planes.Add(Autodesk.Revit.DB.Plane.CreateByNormalAndOrigin(-vxy, boundary1_v));

            // Z boundaries
            planes.Add(Autodesk.Revit.DB.Plane.CreateByNormalAndOrigin(XYZ.BasisZ, boundingBox.Min));
            planes.Add(Autodesk.Revit.DB.Plane.CreateByNormalAndOrigin(-XYZ.BasisZ, boundingBox.Max));

            // Create filter
            PointCloudFilter filter = PointCloudFilterFactory.CreateMultiPlaneFilter(planes);

            // 5.Fetch point cloud
            PointCollection cloudPoints   = element.GetPoints(filter, bufferDistance, numPoints);
            PointCloud      Rh_pointCloud = new PointCloud();

            // 6.Convert CloudPoints to rhino point cloud


            if (element.HasColor())
            {
                foreach (CloudPoint point in cloudPoints)
                {
                    // Process each point
                    Point3d point3d = new Point3d(point.X * 1000, point.Y * 1000, point.Z * 1000);

                    byte[] bArray = BitConverter.GetBytes(point.Color);
                    var    color  = System.Drawing.Color.FromArgb(bArray[0], bArray[1], bArray[2]);

                    Rh_pointCloud.Add(point3d, color);
                }
            }
            else
            {
                foreach (CloudPoint point in cloudPoints)
                {
                    // Process each point
                    Point3d point3d = new Point3d(point.X * 1000, point.Y * 1000, point.Z * 1000);
                    Rh_pointCloud.Add(point3d);
                }
            }


            // 7.Return Grasshopper Cloud
            GH_Cloud GH_pointCloud = new GH_Cloud(Rh_pointCloud);

            DA.SetData(0, GH_pointCloud);
        }
예제 #8
0
 /// <summary>
 /// Initialize a Wall element
 /// </summary>
 /// <param name="wall"></param>
 private void InitWall(Autodesk.Revit.DB.Wall wall)
 {
     InternalSetWall(wall);
 }
예제 #9
0
        void ReconstructWallByProfile
        (
            DB.Document doc,
            ref DB.Wall element,

            IList <Rhino.Geometry.Curve> profile,
            Optional <DB.WallType> type,
            Optional <DB.Level> level,
            [Optional] DB.WallLocationLine locationLine,
            [Optional] bool flipped,
            [Optional, NickName("J")] bool allowJoins,
            [Optional] DB.Structure.StructuralWallUsage structuralUsage
        )
        {
            foreach (var boundary in profile)
            {
                if
                (
                    !boundary.IsClosed ||
                    !boundary.TryGetPlane(out var boundaryPlane, Revit.VertexTolerance) ||
                    !boundaryPlane.ZAxis.IsPerpendicularTo(Rhino.Geometry.Vector3d.ZAxis)
                )
                {
                    ThrowArgumentException(nameof(boundary), "Boundary must be a vertical planar closed curve.");
                }
            }

            SolveOptionalType(ref type, doc, DB.ElementTypeGroup.WallType, nameof(type));
            SolveOptionalLevel(doc, profile, ref level, out var bbox);

            foreach (var curve in profile)
            {
                curve.RemoveShortSegments(Revit.ShortCurveTolerance * Revit.ModelUnits);
            }
            var boundaries = profile.SelectMany(x => GeometryEncoder.ToCurveMany(x)).SelectMany(CurveExtension.ToBoundedCurves).ToList();

            // LocationLine
            if (locationLine != DB.WallLocationLine.WallCenterline)
            {
                double offsetDist        = 0.0;
                var    compoundStructure = type.Value.GetCompoundStructure();
                if (compoundStructure == null)
                {
                    switch (locationLine)
                    {
                    case DB.WallLocationLine.WallCenterline:
                    case DB.WallLocationLine.CoreCenterline:
                        break;

                    case DB.WallLocationLine.FinishFaceExterior:
                    case DB.WallLocationLine.CoreExterior:
                        offsetDist = type.Value.Width / +2.0;
                        break;

                    case DB.WallLocationLine.FinishFaceInterior:
                    case DB.WallLocationLine.CoreInterior:
                        offsetDist = type.Value.Width / -2.0;
                        break;
                    }
                }
                else
                {
                    if (!compoundStructure.IsVerticallyHomogeneous())
                    {
                        compoundStructure = DB.CompoundStructure.CreateSimpleCompoundStructure(compoundStructure.GetLayers());
                    }

                    offsetDist = compoundStructure.GetOffsetForLocationLine(locationLine);
                }

                if (offsetDist != 0.0)
                {
                    profile[0].TryGetPlane(out var plane);
                    var translation = DB.Transform.CreateTranslation((plane.Normal * (flipped ? -offsetDist : offsetDist)).ToXYZ());
                    for (int b = 0; b < boundaries.Count; ++b)
                    {
                        boundaries[b] = boundaries[b].CreateTransformed(translation);
                    }
                }
            }

            var newWall = DB.Wall.Create
                          (
                doc,
                boundaries,
                type.Value.Id,
                level.Value.Id,
                structuralUsage != DB.Structure.StructuralWallUsage.NonBearing
                          );

            // Walls are created with the last LocationLine used in the Revit editor!!
            //newWall.get_Parameter(BuiltInParameter.WALL_KEY_REF_PARAM).Set((int) WallLocationLine.WallCenterline);

            var parametersMask = new DB.BuiltInParameter[]
            {
                DB.BuiltInParameter.ELEM_FAMILY_AND_TYPE_PARAM,
                DB.BuiltInParameter.ELEM_FAMILY_PARAM,
                DB.BuiltInParameter.ELEM_TYPE_PARAM,
                DB.BuiltInParameter.WALL_KEY_REF_PARAM,
                DB.BuiltInParameter.WALL_USER_HEIGHT_PARAM,
                DB.BuiltInParameter.WALL_BASE_CONSTRAINT,
                DB.BuiltInParameter.WALL_BASE_OFFSET,
                DB.BuiltInParameter.WALL_STRUCTURAL_SIGNIFICANT,
                DB.BuiltInParameter.WALL_STRUCTURAL_USAGE_PARAM
            };

            ReplaceElement(ref element, newWall, parametersMask);

            if (newWall != null)
            {
                newWall.get_Parameter(DB.BuiltInParameter.WALL_BASE_CONSTRAINT).Set(level.Value.Id);
                newWall.get_Parameter(DB.BuiltInParameter.WALL_BASE_OFFSET).Set(bbox.Min.Z / Revit.ModelUnits - level.Value.Elevation);
                newWall.get_Parameter(DB.BuiltInParameter.WALL_KEY_REF_PARAM).Set((int)locationLine);
                if (structuralUsage == DB.Structure.StructuralWallUsage.NonBearing)
                {
                    newWall.get_Parameter(DB.BuiltInParameter.WALL_STRUCTURAL_SIGNIFICANT).Set(0);
                }
                else
                {
                    newWall.get_Parameter(DB.BuiltInParameter.WALL_STRUCTURAL_SIGNIFICANT).Set(1);
                    newWall.get_Parameter(DB.BuiltInParameter.WALL_STRUCTURAL_USAGE_PARAM).Set((int)structuralUsage);
                }

                if (newWall.Flipped != flipped)
                {
                    newWall.Flip();
                }

                // Setup joins in a last step
                if (allowJoins)
                {
                    joinedWalls.Add(newWall);
                }
                else
                {
                    DB.WallUtils.DisallowWallJoinAtEnd(newWall, 0);
                    DB.WallUtils.DisallowWallJoinAtEnd(newWall, 1);
                }
            }
        }
예제 #10
0
 public Wall(DB.Wall host) : base(host)
 {
 }
예제 #11
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);

            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);
        }
예제 #12
0
        void ReconstructWallByCurve
        (
            DB.Document doc,
            ref DB.Element element,

            Rhino.Geometry.Curve curve,
            Optional <DB.WallType> type,
            Optional <DB.Level> level,
            [Optional] bool structural,
            [Optional] double height,
            [Optional] DB.WallLocationLine locationLine,
            [Optional] bool flipped,
            [Optional, NickName("J")] bool allowJoins
        )
        {
            var scaleFactor = 1.0 / Revit.ModelUnits;

#if REVIT_2020
            if
            (
                ((curve = curve.ChangeUnits(scaleFactor)) is null) ||
                !(curve.IsLinear(Revit.VertexTolerance) || curve.IsArc(Revit.VertexTolerance) || curve.IsEllipse(Revit.VertexTolerance)) ||
                !curve.TryGetPlane(out var axisPlane, Revit.VertexTolerance) ||
                axisPlane.ZAxis.IsParallelTo(Rhino.Geometry.Vector3d.ZAxis) == 0
            )
            {
                ThrowArgumentException(nameof(curve), "Curve must be a horizontal line, arc or ellipse curve.");
            }
#else
            if
            (
                ((curve = curve.ChangeUnits(scaleFactor)) is null) ||
                !(curve.IsLinear(Revit.VertexTolerance) || curve.IsArc(Revit.VertexTolerance)) ||
                !curve.TryGetPlane(out var axisPlane, Revit.VertexTolerance) ||
                axisPlane.ZAxis.IsParallelTo(Rhino.Geometry.Vector3d.ZAxis) == 0
            )
            {
                ThrowArgumentException(nameof(curve), "Curve must be a horizontal line or arc curve.");
            }
#endif

            SolveOptionalType(ref type, doc, DB.ElementTypeGroup.WallType, nameof(type));

            double axisMinZ     = Math.Min(curve.PointAtStart.Z, curve.PointAtEnd.Z);
            bool   levelIsEmpty = SolveOptionalLevel(ref level, doc, curve, nameof(level));

            height *= scaleFactor;
            if (height < Revit.VertexTolerance)
            {
                height = (type.HasValue ? type.Value : null)?.GetCompoundStructure()?.SampleHeight ?? LiteralLengthValue(6.0) / Revit.ModelUnits;
            }

            // Axis
            var levelPlane = new Rhino.Geometry.Plane(new Rhino.Geometry.Point3d(0.0, 0.0, level.Value.Elevation), Rhino.Geometry.Vector3d.ZAxis);
            curve = Rhino.Geometry.Curve.ProjectToPlane(curve, levelPlane);

            var centerLine = curve.ToHost();

            // LocationLine
            if (locationLine != DB.WallLocationLine.WallCenterline)
            {
                double offsetDist        = 0.0;
                var    compoundStructure = type.Value.GetCompoundStructure();
                if (compoundStructure == null)
                {
                    switch (locationLine)
                    {
                    case DB.WallLocationLine.WallCenterline:
                    case DB.WallLocationLine.CoreCenterline:
                        break;

                    case DB.WallLocationLine.FinishFaceExterior:
                    case DB.WallLocationLine.CoreExterior:
                        offsetDist = type.Value.Width / +2.0;
                        break;

                    case DB.WallLocationLine.FinishFaceInterior:
                    case DB.WallLocationLine.CoreInterior:
                        offsetDist = type.Value.Width / -2.0;
                        break;
                    }
                }
                else
                {
                    if (!compoundStructure.IsVerticallyHomogeneous())
                    {
                        compoundStructure = DB.CompoundStructure.CreateSimpleCompoundStructure(compoundStructure.GetLayers());
                    }

                    offsetDist = compoundStructure.GetOffsetForLocationLine(locationLine);
                }

                if (offsetDist != 0.0)
                {
                    centerLine = centerLine.CreateOffset(flipped ? -offsetDist : offsetDist, DB.XYZ.BasisZ);
                }
            }

            // Type
            ChangeElementTypeId(ref element, type.Value.Id);

            DB.Wall newWall = null;
            if (element is DB.Wall previousWall && previousWall.Location is DB.LocationCurve locationCurve && centerLine.IsSameKindAs(locationCurve.Curve))
            {
                newWall = previousWall;

                locationCurve.Curve = centerLine;
            }
예제 #13
0
        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);
            }
        }
예제 #14
0
 /// <summary>
 /// Set the internal Element, ElementId, and UniqueId
 /// </summary>
 /// <param name="wall"></param>
 private void InternalSetWall(Autodesk.Revit.DB.Wall wall)
 {
     InternalWall      = wall;
     InternalElementId = wall.Id;
     InternalUniqueId  = wall.UniqueId;
 }
예제 #15
0
        public Base WallToSpeckle(DB.Wall revitWall)
        {
            var baseGeometry = LocationToSpeckle(revitWall);

            if (baseGeometry is Geometry.Point)
            {
                return(RevitElementToSpeckle(revitWall));
            }

            RevitWall speckleWall = new RevitWall();

            speckleWall.family     = revitWall.WallType.FamilyName.ToString();
            speckleWall.type       = revitWall.WallType.Name;
            speckleWall.baseLine   = (ICurve)baseGeometry;
            speckleWall.level      = ConvertAndCacheLevel(revitWall, BuiltInParameter.WALL_BASE_CONSTRAINT);
            speckleWall.topLevel   = ConvertAndCacheLevel(revitWall, BuiltInParameter.WALL_HEIGHT_TYPE);
            speckleWall.height     = GetParamValue <double>(revitWall, BuiltInParameter.WALL_USER_HEIGHT_PARAM);
            speckleWall.baseOffset = GetParamValue <double>(revitWall, BuiltInParameter.WALL_BASE_OFFSET);
            speckleWall.topOffset  = GetParamValue <double>(revitWall, BuiltInParameter.WALL_TOP_OFFSET);
            speckleWall.structural = GetParamValue <bool>(revitWall, BuiltInParameter.WALL_STRUCTURAL_SIGNIFICANT);
            speckleWall.flipped    = revitWall.Flipped;


            if (revitWall.CurtainGrid == null)
            {
                if (revitWall.IsStackedWall)
                {
                    var wallMembers = revitWall.GetStackedWallMemberIds().Select(id => (Wall)Doc.GetElement(id));
                    speckleWall.elements = new List <Base>();
                    foreach (var wall in wallMembers)
                    {
                        speckleWall.elements.Add(WallToSpeckle(wall));
                    }
                }

                speckleWall.displayMesh = GetElementDisplayMesh(revitWall,
                                                                new Options()
                {
                    DetailLevel = ViewDetailLevel.Fine, ComputeReferences = false
                });
            }
            else
            {
                // curtain walls have two meshes, one for panels and one for mullions
                // adding mullions as sub-elements so they can be correctly displayed in viewers etc
                (var panelsMesh, var mullionsMesh) = GetCurtainWallDisplayMesh(revitWall);
                speckleWall["renderMaterial"]      = new Other.RenderMaterial()
                {
                    opacity = 0.2, diffuse = System.Drawing.Color.AliceBlue.ToArgb()
                };
                speckleWall.displayMesh = panelsMesh;

                var mullions = new Base
                {
                    ["@displayMesh"]   = mullionsMesh,
                    ["renderMaterial"] = new Other.RenderMaterial()
                    {
                        diffuse = System.Drawing.Color.DarkGray.ToArgb()
                    }
                };
                speckleWall.elements = new List <Base> {
                    mullions
                };
            }

            GetAllRevitParamsAndIds(speckleWall, revitWall, new List <string>
            {
                "WALL_USER_HEIGHT_PARAM",
                "WALL_BASE_OFFSET",
                "WALL_TOP_OFFSET",
                "WALL_BASE_CONSTRAINT",
                "WALL_HEIGHT_TYPE",
                "WALL_STRUCTURAL_SIGNIFICANT"
            });

            GetHostedElements(speckleWall, revitWall);
            //Report.Log($"Converted Wall {revitWall.Id}");
            return(speckleWall);
        }
예제 #16
0
 /// <summary>
 /// Create from an existing Revit Element
 /// </summary>
 /// <param name="wall"></param>
 private Wall(Autodesk.Revit.DB.Wall wall)
 {
     SafeInit(() => InitWall(wall));
 }
        private DB.XYZ GetOffsetPlaneNormal(DB.Wall wall)
        {
            var offsetPlaneNormal = -(DB.XYZ.BasisZ);

            return(wall.Flipped ? -offsetPlaneNormal : offsetPlaneNormal);
        }
예제 #18
0
 public static Wall Wrap(Autodesk.Revit.DB.Wall ele, bool isRevitOwned)
 {
     return(Wall.FromExisting(ele, isRevitOwned));
 }
예제 #19
0
        public static re.Element CreateWallOpening(re.Wall wall, dg.PolyCurve polyCrv)
        {
            try
            {
                // Try to get a wall from trace
                rdb.Document doc         = DocumentManager.Instance.CurrentDBDocument;
                var          openingElem = ElementBinder.GetElementFromTrace <rdb.Element>(doc);
                rdb.Opening  opening     = null;
                if (openingElem != null && openingElem.Id.IntegerValue != (int)rdb.BuiltInCategory.OST_SWallRectOpening)
                {
                    opening = openingElem as rdb.Opening;
                }

                if (!VerifyRect(polyCrv))
                {
                    if (opening != null)
                    {
                        TransactionManager.Instance.EnsureInTransaction(doc);
                        doc.Delete(opening.Id);
                        TransactionManager.Instance.TransactionTaskDone();
                    }
                    TaskDialog.Show("Test", "VerifyRect failed");
                    return(null);
                }

                // Find the two corner points.
                if (!GetRectCorners(polyCrv, out rdb.XYZ corner0, out rdb.XYZ corner1))
                {
                    if (opening != null)
                    {
                        TransactionManager.Instance.EnsureInTransaction(doc);
                        doc.Delete(opening.Id);
                        TransactionManager.Instance.TransactionTaskDone();
                    }
                    TaskDialog.Show("Test", "GetRectCorners failed");
                    return(null);
                }

                if (corner0 == null || corner1 == null)
                {
                    if (opening != null)
                    {
                        TransactionManager.Instance.EnsureInTransaction(doc);
                        doc.Delete(opening.Id);
                        TransactionManager.Instance.TransactionTaskDone();
                    }
                    TaskDialog.Show("Test", "one of the corners is null");
                    return(null);
                }

                TransactionManager.Instance.EnsureInTransaction(doc);
                // Purge the original element
                if (opening != null)
                {
                    doc.Delete(opening.Id);
                }

                // Build a new opening;
                try
                {
                    rdb.Wall    w        = wall.InternalElement as rdb.Wall;
                    rdb.Opening o        = doc.Create.NewOpening(w, corner0, corner1);
                    re.Element  rOpening = re.ElementWrapper.ToDSType(o, true) as re.Element;
                    TransactionManager.Instance.TransactionTaskDone();
                    ElementBinder.CleanupAndSetElementForTrace(doc, o);
                    return(rOpening);
                }
                catch (Exception ex)
                {
                    TransactionManager.Instance.TransactionTaskDone();
                    TaskDialog.Show("CreateError", ex.ToString());
                    ElementBinder.CleanupAndSetElementForTrace(doc, null);
                }
            }
            catch (Exception e)
            {
                Autodesk.Revit.UI.TaskDialog.Show("Test", "Error:\n" + e.ToString());
                throw;
            }
            return(null);
        }
예제 #20
0
        private static void AddHost(Autodesk.Revit.DB.Wall wall, FamilyInstance familyInstance, Dictionary <BuiltInCategory, FamilySymbol> dictionary_FamilySymbol)
        {
            if (wall == null || familyInstance == null)
            {
                return;
            }

            XYZ xYZ = null;

            if (familyInstance.Location is LocationPoint)
            {
                xYZ = ((LocationPoint)familyInstance.Location).Point;
            }
            else if (familyInstance.Location is LocationCurve)
            {
                xYZ = ((LocationCurve)familyInstance.Location).Curve.GetEndPoint(0);
            }

            if (xYZ == null)
            {
                return;
            }

            GeometryElement geometryElement = wall.get_Geometry(new Options());

            BoundingBoxXYZ boundingBoxXYZ = geometryElement.GetBoundingBox();

            if (xYZ.Z >= boundingBoxXYZ.Max.Z)
            {
                return;
            }

            if (xYZ.Z < boundingBoxXYZ.Min.Z)
            {
                return;
            }

            FamilySymbol familySymbol = null;

            if (!dictionary_FamilySymbol.TryGetValue((BuiltInCategory)familyInstance.Category.Id.IntegerValue, out familySymbol))
            {
                return;
            }

            if (familySymbol == null)
            {
                return;
            }

            if (!familySymbol.IsActive)
            {
                familySymbol.Activate();
            }

            FamilyInstance familyInstance_Temp = wall.Document.Create.NewFamilyInstance(xYZ, familySymbol, wall, wall.Document.GetElement(wall.LevelId) as Level, Autodesk.Revit.DB.Structure.StructuralType.NonStructural);

            if (familyInstance_Temp.FacingFlipped != familyInstance.FacingFlipped)
            {
                familyInstance_Temp.flipFacing();
            }

            if (familyInstance_Temp.HandFlipped != familyInstance.HandFlipped)
            {
                familyInstance_Temp.flipHand();
            }

            FamilySymbol aFamilySymbol_Source = familyInstance.Symbol;

            Copy(familyInstance_Temp, familyInstance, "SAM_BuildingElementHeight", "Height");
            Copy(familyInstance_Temp, familyInstance, "SAM_BuildingElementWidth", "Width");
            Copy(familyInstance_Temp, familyInstance, "SAM_BuildingElementFrameWidth", "FrameThickness");
            Copy(familyInstance_Temp, familyInstance, "Sill Height", "Sill Height");
            Copy(familyInstance_Temp, familyInstance, "_Filter Comments 01", "Mark");
            Copy(familyInstance_Temp, familyInstance, "_Filter Comments 03", "Description");

            Parameter parameter;

            parameter = familyInstance_Temp.get_Parameter(BuiltInParameter.ALL_MODEL_INSTANCE_COMMENTS);
            if (parameter != null)
            {
                parameter.Set(familyInstance.Id.IntegerValue.ToString());
            }

            parameter = familyInstance_Temp.LookupParameter("SAM_BuildingElementDescription");
            if (parameter != null)
            {
                parameter.Set(familyInstance.Name);
            }
        }
예제 #21
0
        public void init()
        {
            SetDoorOffsetForm form   = new SetDoorOffsetForm();
            DialogResult      result = form.ShowDialog();

            if (result == DialogResult.OK)
            {
                offsetValue = form.getOffset();
            }


            List <Tuple <Autodesk.Revit.DB.FamilyInstance, Autodesk.Revit.DB.Wall> > selectedDoorsAndWalls = new List <Tuple <FamilyInstance, Wall> >();

            try
            {
                while (true)
                {
                    Autodesk.Revit.DB.FamilyInstance selectedDoor = null;
                    Autodesk.Revit.DB.Wall           selectedWall = null;

                    while (selectedDoor == null)
                    {
                        Reference selectedReference = uidoc.Selection.PickObject(ObjectType.Element, "Select doors in order to set offset. Press ESC key when finished.");
                        if (selectedReference != null)
                        {
                            ElementId selectedElementId = selectedReference.ElementId;
                            if (selectedElementId != null)
                            {
                                Element selectedElement = this.doc.GetElement(selectedElementId);
                                if (selectedElement != null)
                                {
                                    if (selectedElement.Category.Name == "Doors")
                                    {
                                        if (selectedElement is FamilyInstance)
                                        {
                                            selectedDoor = selectedElement as FamilyInstance;
                                        }
                                    }
                                    else
                                    {
                                        TaskDialog.Show("Info", "Your selection is not a door, it will not be counted.");
                                    }
                                }
                            }
                        }
                    }

                    while (selectedWall == null)
                    {
                        Reference selectedReference = uidoc.Selection.PickObject(ObjectType.Element, "Select a wall in order to set offset. Press ESC key when finished.");
                        if (selectedReference != null)
                        {
                            ElementId selectedElementId = selectedReference.ElementId;
                            if (selectedElementId != null)
                            {
                                Element selectedElement = this.doc.GetElement(selectedElementId);
                                if (selectedElement != null)
                                {
                                    if (selectedElement is Wall)
                                    {
                                        selectedWall = selectedElement as Wall;
                                    }
                                    else
                                    {
                                        TaskDialog.Show("Info", "Your selection is not a wall it will not be counted.");
                                    }
                                }
                            }
                        }
                    }


                    if ((selectedDoor != null) && (selectedWall != null))
                    {
                        selectedDoorsAndWalls.Add(new Tuple <FamilyInstance, Wall>(selectedDoor, selectedWall));
                    }
                }
            }
            catch (Exception ex)
            {
            }

            if (selectedDoorsAndWalls.Count > 0)
            {
                SetDoorOffsetHandler handler = new SetDoorOffsetHandler(selectedDoorsAndWalls, this.offsetValue);
                ExternalEvent        exEvent = ExternalEvent.Create(handler);
                exEvent.Raise();
            }
        }