Esempio n. 1
0
        public Result Execute(
            ExternalCommandData commandData,
            ref string message,
            ElementSet elements)
        {
            UIApplication uiapp = commandData.Application;
            UIDocument    uidoc = uiapp.ActiveUIDocument;
            Application   app   = uiapp.Application;
            Document      doc   = uidoc.Document;

            Room   room = null;
            Result rc   = GetRoom(uidoc, out room);

            SpatialElementBoundaryOptions opt
                = new SpatialElementBoundaryOptions();

            opt.SpatialElementBoundaryLocation =
                SpatialElementBoundaryLocation.Center; // loops closed

            //SpatialElementBoundaryLocation.Finish; // loops not closed

            IList <IList <BoundarySegment> > loops
                = room.GetBoundarySegments(opt);

            int nLoops = loops.Count;

            BoundingBoxXYZ bb = room.get_BoundingBox(null);

            string path_data = GetSvgPathFrom(bb, loops[0]);

            DisplaySvg(path_data);

            return(Result.Succeeded);
        }
Esempio n. 2
0
        private RoomInfo Getinfo_Room(Document document, Room room)
        {
            if (room != null)

            {
                var info = new RoomInfo();
                info.Room       = room;
                info.RoomName   = room.Name;
                info.RoomLevel  = room.Level.Name;
                info.RoomNumber = room.Number;

                if (room.Location is LocationPoint location)
                {
                    XYZ point = location.Point;
                    info.RoomLocation = point;
                }

                #region GetHeight
                SpatialElementBoundaryOptions sebOptions = new SpatialElementBoundaryOptions
                {
                    SpatialElementBoundaryLocation = SpatialElementBoundaryLocation.Finish
                };
                SpatialElementGeometryCalculator calc    = new SpatialElementGeometryCalculator(document, sebOptions);
                SpatialElementGeometryResults    results = calc.CalculateSpatialElementGeometry(room);
                Solid roomSolid = results.GetGeometry();
                var   getbb     = roomSolid.GetBoundingBox();
                var   maxZ      = getbb.Max.Z;
                var   minZ      = getbb.Min.Z;
                info.RoomHeight = maxZ - minZ;
                #endregion

                IList <IList <BoundarySegment> > segments = room.GetBoundarySegments(new SpatialElementBoundaryOptions());

                if (null != segments)
                {
                    foreach (IList <BoundarySegment> segmentList in segments)
                    {
                        foreach (BoundarySegment boundarySegment in segmentList)
                        {
                            if (boundarySegment.GetCurve() is Line)
                            {
                                info.RoomBoundarySegment.Add(new RoomInfo
                                {
                                    RoomStartPoint = boundarySegment.GetCurve().GetEndPoint(0),
                                    RoomEndPoint   = boundarySegment.GetCurve().GetEndPoint(1)
                                });
                            }
                            if (boundarySegment.GetCurve() is Arc)
                            {
                                TaskDialog.Show("s", boundarySegment.GetCurve().GetType().ToString());
                            }
                        }
                    }
                }

                return(info);
            }

            return(null);
        }
Esempio n. 3
0
        /// <summary>
        ///     Gets the room's edge list.
        /// </summary>
        /// <param name="room"></param>
        /// <param name="boundary"></param>
        /// <returns></returns>
        public static List <Line> GetEdgeList(this SpatialElement room, SpatialElementBoundaryLocation boundary)
        {
            if (room == null)
            {
                throw new ArgumentNullException(nameof(room));
            }

            var result = new List <Line>();
            var opt    = new SpatialElementBoundaryOptions
            {
                StoreFreeBoundaryFaces         = true,
                SpatialElementBoundaryLocation = boundary
            };
            var segments = room.GetBoundarySegments(opt).SelectMany(s => s);

            foreach (var seg in segments)
            {
                var sp = seg.GetCurve().GetEndPoint(0);
                var ep = seg.GetCurve().GetEndPoint(1);

                result.Add(Line.CreateBound(sp, ep));
            }

            return(result);
        }
Esempio n. 4
0
    public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
    {
        //get application and document objects
        UIApplication uiApp = commandData.Application;
        Document      doc   = uiApp.ActiveUIDocument.Document;

        //define reference
        Reference pickedRef = null;

        ////pick
        Selection sel = uiApp.ActiveUIDocument.Selection;
        //pickedRef = sel.PickObject(ObjectType.Element, "select an element");
        //Element elem = doc.GetElement(pickedRef);
        //Group group = elem as Group;

        //pick a point
        XYZ  point = sel.PickPoint("pick a point inside a room");
        Room room  = doc.GetRoomAtPoint(point);
        SpatialElementBoundaryOptions    options    = new SpatialElementBoundaryOptions();
        IList <IList <BoundarySegment> > boundaries = room.GetBoundarySegments(options);

        //boundary[room][boundary].curve
        //boundary[room][boundary].element
        TaskDialog.Show("title", "room picked");

        //transaction
        Transaction trans = new Transaction(doc);

        trans.Start("macro");

        trans.Commit();

        return(Result.Succeeded);
    }
Esempio n. 5
0
        private void NewMethod(FloorType floorType, CurveArray curves, Level level1)
        {
            RoomFilter filter = new RoomFilter();

            FilteredElementCollector collector = new FilteredElementCollector(_doc);
            IList <Element>          rooms     = collector.WherePasses(filter).ToElements();

            int n = rooms.Count();

            foreach (Room room in rooms)
            {
                IList <IList <BoundarySegment> > segments = room.GetBoundarySegments(new SpatialElementBoundaryOptions());

                CurveArray roomsCurves = new CurveArray(); // Array to hold curv data collected from room boundreis
                roomsCurves.Clear();

                SpatialElementBoundaryOptions bo = new SpatialElementBoundaryOptions();
                SketchPlane sp = _doc.ActiveView.SketchPlane;

                foreach (IList <BoundarySegment> lstBs in room.GetBoundarySegments(bo))
                {
                    foreach (BoundarySegment bs in lstBs)
                    {
                        roomsCurves.Append(bs.GetCurve());
                    }
                }
                _doc.Create.NewFloor(roomsCurves, floorType, level1, false);
            }

            //_doc.Create.NewFloor(curves, floorType, level1, true);
        }
Esempio n. 6
0
        public static List <List <RoomEdge> > GetRoomEdges(Document doc, SpatialElement room)
        {
            //Extract the boundary curves for a room based on the center of the enclosing element
            SpatialElementBoundaryOptions opt = new SpatialElementBoundaryOptions();

            opt.SpatialElementBoundaryLocation = SpatialElementBoundaryLocation.Center;
            IList <IList <BoundarySegment> > boundarySegments = room.GetBoundarySegments(opt);
            List <List <RoomEdge> >          allRoomEdges     = new List <List <RoomEdge> >();

            foreach (List <BoundarySegment> l1 in boundarySegments)
            {
                List <RoomEdge> roomEdges = new List <RoomEdge>();
                foreach (BoundarySegment l2 in l1)
                {
                    RoomEdge roomEdge = new RoomEdge()
                    {
                        _Edge       = l2.GetCurve(),
                        _StartPoint = l2.GetCurve().GetEndPoint(0),
                    };
                    roomEdges.Add(roomEdge);
                }
                allRoomEdges.Add(roomEdges);
            }

            return(allRoomEdges);
        }
        /// <summary>
        /// Distinguish 'Not Placed',  'Redundant'
        /// and 'Not Enclosed' rooms.
        /// </summary>
        RoomState DistinguishRoom(Room room)
        {
            RoomState res = RoomState.Unknown;

            if (room.Area > 0)
            {
                // Placed if having Area

                res = RoomState.Placed;
            }
            else if (null == room.Location)
            {
                // No Area and No Location => Unplaced

                res = RoomState.NotPlaced;
            }
            else
            {
                // must be Redundant or NotEnclosed

                SpatialElementBoundaryOptions opt
                    = new SpatialElementBoundaryOptions();

                IList <IList <BoundarySegment> > segs
                    = room.GetBoundarySegments(opt);

                res = (null == segs || segs.Count == 0)
          ? RoomState.NotEnclosed
          : RoomState.Redundant;
            }
            return(res);
        }
Esempio n. 8
0
        public static List <XYZ> GetPolygon(Room room, Document doc)
        {
            var vertices = new List <XYZ>();
            SpatialElementBoundaryOptions options = new SpatialElementBoundaryOptions();

            options.SpatialElementBoundaryLocation = SpatialElementBoundaryLocation.Center;
            IList <IList <BoundarySegment> > segments = room.GetBoundarySegments(options);

            foreach (IList <BoundarySegment> list in segments)
            {
                foreach (BoundarySegment bs in list)
                {
                    var revitWall = doc.GetElement(bs.ElementId) as Wall;
                    if (revitWall == null)
                    {
                        continue;                    // ignore non-walls here
                    }
                    var X = bs.GetCurve().GetEndPoint(0).X;
                    var Y = bs.GetCurve().GetEndPoint(0).Y;

                    vertices.Add(new XYZ(X, Y, 0));
                }
            }
            return(vertices);
        }
Esempio n. 9
0
        /// <summary>
        /// List some properties of a given room to the
        /// Visual Studio debug output window.
        /// </summary>
        void ListRoomData(Room room)
        {
            SpatialElementBoundaryOptions opt
                = new SpatialElementBoundaryOptions();

            string nr   = room.Number;
            string name = room.Name;
            double area = room.Area;

            Location      loc = room.Location;
            LocationPoint lp  = loc as LocationPoint;
            XYZ           p   = (null == lp) ? XYZ.Zero : lp.Point;

            BoundingBoxXYZ bb = room.get_BoundingBox(null);

            IList <IList <BoundarySegment> > boundary
                = room.GetBoundarySegments(opt);

            int nLoops = boundary.Count;

            int nFirstLoopSegments = 0 < nLoops
        ? boundary[0].Count
        : 0;

            Debug.Print(string.Format(
                            "Room nr. '{0}' named '{1}' at {2} with "
                            + "bounding box {3} and area {4} sqf has "
                            + "{5} loop{6} and {7} segment{8} in first "
                            + "loop.",
                            nr, name, Util.PointString(p),
                            BoundingBoxString2(bb), area, nLoops,
                            Util.PluralSuffix(nLoops), nFirstLoopSegments,
                            Util.PluralSuffix(nFirstLoopSegments)));
        }
Esempio n. 10
0
        private List <string> getVertexPoints(Space roomSpace)
        {
            List <string> verticies            = new List <string>();
            SpatialElementBoundaryOptions opts = new SpatialElementBoundaryOptions();
            IList <IList <Autodesk.Revit.DB.BoundarySegment> > bsa = roomSpace.GetBoundarySegments(opts);

            if (bsa.Count > 0)
            {
                foreach (Autodesk.Revit.DB.BoundarySegment bs in bsa[0])
                {
                    // For 2014
                    //var X = bs.Curve.get_EndPoint(0).X * meterMultiplier;
                    //var Y = bs.Curve.get_EndPoint(0).Y * meterMultiplier;
                    var X = bs.Curve.GetEndPoint(0).X *meterMultiplier;
                    var Y = bs.Curve.GetEndPoint(0).Y *meterMultiplier;

                    verticies.Add(X.ToDecimalString() + " " + Y.ToDecimalString());
                }
            }
            else
            {
                verticies.Add("0 0");
            }
            return(verticies);
        }
Esempio n. 11
0
        public static List <Wall> GetWallsInRoom(Room room)
        {
            SpatialElementBoundaryOptions options = new SpatialElementBoundaryOptions();

            options.SpatialElementBoundaryLocation = SpatialElementBoundaryLocation.Finish;
            List <Wall> result = new List <Wall>();

            foreach (IList <BoundarySegment> boundSegList in room.GetBoundarySegments(options))
            {
                foreach (BoundarySegment boundSeg in boundSegList)
                {
                    ElementId elem = boundSeg.ElementId;
                    Document  doc  = room.Document;
                    Element   e    = doc.GetElement(elem);
                    Wall      wall = e as Wall;
                    try
                    {
                        LocationCurve locationCurve = wall?.Location as LocationCurve;
                        Curve         curve         = locationCurve?.Curve;
                        result.Add((Wall)e);
                    }
                    catch (Exception exception)
                    {
                        TaskDialog.Show("Revit Exception", "Неверно создана комната или стена");
                        throw;
                    }
                }
            }

            return(result);
        }
Esempio n. 12
0
        /// <summary>
        /// Retrieve the room plan view boundary
        /// polygon loops and convert to 2D integer-based.
        /// For optimisation and consistency reasons,
        /// convert all coordinates to integer values in
        /// millimetres. Revit precision is limited to
        /// 1/16 of an inch, which is abaut 1.2 mm, anyway.
        /// </summary>
        static JtLoops GetRoomLoops(Room room)
        {
            SpatialElementBoundaryOptions opt
                = new SpatialElementBoundaryOptions();

            opt.SpatialElementBoundaryLocation =
                SpatialElementBoundaryLocation.Center; // loops closed
            //SpatialElementBoundaryLocation.Finish; // loops not closed

            IList <IList <BoundarySegment> > loops = room.
                                                     GetBoundarySegments(opt);

            int nLoops = loops.Count;

            JtLoops jtloops = new JtLoops(nLoops);

            foreach (IList <BoundarySegment> loop in loops)
            {
                int nSegments = loop.Count;

                JtLoop jtloop = new JtLoop(nSegments);

                XYZ p0 = null; // loop start point
                XYZ p;         // segment start point
                XYZ q = null;  // segment end point

                foreach (BoundarySegment seg in loop)
                {
                    // Todo: handle non-linear curve.
                    // Especially: if two long lines have a
                    // short arc in between them, skip the arc
                    // and extend both lines.

                    p = seg.Curve.GetEndPoint(0);

                    jtloop.Add(new Point2dInt(p));

                    Debug.Assert(null == q || q.IsAlmostEqualTo(p),
                                 "expected last endpoint to equal current start point");

                    q = seg.Curve.GetEndPoint(1);

                    if (_debug_output)
                    {
                        Debug.Print("{0} --> {1}",
                                    Util.PointString(p),
                                    Util.PointString(q));
                    }
                    if (null == p0)
                    {
                        p0 = p; // save loop start point
                    }
                }
                Debug.Assert(q.IsAlmostEqualTo(p0),
                             "expected last endpoint to equal loop start point");

                jtloops.Add(jtloop);
            }
            return(jtloops);
        }
Esempio n. 13
0
        /// <summary>
        ///     Gets intersect element list.
        /// </summary>
        /// <param name="room"></param>
        /// <param name="doc"></param>
        /// <returns></returns>
        public static List <Element> GetIntersectElements(this SpatialElement room, Document doc)
        {
            if (room is null)
            {
                throw new ArgumentNullException(nameof(room));
            }

            if (doc is null)
            {
                throw new ArgumentNullException(nameof(doc));
            }

            var opt = new SpatialElementBoundaryOptions  {
                SpatialElementBoundaryLocation = Center
            };

            var calc = new SpatialElementGeometryCalculator(doc, opt);

            var solid = calc.CalculateSpatialElementGeometry(room).GetGeometry();

            var instFilter = new FilteredElementCollector(doc).WhereElementIsNotElementType();

            var itstFilter = new ElementIntersectsSolidFilter(solid);

            return(instFilter.WherePasses(itstFilter).ToList());
        }
Esempio n. 14
0
        private List <ConnectionNode> getRoomSeparations(List <Room> rooms, Dictionary <ElementId, RoomWithTransitLines> transitRooms)
        {
            List <ConnectionNode>         nodes   = new List <ConnectionNode>();
            SpatialElementBoundaryOptions options = new SpatialElementBoundaryOptions()
            {
                SpatialElementBoundaryLocation = SpatialElementBoundaryLocation.Center
            };
            Dictionary <ElementId, ElementId> separationRooms = new Dictionary <ElementId, ElementId>();

            foreach (Room room in rooms)
            {
                if (room.Area <= 0)
                {
                    continue;
                }

                addRoomSepLineFromBoundary(room, nodes, options);
            }
            foreach (var pair in transitRooms)
            {
                // we also need to capture these...
                Room r = _doc.GetElement(pair.Key) as Room;
                addRoomSepLineFromBoundary(r, nodes, options);
            }

            return(nodes);
        }
Esempio n. 15
0
        public CurveLoop GetRoomFinishBoundarySolid()
        {
            List <CurveLoop> boundarySegmentCurveLoopList = new List <CurveLoop>();

            SpatialElementBoundaryOptions options = new SpatialElementBoundaryOptions();

            options.SpatialElementBoundaryLocation = SpatialElementBoundaryLocation.Finish;

            IList <IList <BoundarySegment> > roomBoundarySegmentsListList = m_room.GetBoundarySegments(options);

            foreach (IList <BoundarySegment> boundarySegmentsList in roomBoundarySegmentsListList)
            {
                IList <Curve> boundarySegmentCurveList = new List <Curve>();

                foreach (BoundarySegment boundarySegment in boundarySegmentsList)
                {
                    boundarySegmentCurveList.Add(boundarySegment.GetCurve());
                }

                CurveLoop boundarySegmentCurveLoop = CurveLoop.Create(boundarySegmentCurveList);

                boundarySegmentCurveLoopList.Add(boundarySegmentCurveLoop);
            }

            boundarySegmentCurveLoopList.Sort((a, b) => (int)a.GetExactLength() - (int)b.GetExactLength());
            CurveLoop roomFinishBoundary = boundarySegmentCurveLoopList[boundarySegmentCurveLoopList.Count - 1];

            return(roomFinishBoundary);
        }
Esempio n. 16
0
        private static void GetstructuralWallArea(Document doc, SpatialElement spElem, out double wallArea)
        {
            SpatialElementBoundaryOptions boundaryOptions =
                new SpatialElementBoundaryOptions
            {
                SpatialElementBoundaryLocation = SpatialElementBoundaryLocation.Center
            };

            IList <IList <BoundarySegment> > bndSegmentsList =
                spElem.GetBoundarySegments(boundaryOptions);

            wallArea = 0;
            for (int i = 0; i < bndSegmentsList.Count; ++i)
            {
                for (int j = 0; j < bndSegmentsList[i].Count; ++j)
                {
                    Element boundaryElem = doc.GetElement(bndSegmentsList[i][j].ElementId);
                    if (boundaryElem is Wall &&
                        ((Wall)boundaryElem).get_Parameter(BuiltInParameter.WALL_STRUCTURAL_SIGNIFICANT).AsInteger() == 1)
                    {
                        Wall strWall = (Wall)boundaryElem;
                        wallArea += (strWall.WallType.Width / 2) *
                                    (bndSegmentsList[i][j].GetCurve().Length);
                    }
                }
            }
        }
Esempio n. 17
0
        public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
        {
            UIApplication uiapp               = commandData.Application;
            UIDocument    uidoc               = uiapp.ActiveUIDocument;
            Document      doc                 = uidoc.Document;
            Selection     selection           = uidoc.Selection;
            CurveArray    curveArray          = new CurveArray();
            Reference     reff                = selection.PickObject(ObjectType.Element, "please select a room");
            Room          room                = doc.GetElement(reff) as Room;
            SpatialElementBoundaryOptions opt = new SpatialElementBoundaryOptions();

            opt.SpatialElementBoundaryLocation = SpatialElementBoundaryLocation.Finish;
            IList <IList <BoundarySegment> > loops = room.GetBoundarySegments(opt);

            foreach (IList <BoundarySegment> bs1 in loops)
            {
                foreach (BoundarySegment bs2 in bs1)
                {
                    Curve curve = bs2.GetCurve();
                    //TaskDialog.Show("1", "2");
                    curveArray.Append(curve);
                }
            }
            using (Transaction ts = new Transaction(doc, "Create Floor"))
            {
                ts.Start();
                doc.Create.NewFloor(curveArray, false);
                ts.Commit();
            }
            return(Result.Succeeded);
        }
Esempio n. 18
0
        //public void GetBoundingBox(Room newRoom, View view)
        //{
        //    BoundingBoxXYZ box = newRoom.get_BoundingBox(view);
        //    WpfCoordinates center = new WpfCoordinates();

        //    center.X = (int)(box.Min.X - box.Max.X) / 2;
        //    center.Y = (int)(box.Min.Y - box.Max.Y) / 2;

        //    ConversionPoint roomMin = new ConversionPoint(box.Min);
        //    ConversionPoint roomMax = new ConversionPoint(box.Max);
        //}


        public List <System.Windows.Shapes.Line> GetWalls(Room room)
        {
            SpatialElementBoundaryOptions boundaryOption = new SpatialElementBoundaryOptions();

            boundaryOption.SpatialElementBoundaryLocation = SpatialElementBoundaryLocation.Center;

            IList <IList <BoundarySegment> >  boundary  = room.GetBoundarySegments(boundaryOption);
            List <System.Windows.Shapes.Line> wallCoord = new List <System.Windows.Shapes.Line>();

            foreach (IList <BoundarySegment> walls in boundary)
            {
                foreach (BoundarySegment segment in walls)
                {
                    System.Windows.Shapes.Line wall = new System.Windows.Shapes.Line();

                    var segmentStart = segment.GetCurve().GetEndPoint(0);

                    //wall.X1 = Convert.ToInt32(segmentStart.X * 25.4 * 12);
                    //wall.Y1 = Convert.ToInt32(segmentStart.Y * 25.4 * 12);
                    wall.X1 = (segmentStart.X * 25.4 * 12);
                    wall.Y1 = (segmentStart.Y * 25.4 * 12);

                    var segmentEnd = segment.GetCurve().GetEndPoint(1);

                    //wall.X2 = Convert.ToInt32(segmentEnd.X * 25.4 * 12);
                    //wall.Y2 = Convert.ToInt32(segmentEnd.Y * 25.4 * 12);
                    wall.X2 = (segmentEnd.X * 25.4 * 12);
                    wall.Y2 = (segmentEnd.Y * 25.4 * 12);

                    wallCoord.Add(wall);
                }
            }
            return(wallCoord);
        }
Esempio n. 19
0
        GraphGenerator roomstuff(IList <Element> rooms, Document doc)
        {
            GraphGenerator gg = new GraphGenerator(doc);

            foreach (Element e in rooms)
            {
                Room room = e as Room;
                SpatialElementBoundaryOptions options = new SpatialElementBoundaryOptions();
                options.SpatialElementBoundaryLocation = SpatialElementBoundaryLocation.Center;
                IList <IList <BoundarySegment> > segments = room.GetBoundarySegments(options);
                foreach (IList <BoundarySegment> list in segments)
                {
                    foreach (BoundarySegment element in list)
                    {
                        Element    sep  = doc.GetElement(element.ElementId);
                        Categories cats = doc.Settings.Categories;
                        ElementId  rsp  = cats.get_Item(BuiltInCategory.OST_RoomSeparationLines).Id;
                        ElementId  door = cats.get_Item(BuiltInCategory.OST_Doors).Id;
                        if (sep.Category.Id.Equals(rsp) || sep.Category.Id.Equals(door))
                        {
                            BoundingBoxXYZ bb    = sep.get_BoundingBox(null);
                            XYZ            n     = bb.Max - bb.Min;
                            XYZ            nn    = new XYZ(n.Y, -n.X, n.Z).Normalize();
                            XYZ            exitp = floorCenter(bb);
                            gg.AddRoomExit(nn, exitp, new RoomData {
                                Number = room.Number, Area = room.Area, Position = floorCenter(room.get_BoundingBox(null)), Vertices = GetPolygon(room, doc), Original = room
                            });
                        }
                    }
                }
            }
            gg.Final();
            return(gg);
        }
Esempio n. 20
0
    /// <summary>
    /// Retrieve the room plan view boundary 
    /// polygon loops and convert to 2D integer-based.
    /// For optimisation and consistency reasons, 
    /// convert all coordinates to integer values in
    /// millimetres. Revit precision is limited to 
    /// 1/16 of an inch, which is abaut 1.2 mm, anyway.
    /// </summary>
    static JtLoops GetRoomLoops( Room room )
    {
      SpatialElementBoundaryOptions opt 
        = new SpatialElementBoundaryOptions();

      opt.SpatialElementBoundaryLocation =
        SpatialElementBoundaryLocation.Center; // loops closed
        //SpatialElementBoundaryLocation.Finish; // loops not closed

      IList<IList<BoundarySegment>> loops = room.
        GetBoundarySegments( opt );

      int nLoops = loops.Count;

      JtLoops jtloops = new JtLoops( nLoops );

      foreach( IList<BoundarySegment> loop in loops )
      {
        int nSegments = loop.Count;

        JtLoop jtloop = new JtLoop( nSegments );

        XYZ p0 = null; // loop start point
        XYZ p; // segment start point
        XYZ q = null; // segment end point

        foreach( BoundarySegment seg in loop )
        {
          // Todo: handle non-linear curve.
          // Especially: if two long lines have a 
          // short arc in between them, skip the arc
          // and extend both lines.

          p = seg.GetCurve().GetEndPoint( 0 );

          jtloop.Add( new Point2dInt( p ) );

          Debug.Assert( null == q || q.IsAlmostEqualTo( p ),
            "expected last endpoint to equal current start point" );

          q = seg.GetCurve().GetEndPoint( 1 );

          if( _debug_output )
          {
            Debug.Print( "{0} --> {1}",
              Util.PointString( p ),
              Util.PointString( q ) );
          }
          if( null == p0 )
          {
            p0 = p; // save loop start point
          }
        }
        Debug.Assert( q.IsAlmostEqualTo( p0 ),
          "expected last endpoint to equal loop start point" );

        jtloops.Add( jtloop );
      }
      return jtloops;
    }
Esempio n. 21
0
        private void updateGeometry(RoomObject ro, IList <RoomObject> allRooms, Phase roomPhase, Level refLevel)
        {
            // add all of the geometry info...

            Autodesk.Revit.DB.Architecture.Room r = ro.Document.GetElement(ro.Id) as Autodesk.Revit.DB.Architecture.Room;

            SpatialElementBoundaryOptions opts = new SpatialElementBoundaryOptions()
            {
                SpatialElementBoundaryLocation = SpatialElementBoundaryLocation.Center
            };

            var segmentList = r.GetBoundarySegments(opts);

            foreach (BoundarySegment roomSeg in segmentList[0])  // outermost segment only!
            {
                Segment seg = new Segment()
                {
                    Parent = ro, Element = roomSeg.ElementId
                };
                fetchSegmentElemInfo(ro, roomSeg, refLevel, seg);
                ro.Boundaries.Add(seg);
            }

            calculateOppositeRooms(ro, allRooms, refLevel, roomPhase);
        }
Esempio n. 22
0
        public List <Geometry2D> GetWallsOfRoomAsGeometry2D(UIDocument document, Room room)
        {
            List <Geometry2D>             allWalls = new List <Geometry2D>();
            SpatialElementBoundaryOptions option   = new SpatialElementBoundaryOptions();

            option.SpatialElementBoundaryLocation = SpatialElementBoundaryLocation.Finish;
            IList <IList <BoundarySegment> > boundariesList = room.GetBoundarySegments(option);
            string roomName         = room.Name;
            int    boundaryIterator = 0;

            foreach (IList <BoundarySegment> currentBoundary in boundariesList)
            {
                List <XYZ> boundaryVertices = GetBoundaryVertices(currentBoundary);

                if (boundaryVertices.ElementAt(0).IsAlmostEqualTo(boundaryVertices.ElementAt(boundaryVertices.Count - 1)))
                {
                    allWalls.Add(RoomBoundaryToPolygon2D(document, boundaryVertices, currentBoundary, roomName + boundaryIterator.ToString(), MEASUREMENTUNITFACTOR));
                }
                else
                {
                    allWalls.AddRange(RoomBoundaryToSegment2D(document, boundaryVertices, roomName + boundaryIterator.ToString(), MEASUREMENTUNITFACTOR));
                }

                boundaryIterator++;
            }

            return(allWalls);
        }
        /// <summary>
        /// 调整viewPlan的尺寸并贴合选中房间
        /// change a viewPlan to fix the selected room
        /// </summary>
        /// <param name="view"></param>
        /// <param name="tran"></param>
        /// <param name="viewOffseet"></param>
        public void ChangeViewFitRoom(ViewPlan view, Transaction tran, double viewOffseet)
        {
            if (view == null)
            {
                TaskDialog.Show("viewIsNull", "Can't find the type of View.");
                return;
            }

            //获得并设定房间的边界设定,并获取其边界集
            DocSet.uidoc.ActiveView = view;
            SpatialElementBoundaryOptions opt = new SpatialElementBoundaryOptions();

            opt.SpatialElementBoundaryLocation = SpatialElementBoundaryLocation.Center;//房间边界设定,能变更获取的边界位置
            IList <IList <BoundarySegment> > segments = DocSet.selRoom.GetBoundarySegments(opt);

            if (segments == null)
            {
                TaskDialog.Show("segementsIsNull", "can't get the BoundarySegment of room");
                return;
            }


            ViewCropRegionShapeManager vcrShanpMgr = view.GetCropRegionShapeManager();

            CurveLoop loop = new CurveLoop();

            foreach (IList <BoundarySegment> segmentList in segments)
            {
                foreach (BoundarySegment segment in segmentList)
                {
                    Curve curve = segment.GetCurve();
                    loop.Append(curve);
                }


                bool cropValid = vcrShanpMgr.IsCropRegionShapeValid(loop);
                if (cropValid)
                {
                    //默认矩形
                    //TaskDialog.Show("cropValid", "the crop is shape Valid");
                    tran.Start("change the view crop region");
                    vcrShanpMgr.SetCropShape(loop);
                    tran.Commit();
                    tran.Start("Remove Crop Region Shape");
                    vcrShanpMgr.RemoveCropRegionShape();
                    tran.Commit();
                    //TaskDialog.Show("ChangeView", "ChangeViewdone");
                    break;
                }
            }

            tran.Start("loop offset");
            //TaskDialog.Show("!!!", "changeloop!");
            loop = CurveLoop.CreateViaOffset(vcrShanpMgr.GetCropShape().First(), -1 * viewOffseet / 300, new XYZ(0, 0, 1));
            vcrShanpMgr.SetCropShape(loop);
            tran.Commit();

            DocSet.uidoc.ActiveView = view;
        }
Esempio n. 24
0
        public Result Execute(
            ExternalCommandData commandData,
            ref string message,
            ElementSet elements)
        {
            UIApplication uiapp = commandData.Application;
            UIDocument    uidoc = uiapp.ActiveUIDocument;
            Application   app   = uiapp.Application;
            Document      doc   = uidoc.Document;

            if (null == doc)
            {
                Util.ErrorMsg("Please run this command in a valid"
                              + " Revit project document.");
                return(Result.Failed);
            }

            IEnumerable <ElementId> ids
                = Util.GetSelectedRooms(uidoc);

            if ((null == ids) || (0 == ids.Count()))
            {
                return(Result.Cancelled);
            }

            View view = doc.ActiveView;

            SpatialElementBoundaryOptions seb_opt
                = new SpatialElementBoundaryOptions();

            Dictionary <int, JtLoops> booleanLoops
                = new Dictionary <int, JtLoops>(
                      ids.Count <ElementId>());

            foreach (ElementId id in ids)
            {
                Room room = doc.GetElement(id) as Room;

                JtLoops loops
                    = ClipperRvt.GetRoomOuterBoundaryLoops(
                          room, seb_opt, view);

                if (null == loops) // the room may not be bounded
                {
                    continue;
                }
                booleanLoops.Add(id.IntegerValue, loops);
            }

            JtWindowHandle hwnd = new JtWindowHandle(
                uiapp.MainWindowHandle);

            Util.CreateOutput("room_outer_outline",
                              "Room Outer Outline", doc, hwnd, booleanLoops);

            return(Result.Succeeded);
        }
Esempio n. 25
0
        /// <summary>
        /// 使用空间计算工具计算房间Solid
        /// </summary>
        /// <param name="room"></param>
        /// <returns></returns>
        /// <remarks>轮廓上没问题,在高度上可能会出错</remarks>
        public static Solid GetRoomSolid(this Room room)
        {
            var bndOpt = new SpatialElementBoundaryOptions();
            SpatialElementGeometryCalculator calculator = new SpatialElementGeometryCalculator(room.Document, bndOpt);
            SpatialElementGeometryResults    results    = calculator.CalculateSpatialElementGeometry(room); // compute the room geometry
            Solid roomSolid = results.GetGeometry();                                                        // get the solid representing the room's geometry

            return(roomSolid);
        }
Esempio n. 26
0
        private IList <IList <BoundarySegment> > GetRoomLoops(Room room)
        {
            SpatialElementBoundaryOptions opt = new SpatialElementBoundaryOptions
            {
                SpatialElementBoundaryLocation = SpatialElementBoundaryLocation.Center
            };

            return(room.GetBoundarySegments(opt));
        }
Esempio n. 27
0
        public void CreateFloors(Document document, FloorsFinishesSetup floorsFinishesSetup, Transaction tx)
        {
            tx.Start(Tools.LangResMan.GetString("floorFinishes_transactionName", Tools.Cult));

            foreach (Room room in floorsFinishesSetup.SelectedRooms)
            {
                if (room != null)
                {
                    if (room.UnboundedHeight != 0)
                    {
                        //Get all finish properties
                        double height;
                        if (floorsFinishesSetup.RoomParameter == null)
                        {
                            height = floorsFinishesSetup.FloorHeight;
                        }
                        else
                        {
                            Parameter roomParameter = room.get_Parameter(floorsFinishesSetup.RoomParameter.Definition);
                            height = roomParameter.AsDouble();
                        }

                        SpatialElementBoundaryOptions opt = new SpatialElementBoundaryOptions();


                        IList <IList <Autodesk.Revit.DB.BoundarySegment> > boundarySegments = room.GetBoundarySegments(opt);

                        CurveArray curveArray = new CurveArray();

                        if (boundarySegments.Count != 0)
                        {
                            foreach (Autodesk.Revit.DB.BoundarySegment boundSeg in boundarySegments.First())
                            {
                                curveArray.Append(boundSeg.GetCurve());
                            }


                            //Retrive room info
                            Level     rmLevel  = document.GetElement(room.LevelId) as Level;
                            Parameter param    = room.get_Parameter(BuiltInParameter.ROOM_HEIGHT);
                            double    rmHeight = param.AsDouble();

                            if (curveArray.Size != 0)
                            {
                                Floor floor = document.Create.NewFloor(curveArray, floorsFinishesSetup.SelectedFloorType, rmLevel, false);

                                //Change some param on the floor
                                param = floor.get_Parameter(BuiltInParameter.FLOOR_HEIGHTABOVELEVEL_PARAM);
                                param.Set(height);
                            }
                        }
                    }
                }
            }

            tx.Commit();
        }
Esempio n. 28
0
        public void CollectRooms()
        {
            try
            {
                foreach (var room in RoomElements)
                {
                    var rp = new RoomProperties();
                    rp.RoomObject = room;
                    rp.RoomId     = room.Id.IntegerValue;
                    rp.RoomName   = room.Name;
                    rp.RoomNumber = room.Number;
                    rp.SourceView = FindViewSource(room);

                    var locationPoint = room.Location as LocationPoint;
                    rp.RoomLocation = locationPoint.Point;

                    var roomSeparations   = new List <ModelCurve>();
                    var roomSeparationIds = new List <ElementId>();
                    var opt = new SpatialElementBoundaryOptions();
                    var boundaryListList = room.GetBoundarySegments(opt);
                    if (null != boundaryListList)
                    {
                        if (boundaryListList.Count > 0)
                        {
                            foreach (var boundaryList in boundaryListList)
                            {
                                foreach (var segment in boundaryList)
                                {
#if RELEASE2015
                                    var element = segment.Element;
#else
                                    var element = m_doc.GetElement(segment.ElementId);
#endif
                                    if (null != element)
                                    {
                                        if (element.Category.Id.IntegerValue == (int)BuiltInCategory.OST_RoomSeparationLines)
                                        {
                                            var modelCurve = element as ModelCurve;
                                            roomSeparations.Add(modelCurve);
                                            roomSeparationIds.Add(modelCurve.Id);
                                        }
                                    }
                                }
                            }
                        }
                    }
                    rp.RoomSeparationLines    = roomSeparations;
                    rp.RoomSeparationLinesIds = roomSeparationIds;
                    RoomDictionary.Add(rp.RoomId, rp);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Failed to collect rooms.\n" + ex.Message, "Collect Rooms", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }
Esempio n. 29
0
        public static List <Panel> Panels(this SpatialElement spatialElement, SpatialElementBoundaryOptions spatialElementBoundaryOptions, Core.Revit.ConvertSettings convertSettings)
        {
            if (spatialElement == null || spatialElementBoundaryOptions == null)
            {
                return(null);
            }

            SpatialElementGeometryCalculator spatialElementGeometryCalculator = new SpatialElementGeometryCalculator(spatialElement.Document, spatialElementBoundaryOptions);

            return(Panels(spatialElement, spatialElementGeometryCalculator, convertSettings));
        }
Esempio n. 30
0
        /***************************************************/

        public static Space SpaceFromRevit(this SpatialElement spatialElement, SpatialElementBoundaryOptions spatialElementBoundaryOptions, RevitSettings settings = null, Dictionary <string, List <IBHoMObject> > refObjects = null)
        {
            if (spatialElement == null || spatialElementBoundaryOptions == null)
            {
                return(new Space());
            }

            SpatialElementGeometryCalculator spatialElementGeometryCalculator = new SpatialElementGeometryCalculator(spatialElement.Document, spatialElementBoundaryOptions);

            return(SpaceFromRevit(spatialElement, spatialElementGeometryCalculator, settings, refObjects));
        }
        public SpatialElementStream(ArrayList data, object elem)
        {
            this.data      = data;
            spatialElement = elem as SpatialElement;

            boundaryOptions = new SpatialElementBoundaryOptions
            {
                StoreFreeBoundaryFaces         = true,
                SpatialElementBoundaryLocation = SpatialElementBoundaryLocation.Center
            };
        }
        /// <summary>
        /// Distinguish 'Not Placed',  'Redundant' 
        /// and 'Not Enclosed' rooms.
        /// </summary>
        RoomState DistinguishRoom( Room room )
        {
            RoomState res = RoomState.Unknown;

              if( room.Area > 0 )
              {
            // Placed if having Area

            res = RoomState.Placed;
              }
              else if( null == room.Location )
              {
            // No Area and No Location => Unplaced

            res = RoomState.NotPlaced;
              }
              else
              {
            // must be Redundant or NotEnclosed

            SpatialElementBoundaryOptions opt
              = new SpatialElementBoundaryOptions();

            IList<IList<BoundarySegment>> segs
              = room.GetBoundarySegments( opt );

            res = ( null == segs || segs.Count == 0 )
              ? RoomState.NotEnclosed
              : RoomState.Redundant;
              }
              return res;
        }
        /// <summary>
        /// List some properties of a given room to the
        /// Visual Studio debug output window.
        /// </summary>
        void ListRoomData( Room room )
        {
            SpatialElementBoundaryOptions opt
            = new SpatialElementBoundaryOptions();

              string nr = room.Number;
              string name = room.Name;
              double area = room.Area;

              Location loc = room.Location;
              LocationPoint lp = loc as LocationPoint;
              XYZ p = ( null == lp ) ? XYZ.Zero : lp.Point;

              BoundingBoxXYZ bb = room.get_BoundingBox( null );

              IList<IList<BoundarySegment>> boundary
            = room.GetBoundarySegments( opt );

              int nLoops = boundary.Count;

              int nFirstLoopSegments = 0 < nLoops
            ? boundary[0].Count
            : 0;

              Debug.Print( string.Format(
            "Room nr. '{0}' named '{1}' at {2} with "
            + "bounding box {3} and area {4} sqf has "
            + "{5} loop{6} and {7} segment{8} in first "
            + "loop.",
            nr, name, Util.PointString( p ),
            BoundingBoxString2( bb ), area, nLoops,
            Util.PluralSuffix( nLoops ), nFirstLoopSegments,
            Util.PluralSuffix( nFirstLoopSegments ) ) );
        }
        /// <summary>
        /// Gets the boundary options of a spatial element.
        /// </summary>
        /// <param name="spatialElement">The spatial element. null to get the default options.</param>
        /// <returns>The SpatialElementBoundaryOptions.</returns>
        static SpatialElementBoundaryOptions GetSpatialElementBoundaryOptions(SpatialElement spatialElement)
        {
            SpatialElementBoundaryOptions spatialElementBoundaryOptions = new SpatialElementBoundaryOptions();
            spatialElementBoundaryOptions.SpatialElementBoundaryLocation = SpatialElementBoundaryLocation.Finish;

            if (spatialElement == null)
                return spatialElementBoundaryOptions;

            SpatialElementType spatialElementType = SpatialElementType.Room;
            if (spatialElement is Autodesk.Revit.DB.Architecture.Room)
            {
                spatialElementType = SpatialElementType.Room;
            }
            else if (spatialElement is Area)
            {
                spatialElementType = SpatialElementType.Area;
            }
            else if (spatialElement is Autodesk.Revit.DB.Mechanical.Space)
            {
                spatialElementType = SpatialElementType.Space;
            }
            else
                return spatialElementBoundaryOptions;

            AreaVolumeSettings areaSettings = AreaVolumeSettings.GetAreaVolumeSettings(spatialElement.Document);
            if (areaSettings != null)
            {
                spatialElementBoundaryOptions.SpatialElementBoundaryLocation = areaSettings.GetSpatialElementBoundaryLocation(spatialElementType);
            }

            return spatialElementBoundaryOptions;
        }
        /// <summary>
        /// List some properties of a given room to the
        /// Visual Studio debug output window.
        /// </summary>
        void ListRoomData( Room room )
        {
            SpatialElementBoundaryOptions opt
            = new SpatialElementBoundaryOptions();

              string nr = room.Number;
              string name = room.Name;
              double area = room.Area;

              Location loc = room.Location;
              LocationPoint lp = loc as LocationPoint;
              XYZ p = ( null == lp ) ? XYZ.Zero : lp.Point;

              BoundingBoxXYZ bb = room.get_BoundingBox( null );

              IList<IList<BoundarySegment>> boundary
            = room.GetBoundarySegments( opt );

              int nLoops = boundary.Count;

              int nFirstLoopSegments = 0 < nLoops
            ? boundary[0].Count
            : 0;

              BoundingBoxXYZ boundary_bounding_box
            = GetBoundingBox( boundary );

              List<XYZ> convex_hull
            = GetConvexHullOfRoomBoundary( boundary );

              Debug.Print( string.Format(
            "Room nr. '{0}' named '{1}' at {2} with "
            + "lower left corner {3}, convex hull {4}, "
            + "bounding box {5} and area {6} sqf has "
            + "{7} loop{8} and {9} segment{10} in first "
            + "loop.",
            nr, name, Util.PointString( p ),
            Util.PointString( boundary_bounding_box.Min ),
            Util.PointArrayString( convex_hull ),
            BoundingBoxString2( bb ), area, nLoops,
            Util.PluralSuffix( nLoops ), nFirstLoopSegments,
            Util.PluralSuffix( nFirstLoopSegments ) ) );
        }
        public Result Execute( 
            ExternalCommandData commandData,
            ref string message,
            ElementSet elements)
        {
            UIApplication uiapp = commandData.Application;
              UIDocument uidoc = uiapp.ActiveUIDocument;
              Document doc = uidoc.Document;

              // Interactively select elements of type Room,
              // either via pre-selection before launching the
              // command, or interactively via post-selection.

              JtSelectorMulti<Room> selector
            = new JtSelectorMulti<Room>(
              uidoc, BuiltInCategory.OST_Rooms, "room",
              e => e is Room );

              if( selector.IsEmpty )
              {
            return selector.ShowResult();
              }

              IList<Room> rooms = selector.Selected;

              List<string> msg = new List<string>();

              int n = rooms.Count;

              msg.Add( string.Format(
            "{0} room{1} selected{2}\r\n",
            n, Util.PluralSuffix( n ),
            Util.DotOrColon( n ) ) );

              SpatialElementBoundaryOptions opt
            = new SpatialElementBoundaryOptions();

              IList<IList<BoundarySegment>> loops;

              Room neighbour;
              int i = 0, j, k;

              foreach( Room room in rooms )
              {
            ++i;

            loops = room.GetBoundarySegments( opt );

            n = loops.Count;

            msg.Add( string.Format(
              "{0}. {1} has {2} loop{3}{4}",
              i, Util.ElementDescription( room ),
              n, Util.PluralSuffix( n ),
              Util.DotOrColon( n ) ) );

            j = 0;

            foreach( IList<BoundarySegment> loop in loops )
            {
              ++j;

              n = loop.Count;

              msg.Add( string.Format(
            "  {0}. Loop has {1} boundary segment{2}{3}",
            j, n, Util.PluralSuffix( n ),
            Util.DotOrColon( n ) ) );

              k = 0;

              foreach( BoundarySegment seg in loop )
              {
            ++k;

            neighbour = GetRoomNeighbourAt( seg, room );

            msg.Add( string.Format(
              "    {0}. Boundary segment has neighbour {1}",
              k,
              (null==neighbour
                ? "<nil>"
                : Util.ElementDescription( neighbour )) ) );
              }
            }
              }

              Util.InfoMsg2( "Room Neighbours",
            string.Join( "\n", msg.ToArray() ) );

              return Result.Succeeded;
        }
Esempio n. 37
0
        private List<string> getVertexPoints(Space roomSpace)
        {
            List<string> verticies = new List<string>();
            SpatialElementBoundaryOptions opts = new SpatialElementBoundaryOptions();
            IList<IList<Autodesk.Revit.DB.BoundarySegment>> bsa = roomSpace.GetBoundarySegments(opts);
            if (bsa.Count > 0)
            {
                foreach (Autodesk.Revit.DB.BoundarySegment bs in bsa[0])
                {
                    // For 2014
                    //var X = bs.Curve.get_EndPoint(0).X * meterMultiplier;
                    //var Y = bs.Curve.get_EndPoint(0).Y * meterMultiplier;
                    var X = bs.Curve.GetEndPoint(0).X * meterMultiplier;
                    var Y = bs.Curve.GetEndPoint(0).Y * meterMultiplier;

                    verticies.Add(X.ToDecimalString() + " " + Y.ToDecimalString());
                }

            }
            else
            {
                verticies.Add("0 0");
            }
            return verticies;
        }
Esempio n. 38
0
        private int getVertexPointNums(Space roomSpace)
        {
            SpatialElementBoundaryOptions opts = new SpatialElementBoundaryOptions();
            try
            {
                IList<IList<Autodesk.Revit.DB.BoundarySegment>> bsa = roomSpace.GetBoundarySegments(opts);

                return bsa[0].Count;
            }
            catch (Exception)
            {
                TaskDialog.Show("OOPS!", "Seems you have a Space in your view that is not in a properly enclosed region. \n\nPlease remove these Spaces or re-establish them inside of boundary walls and run the Exporter again.");
                throw new IndexOutOfRangeException();
            }
        }