Quantcast
Channel: All Revit API Forum posts
Viewing all articles
Browse latest Browse all 66677

Re: Check if an Element is of Room type?

$
0
0

You can filter by category or you can check the category name of the element if it equals Rooms. Please have a look on the following code and if it satisfies your needs mark this reply as an answer.

#region Namespaces

using System;
using System.Text;
using System.Linq;
using System.Xml;
using System.Reflection;
using System.ComponentModel;
using System.Collections;
using System.Collections.Generic;
using System.Windows;

using System.IO;

using Autodesk.Revit.ApplicationServices;
using Autodesk.Revit.Attributes;

using Autodesk.Revit.DB;
using Autodesk.Revit.DB.Events;
using Autodesk.Revit.DB.Architecture;
using Autodesk.Revit.DB.Structure;
using Autodesk.Revit.DB.Mechanical;
using Autodesk.Revit.DB.Electrical;
using Autodesk.Revit.DB.Plumbing;

using Autodesk.Revit.UI;
using Autodesk.Revit.UI.Selection;
using Autodesk.Revit.UI.Events;

//using Autodesk.Revit.Collections;
using Autodesk.Revit.Exceptions;
using Autodesk.Revit.Utility;

using RvtApplication = Autodesk.Revit.ApplicationServices.Application;
using RvtDocument = Autodesk.Revit.DB.Document;

#endregion

namespace RvtTest
{
    [Transaction(TransactionMode.Manual)]
    [Regeneration(RegenerationOption.Manual)]
    public class ExtCmd : IExternalCommand
    {
        #region Cached Variables

        private static ExternalCommandData _cachedCmdData;
        
        public static UIApplication CachedUiApp
        {
            get
            {
                return _cachedCmdData.Application;
            }
        }

        public static RvtApplication CachedApp
        {
            get
            {
                return CachedUiApp.Application;
            }
        }

        public static RvtDocument CachedDoc
        {
            get
            {
                return CachedUiApp.ActiveUIDocument.Document;
            }
        }
        
        #endregion

        #region IExternalCommand Members         

        public Result Execute(ExternalCommandData cmdData, ref string msg, ElementSet elemSet)
        {
            _cachedCmdData = cmdData;

            try
            {
                //TODO: add your code below.
                FilteredElementCollector collector = new FilteredElementCollector(CachedDoc);
                ICollection<Element> rooms = collector.OfCategory(BuiltInCategory.OST_Rooms).ToElements();
                collector.WhereElementIsNotElementType();

                StringBuilder sb = new StringBuilder();

                foreach (Element el in rooms)
                {
                    if (el.Category.Name == "Rooms")
                    {
                        //This is a room
                    }
                }

                TaskDialog.Show("reavit", sb.ToString());

                return Result.Succeeded;
            }
            catch (Exception ex)
            {
                msg = ex.ToString();
                return Result.Failed;
            }
        }

        #endregion
    }
}

Viewing all articles
Browse latest Browse all 66677

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>