Example #1
0
        public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
        {
            UIDocument uidoc            = commandData.Application.ActiveUIDocument;
            Document   doc              = uidoc.Document;
            ICollection <ElementId> ids = uidoc.Selection.GetElementIds();

            foreach (ElementId eid in ids)
            {
                Element         elem  = doc.GetElement(eid);
                CeilingAndFloor slab  = elem as CeilingAndFloor;
                Floor           floor = elem as Floor;
                if (slab != null)
                {
                    MessageBox.Show("slab is ceiling and floor!");
                }
                if (floor != null)
                {
                    StringBuilder sb = new StringBuilder();
                    MessageBox.Show("slab is floor!");
                    SlabShapeEditor      sbe     = floor.SlabShapeEditor;
                    SlabShapeVertexArray sbArray = sbe.SlabShapeVertices;
                    foreach (SlabShapeVertex vertex in sbArray)
                    {
                        sb.AppendLine(vertex.Position.ToString());
                    }

                    MessageBox.Show(sb.ToString());
                }
            }
            return(Result.Succeeded);
        }
Example #2
0
        Stream(ArrayList data, SlabShapeEditor slabEditor)
        {
            data.Add(new Snoop.Data.ClassSeparator(typeof(SlabShapeEditor)));

            data.Add(new Snoop.Data.Bool("Is enabled", slabEditor.IsEnabled));
            data.Add(new Snoop.Data.Enumerable("Slab shape creases", slabEditor.SlabShapeCreases));
            data.Add(new Snoop.Data.Enumerable("Slab shape vertices", slabEditor.SlabShapeVertices));
        }
        Stream(ArrayList data, SlabShapeEditor slabEditor)
        {
            data.Add(new Snoop.Data.ClassSeparator(typeof(SlabShapeEditor)));

            data.Add(new Snoop.Data.Bool("Is enabled", slabEditor.IsEnabled));
            data.Add(new Snoop.Data.Enumerable("Slab shape creases", slabEditor.SlabShapeCreases));
            data.Add(new Snoop.Data.Enumerable("Slab shape vertices", slabEditor.SlabShapeVertices));
        }
Example #4
0
        const string selectFirst = "Please select a Vertex (or Crease) first!"; //error message

        /// <summary>
        /// constructor
        /// </summary>
        /// <param name="commandData">selected floor (or slab)</param>
        /// <param name="commandData">contains reference of Revit Application</param>
        public SlabShapeEditingForm(Floor floor, ExternalCommandData commandData)
        {
            InitializeComponent();
            m_commandData     = commandData;
            m_slabProfile     = new SlabProfile(floor, commandData);
            m_slabShapeEditor = floor.SlabShapeEditor;
            m_lineTool        = new LineTool();
            m_pointTool       = new LineTool();
            editorState       = EditorState.AddVertex;
            m_graphicsPaths   = new ArrayList();
            m_createdVertices = new ArrayList();
            m_createCreases   = new ArrayList();
            m_selectIndex     = -1;
            m_clickedIndex    = -1;
            m_toolPen         = new Pen(System.Drawing.Color.Blue, 2);
            m_selectPen       = new Pen(System.Drawing.Color.Red, 2);
            m_profilePen      = new Pen(System.Drawing.Color.Black, (float)(0.5));
        }
Example #5
0
        CollectEvent(object sender, CollectorEventArgs e)
        {
            // cast the sender object to the SnoopCollector we are expecting
            Collector snoopCollector = sender as Collector;

            if (snoopCollector == null)
            {
                Debug.Assert(false);    // why did someone else send us the message?
                return;
            }

            // see if it is a type we are responsible for
            SlabShapeCrease slabCrease = e.ObjToSnoop as SlabShapeCrease;

            if (slabCrease != null)
            {
                Stream(snoopCollector.Data(), slabCrease);
                return;
            }

            SlabShapeEditor slabEditor = e.ObjToSnoop as SlabShapeEditor;

            if (slabEditor != null)
            {
                Stream(snoopCollector.Data(), slabEditor);
                return;
            }

            SlabShapeVertex slabVertex = e.ObjToSnoop as SlabShapeVertex;

            if (slabVertex != null)
            {
                Stream(snoopCollector.Data(), slabVertex);
                return;
            }
        }
Example #6
0
        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);
        }
Example #7
0
        Pen m_toolPen; //pen use to draw new created vertex and crease

        #endregion Fields

        #region Constructors

        /// <summary>
        /// constructor
        /// </summary>
        /// <param name="commandData">selected floor (or slab)</param>
        /// <param name="commandData">contains reference of Revit Application</param>
        public SlabShapeEditingForm(Floor floor, ExternalCommandData commandData)
        {
            InitializeComponent();
            m_commandData = commandData;
            m_slabProfile = new SlabProfile(floor, commandData);
            m_slabShapeEditor = floor.SlabShapeEditor;
            m_lineTool = new LineTool();
            m_pointTool = new LineTool();
            editorState = EditorState.AddVertex;
            m_graphicsPaths = new ArrayList();
            m_createdVertices = new ArrayList();
            m_createCreases = new ArrayList();
            m_selectIndex = -1;
            m_clickedIndex = -1;
            m_toolPen = new Pen(System.Drawing.Color.Blue, 2);
            m_selectPen = new Pen(System.Drawing.Color.Red, 2);
            m_profilePen = new Pen(System.Drawing.Color.Black, (float)(0.5));
        }
Example #8
0
        /***************************************************/
        /****              Public methods               ****/
        /***************************************************/

        public static RoofBase ToRevitRoofBase(this oM.Physical.Elements.Roof roof, Document document, RevitSettings settings = null, Dictionary <Guid, List <int> > refObjects = null)
        {
            if (roof == null || roof.Location == null || document == null)
            {
                return(null);
            }

            PlanarSurface planarSurface = roof.Location as PlanarSurface;

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

            RoofBase roofBase = refObjects.GetValue <RoofBase>(document, roof.BHoM_Guid);

            if (roofBase != null)
            {
                return(roofBase);
            }

            settings = settings.DefaultIfNull();

            RoofType roofType = roof.Construction?.ToRevitElementType(document, new List <BuiltInCategory> {
                BuiltInCategory.OST_Roofs
            }, settings, refObjects) as RoofType;

            if (roofType == null)
            {
                roofType = roof.ElementType(document, settings);
            }

            if (roofType == null)
            {
                Compute.ElementTypeNotFoundWarning(roof);
                return(null);
            }

            Level level = document.LevelBelow(roof.Location, settings);

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

            double elevation = level.Elevation.ToSI(UnitType.UT_Length);

            oM.Geometry.Plane plane = BH.Engine.Geometry.Create.Plane(BH.Engine.Geometry.Create.Point(0, 0, elevation), BH.Engine.Geometry.Create.Vector(0, 0, 1));

            ICurve     curve      = planarSurface.ExternalBoundary.IProject(plane);
            CurveArray curveArray = Create.CurveArray(curve.IToRevitCurves());

            ModelCurveArray modelCurveArray = new ModelCurveArray();

            roofBase = document.Create.NewFootPrintRoof(curveArray, level, roofType, out modelCurveArray);

            if (roofBase != null)
            {
                Parameter parameter = roofBase.get_Parameter(BuiltInParameter.ROOF_UPTO_LEVEL_PARAM);
                if (parameter != null)
                {
                    parameter.Set(ElementId.InvalidElementId);
                }

                List <oM.Geometry.Point> controlPoints = planarSurface.ExternalBoundary.IControlPoints();

                if (controlPoints != null && controlPoints.Count > 2)
                {
                    SlabShapeEditor slabShapeEditor = roofBase.SlabShapeEditor;
                    slabShapeEditor.ResetSlabShape();

                    foreach (oM.Geometry.Point point in controlPoints)
                    {
                        if (Math.Abs(point.Z - plane.Origin.Z) > settings.DistanceTolerance)
                        {
                            XYZ xyz = point.ToRevit();
                            slabShapeEditor.DrawPoint(xyz);
                        }
                    }
                }
            }

            roofBase.CheckIfNullPush(roof);
            if (roofBase == null)
            {
                return(null);
            }

            // Copy parameters from BHoM object to Revit element
            roofBase.CopyParameters(roof, settings);

            // Update the offset in case the level had been overwritten.
            double offset = 0;

            if (roofBase.LevelId.IntegerValue != level.Id.IntegerValue)
            {
                Level newLevel = document.GetElement(roofBase.LevelId) as Level;
                offset += (level.ProjectElevation - newLevel.ProjectElevation).ToSI(UnitType.UT_Length);
            }

            roofBase.SetParameter(BuiltInParameter.ROOF_LEVEL_OFFSET_PARAM, offset);

            refObjects.AddOrReplace(roof, roofBase);
            return(roofBase);
        }
Example #9
-1
        Matrix4 m_transformMatrix = null; // store the Matrix used to transform Revit coordinate to window UI

        #endregion Fields

        #region Constructors

        /// <summary>
        /// constructor
        /// </summary>
        /// <param name="floor">Floor object in Revit</param>
        /// <param name="commandData">contains reference of Revit Application</param>
        public SlabProfile(Autodesk.Revit.DB.Floor floor, ExternalCommandData commandData)
        {
            m_floor = floor;
            m_commandData = commandData;
            m_slabShapeEditor = floor.SlabShapeEditor;
            GetSlabProfileInfo();
        }
Example #10
-1
        double m_rotateAngleY = 0;               //rotate angle in Y direction

        #endregion

        /// <summary>
        /// constructor
        /// </summary>
        /// <param name="floor">Floor object in Revit</param>
        /// <param name="commandData">contains reference of Revit Application</param>
        public SlabProfile(Autodesk.Revit.DB.Floor floor, ExternalCommandData commandData)
        {
            m_floor           = floor;
            m_commandData     = commandData;
            m_slabShapeEditor = floor.SlabShapeEditor;
            GetSlabProfileInfo();
        }