Application: AddSpaceAndZone
Revit Platform: MEP
Revit Version: 2010.0
First Released For: 2009.0
Last Modified: 02/26/2008
Modified By: JL Autodesk
Programming Language: C#
Skill Level: Medium
Category: Rooms/Spaces
Type: ExternalCommand

Subject: Create spaces and zones.
Summary: 
This sample demonstrates three main features:
1.	How to get all Space elements in a specified level.
2.	How to get all Zone elements   in a specified level.
3.	How to create Space elements for each closed wall loop or closed space separation.
4.	How to create a new Zone element in a specified level and phase.
5.	How to add/remove spaces in a Zone element.

Classes: 
Autodesk.Revit.IExternalCommand
Autodesk.Revit.Elements.Space
Autodesk.Revit.Elements.Zone
Autodesk.Revit.Elements.Phase
Autodesk.Revit.Creation.Document

Project Files: 
Command.cs
This file contains the class “Command” which inherits from “IExternalCommand” interface and implements the “Execute” method.

DataManager.cs
It contains a class named “DataManager” which is used to obtain, create or edit the Space elements and Zone elements.

SpaceManager.cs
It contains a class named “SpaceManager” which is used to manage the Space elements in the current document. It can create Space elements for each closed wall loop or closed space separation.

ZoneManager.cs
It contains a class named “ZoneManager” which is used to manage the Zone elements in the current document. It can add/remove spaces in a Zone element.

Description: 
Functionalities:
-	Get all Space elements and Zone elements in active document and list them grouped by level.
-	Create Space elements for each closed wall loop or closed space separation in a specified level.
-	Create a new Zone element in a specified level and phase.
-	Add/remove spaces in a Zone element

Implementations:
-	Using Element Filter to get all Space and Zone elements.
-	Create spaces for each closed wall loop or closed space separation via ElementSet NewSpaces (Level level, Phase phase, View view) method.
-	Create spaces for each closed wall loop or closed space separation via ElementSet NewSpaces (Level level, Phase phase, View view) method.
-	Add/Remove spaces in a zone via bool AddSpaces (SpaceSet spaces)/Remove (SpaceSet spaces) member functions of Zone class.

Instructions: 
1.	Open a Revit MEP 2009 file which contains some enclosed loops which are made up of walls. A sample project file WallLoopForAddingSpaceAndZone.rvt is available in the sample’s folder.
2.	Run this command.
3.	An AddSpaceAndZone dialog will be shown to display all the Space and Zone elements filtered by level. The Spaces will be displayed as a list in the Spaces Tag page, the Zones will be displayed as a tree list to show the spaces each Zone element contains.
4.	Click “Create Spaces” button in Space Tag page to create spaces for each closed wall loop or closed space separation in the selected level.
5.	Click “Create Zone” button in Zones Tag page to create a zone in a current level and phase of the active view
6.	Select a Zone, click the “Edit Zone” button, a ZoneEditorForm will be shown to display the available spaces list and the spaces the selected zone contains in current level. Select some spaces in the available spaces list, click the “Add” button to add them to the current Zone. Select some spaces in the current spaces list, click the “Remove” button to remove them from the current Zone. Click the “OK” button to return the AddSpaceAndZone dialog.
7.	Click “OK” button to accept the operation or click “Cancel” button to abort them.