Example #1
0
        SketchBoundary()
        {
            Revit.Creation.Document doc         = m_revitApp.ActiveUIDocument.Document.Create;
            SketchPlane             sketchPlane = Utils.Geometry.GetWorldPlane(m_revitApp);

            RevitLookup.Test.Forms.Levels lev = new RevitLookup.Test.Forms.Levels(m_revitApp);
            if (lev.ShowDialog() != DialogResult.OK)
            {
                return;
            }

            Level curLevel = lev.LevelSelected;

            if (curLevel == null)
            {
                MessageBox.Show("No Level was selected.");
                return;
            }

            // Get the plan topology of the active doc first
            PlanTopology            planTopo = m_revitApp.ActiveUIDocument.Document.get_PlanTopology(curLevel);
            ICollection <ElementId> roomIds  = planTopo.GetRoomIds();

            if (roomIds.Count > 0)
            {
                IEnumerator <ElementId> setIter = roomIds.GetEnumerator();
                while (setIter.MoveNext())
                {
                    Autodesk.Revit.DB.Architecture.Room room = m_revitApp.ActiveUIDocument.Document.GetElement(setIter.Current) as Autodesk.Revit.DB.Architecture.Room;

                    if (null != room)
                    {
                        IList <IList <Autodesk.Revit.DB.BoundarySegment> > boundSegArrayArray = room.GetBoundarySegments(new SpatialElementBoundaryOptions());

                        foreach (IList <Autodesk.Revit.DB.BoundarySegment> boundSegArray in boundSegArrayArray)
                        {
                            foreach (Autodesk.Revit.DB.BoundarySegment boundSeg in boundSegArray)
                            {
                                if (null != boundSeg)
                                {
                                    // once you get to the Boundary Segment which represent one of the sides of the room boundary, draw a Model Curve to
                                    // represent the outline.
                                    ModelCurve modCurve = m_revitApp.ActiveUIDocument.Document.Create.NewModelCurve(boundSeg.Curve, sketchPlane);
                                }
                            }
                        }
                    }
                }
            }
            else
            {
                MessageBox.Show("No rooms found in the Active Document", "RevitLookup", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }
Example #2
0
        RoomArea()
        {
            Revit.Creation.Document doc         = m_revitApp.ActiveUIDocument.Document.Create;
            SketchPlane             sketchPlane = Utils.Geometry.GetWorldPlane(m_revitApp);

            RevitLookup.Test.Forms.Levels lev = new RevitLookup.Test.Forms.Levels(m_revitApp);
            if (lev.ShowDialog() != DialogResult.OK)
            {
                return;
            }

            Level curLevel = lev.LevelSelected;

            if (curLevel == null)
            {
                MessageBox.Show("No Level was selected.");
                return;
            }

            // Get the plan topology of the active doc first
            PlanTopology            planTopo = m_revitApp.ActiveUIDocument.Document.get_PlanTopology(curLevel);
            ICollection <ElementId> roomIds  = planTopo.GetRoomIds();

            if (roomIds.Count > 0)
            {
                IEnumerator <ElementId> setIter = roomIds.GetEnumerator();
                while (setIter.MoveNext())
                {
                    Room room = m_revitApp.ActiveUIDocument.Document.GetElement(setIter.Current) as Room;
                    if (null != room)
                    {
                        Autodesk.Revit.DB.View view          = m_revitApp.ActiveUIDocument.Document.ActiveView;
                        LocationPoint          locationPoint = room.Location as LocationPoint;

                        Double area = room.get_Parameter(BuiltInParameter.ROOM_AREA).AsDouble();

                        Double roundedArea = Math.Round(area, 2);

                        // providing an offset so that the Room Tag and the Area Tag dont overlap. Overlapping leads to an
                        // alignment related assert.

                        XYZ offset = new XYZ(5.0, 0, 0);

                        /// align text middle and center
                        TextAlignFlags align   = TextAlignFlags.TEF_ALIGN_MIDDLE ^ TextAlignFlags.TEF_ALIGN_CENTER;
                        TextNote       txtNote = m_revitApp.ActiveUIDocument.Document.Create.NewTextNote(view, offset + locationPoint.Point, GeomUtils.kXAxis,
                                                                                                         view.ViewDirection, .25,
                                                                                                         align, roundedArea.ToString());
                    }
                }
            }
            else
            {
                MessageBox.Show("No rooms found in the Active Document", "RevitLookup", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }


            // TBD: Tried to play around with PlanCircuits and there seems to be a problem with the IsRoomLocated property.
            // arj 1/23/07

            //Revit.PlanCircuitSet circSet = planTopo.Circuits;
            //Revit.PlanCircuitSetIterator setIters = circSet.ForwardIterator();

            //while (setIters.MoveNext())
            //{
            //    Revit.PlanCircuit planCircuit = setIters.Current as Revit.PlanCircuit;

            //    if (null != planCircuit)
            //    {
            //
            //        if (planCircuit.IsRoomLocated) // throws an exception always "Attempted to read or write protected memory.
            // This is often an indication that other memory is corrupt."
            //        {
            //        }
            //    }
            //}
        }
Example #3
0
        /// <summary>
        /// Draw lines to sketch the boundaries of available rooms in the Active Document.
        /// </summary>
        public void SketchBoundary()
        {
            Revit.Creation.Document doc = m_revitApp.ActiveUIDocument.Document.Create;
             SketchPlane sketchPlane = Utils.Geometry.GetWorldPlane(m_revitApp);

             RevitLookup.Test.Forms.Levels lev = new RevitLookup.Test.Forms.Levels(m_revitApp);
             if (lev.ShowDialog() != DialogResult.OK)
            return;

             Level curLevel = lev.LevelSelected;
             if (curLevel == null)
             {
            MessageBox.Show("No Level was selected.");
            return;
             }

             // Get the plan topology of the active doc first
             PlanTopology planTopo = m_revitApp.ActiveUIDocument.Document.get_PlanTopology(curLevel);
             ICollection<ElementId> roomIds = planTopo.GetRoomIds();

             if (roomIds.Count > 0)
             {
            IEnumerator<ElementId> setIter = roomIds.GetEnumerator();
            while (setIter.MoveNext())
            {
               Autodesk.Revit.DB.Architecture.Room room = m_revitApp.ActiveUIDocument.Document.GetElement(setIter.Current) as Autodesk.Revit.DB.Architecture.Room;

               if (null != room)
               {
                  IList<IList<Autodesk.Revit.DB.BoundarySegment>> boundSegArrayArray = room.GetBoundarySegments(new SpatialElementBoundaryOptions());

                  foreach (IList<Autodesk.Revit.DB.BoundarySegment> boundSegArray in boundSegArrayArray)
                  {
                     foreach (Autodesk.Revit.DB.BoundarySegment boundSeg in boundSegArray)
                     {
                        if (null != boundSeg)
                        {
                           // once you get to the Boundary Segment which represent one of the sides of the room boundary, draw a Model Curve to
                           // represent the outline.
                           ModelCurve modCurve = m_revitApp.ActiveUIDocument.Document.Create.NewModelCurve(boundSeg.GetCurve(), sketchPlane);
                        }
                     }
                  }
               }
            }
             }
             else
             {
            MessageBox.Show("No rooms found in the Active Document", "RevitLookup", MessageBoxButtons.OK, MessageBoxIcon.Information);
             }
        }
Example #4
0
        /// <summary>
        /// Calulate the area of all the available rooms and specify them using TextNotes
        /// </summary>
        public void RoomArea()
        {
            Revit.Creation.Document doc = m_revitApp.ActiveUIDocument.Document.Create;
             SketchPlane sketchPlane = Utils.Geometry.GetWorldPlane(m_revitApp);

             RevitLookup.Test.Forms.Levels lev = new RevitLookup.Test.Forms.Levels(m_revitApp);
             if (lev.ShowDialog() != DialogResult.OK)
            return;

             Level curLevel = lev.LevelSelected;
             if (curLevel == null)
             {
            MessageBox.Show("No Level was selected.");
            return;
             }

             // Get the plan topology of the active doc first
             PlanTopology planTopo = m_revitApp.ActiveUIDocument.Document.get_PlanTopology(curLevel);
             ICollection<ElementId> roomIds = planTopo.GetRoomIds();

             if (roomIds.Count > 0)
             {
            IEnumerator<ElementId> setIter = roomIds.GetEnumerator();
            while (setIter.MoveNext())
            {
               Room room = m_revitApp.ActiveUIDocument.Document.GetElement(setIter.Current) as Room;
               if (null != room)
               {
                  Autodesk.Revit.DB.View view = m_revitApp.ActiveUIDocument.Document.ActiveView;
                  LocationPoint locationPoint = room.Location as LocationPoint;

                  Double area = room.get_Parameter(BuiltInParameter.ROOM_AREA).AsDouble();

                  Double roundedArea = Math.Round(area, 2);

                  // providing an offset so that the Room Tag and the Area Tag dont overlap. Overlapping leads to an
                  // alignment related assert.

                  XYZ offset = new XYZ(5.0, 0, 0);

                  /// align text middle and center
                  TextNoteOptions op = new TextNoteOptions();
                  TextNote txtNote = TextNote.Create(m_revitApp.ActiveUIDocument.Document, view.Id, offset + locationPoint.Point, .25, roundedArea.ToString(), op);
               }
            }
             }
             else
             {
            MessageBox.Show("No rooms found in the Active Document", "RevitLookup", MessageBoxButtons.OK, MessageBoxIcon.Information);
             }

             // TBD: Tried to play around with PlanCircuits and there seems to be a problem with the IsRoomLocated property.
             // arj 1/23/07

             //Revit.PlanCircuitSet circSet = planTopo.Circuits;
             //Revit.PlanCircuitSetIterator setIters = circSet.ForwardIterator();

             //while (setIters.MoveNext())
             //{
             //    Revit.PlanCircuit planCircuit = setIters.Current as Revit.PlanCircuit;

             //    if (null != planCircuit)
             //    {
             //
             //        if (planCircuit.IsRoomLocated) // throws an exception always "Attempted to read or write protected memory.
             // This is often an indication that other memory is corrupt."
             //        {
             //        }
             //    }
             //}
        }