Ejemplo n.º 1
0
        /// <summary>
        /// Auto tag rooms with specified RoomTagType in a level
        /// </summary>
        /// <param name="level">The level where rooms will be auto tagged</param>
        /// <param name="tagType">The room tag type</param>
        public void AutoTagRooms(Level level, RoomTagType tagType)
        {
            PlanTopology planTopology = m_revit.ActiveUIDocument.Document.get_PlanTopology(level);

            SubTransaction subTransaction = new SubTransaction(m_revit.ActiveUIDocument.Document);

            subTransaction.Start();
            foreach (ElementId eid in planTopology.GetRoomIds())
            {
                Room tmpRoom = m_revit.ActiveUIDocument.Document.GetElement(eid) as Room;

                if (m_revit.ActiveUIDocument.Document.GetElement(tmpRoom.LevelId) != null && tmpRoom.Location != null)
                {
                    // Create a specified type RoomTag to tag a room
                    LocationPoint        locationPoint = tmpRoom.Location as LocationPoint;
                    Autodesk.Revit.DB.UV point         = new Autodesk.Revit.DB.UV(locationPoint.Point.X, locationPoint.Point.Y);
                    RoomTag newTag = m_revit.ActiveUIDocument.Document.Create.NewRoomTag(new LinkElementId(tmpRoom.Id), point, null);
                    newTag.RoomTagType = tagType;

                    List <RoomTag> tagListInTheRoom = m_roomWithTags[newTag.Room.Id];
                    tagListInTheRoom.Add(newTag);
                }
            }
            subTransaction.Commit();
        }
Ejemplo n.º 2
0
 Stream(ArrayList data, PlanTopology planTopo)
 {
     data.Add(new Snoop.Data.ClassSeparator(typeof(PlanTopology)));
     try
     {
         data.Add(new Snoop.Data.Enumerable("Circuits", planTopo.Circuits));
     }
     catch (System.Exception ex)
     {
         data.Add(new Snoop.Data.Exception("Circuits", ex));
     }
     try
     {
         data.Add(new Snoop.Data.Object("Level", planTopo.Level));
     }
     catch (System.Exception ex)
     {
         data.Add(new Snoop.Data.Exception("Level", ex));
     }
     data.Add(new Snoop.Data.Object("Phase", planTopo.Phase));
     try
     {
         data.Add(new Snoop.Data.Enumerable("Rooms", planTopo.GetRoomIds(), m_activeDoc));
     }
     catch (System.Exception ex)
     {
         data.Add(new Snoop.Data.Exception("Rooms", ex));
     }
 }
        public Result Execute(
            ExternalCommandData commandData,
            ref string message,
            ElementSet elements)
        {
            UIApplication app = commandData.Application;
            Document      doc = app.ActiveUIDocument.Document;

            FilteredElementCollector levels = Util.GetElementsOfType(
                doc, typeof(Level), BuiltInCategory.OST_Levels);

            Level level = levels.FirstElement() as Level;

            PlanTopology pt = doc.get_PlanTopology(level);

            // Collect some data on each room in the circuit

            string output = "Rooms on "
                            + level.Name + ":"
                            + "\n  Name and Number : Area";

            //foreach( Room r in pt.Rooms ) // 2012

            foreach (ElementId id in pt.GetRoomIds()) // 2013
            {
                Room r = doc.GetElement(id) as Room;

                output += "\n  " + r.Name + " : "
                          + Util.RealString(r.Area) + " sqf";
            }
            Util.InfoMsg(output);

            output = "Circuits without rooms:"
                     + "\n  Number of Sides : Area";

            using (Transaction t = new Transaction(doc))
            {
                t.Start("Create New Rooms");

                foreach (PlanCircuit pc in pt.Circuits)
                {
                    if (!pc.IsRoomLocated) // this circuit has no room, create one
                    {
                        output += "\n  " + pc.SideNum + " : "
                                  + Util.RealString(pc.Area) + " sqf";

                        // Pass null to create a new room;
                        // to place an existing unplaced room,
                        // pass it in instead of null:

                        Room r = doc.Create.NewRoom(null, pc);
                    }
                }
                t.Commit();
            }
            Util.InfoMsg(output);

            return(Result.Succeeded);
        }
Ejemplo n.º 4
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);
            }
        }
Ejemplo n.º 5
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."
            //        {
            //        }
            //    }
            //}
        }