// // (C) Copyright 2003-2023 by Autodesk, Inc. // // Permission to use, copy, modify, and distribute this software in // object code form for any purpose and without fee is hereby granted, // provided that the above copyright notice appears in all copies and // that both that copyright notice and the limited warranty and // restricted rights notice below appear in all supporting // documentation. // // AUTODESK PROVIDES THIS PROGRAM "AS IS" AND WITH ALL FAULTS. // AUTODESK SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTY OF // MERCHANTABILITY OR FITNESS FOR A PARTICULAR USE. AUTODESK, INC. // DOES NOT WARRANT THAT THE OPERATION OF THE PROGRAM WILL BE // UNINTERRUPTED OR ERROR FREE. // // Use, duplication, or disclosure by the U.S. Government is subject to // restrictions set forth in FAR 52.227-19 (Commercial Computer // Software - Restricted Rights) and DFAR 252.227-7013(c)(1)(ii) // (Rights in Technical Data and Computer Software), as applicable. // using System; using System.Collections.Generic; using System.Text; using Autodesk.Revit; using Autodesk.Revit.DB; using Autodesk.Revit.UI; using Autodesk.Revit.DB.Mechanical; namespace Revit.SDK.Samples.AddSpaceAndZone.CS { /// /// The SpaceManager class is used to manage the Spaces elements in the current document. /// class SpaceManager { ExternalCommandData m_commandData; Dictionary> m_spaceDictionary; /// /// The constructor of SpaceManager class. /// /// The ExternalCommandData /// The spaceData contains all the Space elements in different level. public SpaceManager(ExternalCommandData data, Dictionary> spaceData) { m_commandData = data; m_spaceDictionary = spaceData; } /// /// Get the Spaces elements in a specified level. /// /// /// Return a space list public List GetSpaces(Level level) { return m_spaceDictionary[level.Id]; } /// /// Create the space for each closed wall loop or closed space separation in the active view. /// /// The level in which the spaces is to exist. /// The phase in which the spaces is to exist. public void CreateSpaces(Level level, Phase phase) { try { ICollection elements = m_commandData.Application.ActiveUIDocument.Document.Create.NewSpaces2(level, phase, this.m_commandData.Application.ActiveUIDocument.Document.ActiveView); foreach (ElementId elem in elements) { Space space = m_commandData.Application.ActiveUIDocument.Document.GetElement(elem) as Space; if (space != null) { m_spaceDictionary[level.Id].Add(space); } } if (elements == null || elements.Count == 0) { Autodesk.Revit.UI.TaskDialog.Show("Revit", "There is no enclosed loop in " + level.Name); } } catch (Exception ex) { Autodesk.Revit.UI.TaskDialog.Show("Revit", ex.Message); } } } }