Results 1 to 4 of 4

Thread: Create a Zone for Each Space

  1. #1
    Member
    Join Date
    2012-02
    Posts
    27
    Login to Give a bone
    0

    Default Create a Zone for Each Space

    Hello all,

    I'm taking a swing at writing my first addin for Revit. I would like to write an addin that creates a zone for each space in the model and assigns the space to the new zone. I create all my eQuest energy models in Revit, and eQuest requires there to be exactly one zone per space. So, this addin both seems like a pretty simple first addin and would save me the time of clicking on each space and creating a zone. I went through the My First Plugin tutorials. And, I starting by looking for pieces of code in the "AddSpaceAndZone" sample addin in the 2013 SDK. I am proficient at writing Excel macros in VBA. Here is what the basic concept would look like in VBA:

    'For each space in Spaces,
    'Create a zone
    'assign the zone to the spaceS
    'set the zone name = space number
    'Next space

    Below is what I have peiced together as an attemp. Any help would be greatly appreciated!

    Thanks:

    Code:
    using System;
    using System.Collections.Generic;
    using Autodesk.Revit.DB;
    using Autodesk.Revit.UI;
    using Autodesk.Revit.DB.Mechanical;
    
    namespace Revit.SDK.Samples.CreateZonePerSpace.CS
    {
        /// <summary>
        /// Implements the Revit add-in interface IExternalCommand
        /// </summary>
        [Autodesk.Revit.Attributes.Transaction(Autodesk.Revit.Attributes.TransactionMode.Manual)]
        [Autodesk.Revit.Attributes.Regeneration(Autodesk.Revit.Attributes.RegenerationOption.Manual)]
        [Autodesk.Revit.Attributes.Journaling(Autodesk.Revit.Attributes.JournalingMode.NoCommandData)]
        public class Command : IExternalCommand
        {
    
     /// IExternalCommand
          public Autodesk.Revit.UI.Result Execute(Autodesk.Revit.UI.ExternalCommandData commandData,
                                                 ref string message,
                                                 ElementSet elements)
          {
          /// loop through spaces
          /// ??????
    
       
          /// For each space, create a zone
          public void CreateZone()
          {
              Zone zone = m_commandData.Application.ActiveUIDocument.Document.Create.NewZone();
              if (zone != null)
              {
                  this.m_zoneDictionary[level.Id.IntegerValue].Add(zone);
              }
          }
    
     /// add the space to the zone
            public void AddSpaces(SpaceSet spaces)
            {
                m_currentZone.AddSpaces(spaces);
            }
          }
       }
    }

  2. #2
    Member
    Join Date
    2012-09
    Posts
    34
    Login to Give a bone
    0

    Default Re: Create a Zone for Each Space

    You'll need a few things to do this.

    First, you'll need to use a FilteredElementCollector in conjunction with a SpaceFilter in order to retrieve all of the spaces in the model.

    Once you have these, you can iterate through each space, and use the NewZone method that you included above to create a new zone.

    The constructor for the NewZone method requires a Level and a Phase to be specified.

    You should be able to retrieve the level using the Space.Level property.

    You can retrieve the Phase from the Document.Phases property.

    Once the zone is created, use the Zone.AddSpaces property to add the space. You will need to create a new SpaceSet and insert the Space that you wish to use.

    You will also need to use transactions to create the zones and the spaces. I'd recommend creating each zone (and inserting the space) in its own Transaction. You can optionally wrap the entire function in a TransactionGroup so that the entire function only shows up as one entry in the Undo menu.

    You should consult the API documentation that's included in the SDK for further information (RevitAPI.chm)

    Hopefully this isn't too much information to take in all at once. Good luck!

  3. #3
    Woo! Hoo! my 1st post
    Join Date
    2016-03
    Posts
    1
    Login to Give a bone
    0

    Default Re: Create a Zone for Each Space

    Did you ever figure this one out? Looking at cracking the same problem now..

    Thanks.

  4. #4
    Member
    Join Date
    2012-09
    Posts
    34
    Login to Give a bone
    0

    Default Re: Create a Zone for Each Space

    If you have spaces on multiple phases in the model, then you will need some additional logic to deal with this. The code below assumes that there is only one phase present in the model and that all spaces are on this phase.

    I haven't tested the code below but I believe that it should work.

    Code:
        using System.Linq;
    
        using Autodesk.Revit.Attributes;
        using Autodesk.Revit.DB;
        using Autodesk.Revit.DB.Mechanical;
        using Autodesk.Revit.UI;
    
        [Transaction(TransactionMode.Manual)]
        public class CreateOneZonePerSpace : IExternalCommand
        {
            public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
            {
                UIApplication uiApplication = commandData.Application;
    
                UIDocument uidoc = uiApplication.ActiveUIDocument;
    
                Document doc = uidoc.Document;
    
                Phase firstPhase = doc.Phases.Cast<Phase>().First();
    
                var spaces = new FilteredElementCollector(doc).WherePasses(new SpaceFilter()).Cast<Space>();
    
                using (TransactionGroup transGroup = new TransactionGroup(doc, "Creating Zones from Spaces"))
                {
                    transGroup.Start();
    
                    foreach (var space in spaces)
                    {
                        string name = space.Name;
    
                        using (var trans = new Transaction(doc, "Creating zone for space " + name))
                        {
                            trans.Start();
    
                            Level spaceLevel = space.Level;
    
                            Zone newZone = doc.Create.NewZone(spaceLevel, firstPhase);
    
                            SpaceSet spaceSet = new SpaceSet();
    
                            spaceSet.Insert(space);
    
                            newZone.AddSpaces(spaceSet);
    
                            trans.Commit();
                        }
                    }
    
                    transGroup.Assimilate();
                }
    
                return Result.Succeeded;
            }
        }

Similar Threads

  1. Space and Zone Airflow Schedule Organization
    By pcunningham in forum Revit MEP - General
    Replies: 1
    Last Post: 2010-06-21, 03:34 PM
  2. [2009] Space information in the HVAC Zone Schedule (OPEN)
    By JoelLondenberg in forum Revit MEP - Wish List
    Replies: 4
    Last Post: 2010-03-04, 03:13 PM
  3. Creating a Family with space/zone id's
    By mwalker.87963 in forum Revit MEP - Families
    Replies: 0
    Last Post: 2009-12-09, 06:25 PM
  4. Space/Zone Manger Ceiling Floor and Surface
    By jwanstaett in forum ACA General
    Replies: 5
    Last Post: 2008-09-17, 01:38 PM
  5. Replies: 5
    Last Post: 2004-06-02, 01:39 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •