// // (C) Copyright 2003-2019 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.Data; using System.Drawing; using System.Drawing.Drawing2D; using System.Text; using System.Windows.Forms; using System.Linq; using Autodesk.Revit; using Autodesk.Revit.DB; using Autodesk.Revit.UI; namespace Revit.SDK.Samples.CurtainWallGrid.CS { /// /// maintains all the data used in the sample /// public class MyDocument { #region Fields // object which contains reference of Revit Application ExternalCommandData m_commandData; /// /// object which contains reference of Revit Application /// public ExternalCommandData CommandData { get { return m_commandData; } } // the active document of Revit UIDocument m_uiDocument; /// /// the active document of Revit /// public UIDocument UIDocument { get { return m_uiDocument; } } // the active document of Revit Document m_document; /// /// the active document of Revit /// public Document Document { get { return m_document; } } // stores all the Curtain WallTypes in the active Revit document List m_wallTypes; // stores all the ViewPlans in the active Revit document List m_views; // stores the wall creation related data and operations WallGeometry m_wallGeometry; // stores the curtain wall created Wall m_curtainWall; // indicates whether the curtain wall has been created bool m_wallCreated; // store the grid information of the created curtain wall GridGeometry m_gridGeometry; // store the active grid line operation LineOperation m_activeOperation; // the length unit type for the active Revit document ForgeTypeId m_LengthUnit; // store the message of the sample private KeyValuePair m_message; /// /// stores all the Curtain WallTypes in the active Revit document /// public List WallTypes { get { return m_wallTypes; } } /// /// stores all the ViewPlans in the active Revit document /// public List Views { get { return m_views; } } /// /// stores the wall creation related data and operations /// public WallGeometry WallGeometry { get { return m_wallGeometry; } } /// /// stores the curtain wall created /// public Wall CurtainWall { get { return m_curtainWall; } set { m_curtainWall = value; } } /// /// indicates whether the curtain wall has been created /// public bool WallCreated { get { return m_wallCreated; } set { m_wallCreated = value; } } /// /// store the grid information of the created curtain wall /// public GridGeometry GridGeometry { get { return m_gridGeometry; } } /// /// store the active grid line operation /// public LineOperation ActiveOperation { get { return m_activeOperation; } set { m_activeOperation = value; } } public ForgeTypeId LengthUnit { get { return m_LengthUnit; } } /// /// store the message of the sample /// public KeyValuePair Message { get { return m_message; } set { m_message = value; if (null != MessageChanged) { MessageChanged(); } } } #endregion #region Delegates and Events // occurs only when the message was updated public delegate void MessageChangedHandler(); public event MessageChangedHandler MessageChanged; #endregion #region Constructors /// /// constructor /// /// /// object which contains reference of Revit Application /// public MyDocument(ExternalCommandData commandData) { if (null != commandData.Application.ActiveUIDocument) { m_commandData = commandData; m_uiDocument = m_commandData.Application.ActiveUIDocument; m_document = m_uiDocument.Document; m_views = new List(); m_wallTypes = new List(); m_wallGeometry = new WallGeometry(this); m_wallCreated = false; m_gridGeometry = new GridGeometry(this); // get all the wall types and all the view plans InitializeData(); // get the length unit type of the active Revit document GetLengthUnitType(); // initialize the curtain grid operation type m_activeOperation = new LineOperation(LineOperationType.Waiting); } } #endregion #region Private methods /// /// Get current length display unit type /// private void GetLengthUnitType() { ForgeTypeId specTypeId = SpecTypeId.Length; Units projectUnit = m_document.GetUnits(); try { Autodesk.Revit.DB.FormatOptions formatOption = projectUnit.GetFormatOptions(specTypeId); m_LengthUnit = formatOption.GetUnitTypeId(); } catch (System.Exception /*e*/) { m_LengthUnit = UnitTypeId.Feet; } } /// /// get all the wall types for curtain wall and all the view plans from the active document /// private void InitializeData() { // get all the wall types FilteredElementCollector filteredElementCollector = new FilteredElementCollector(m_document); filteredElementCollector.OfClass(typeof(WallType)); // just get all the curtain wall type m_wallTypes = filteredElementCollector.Cast().Where(wallType => wallType.Kind == WallKind.Curtain).ToList(); // sort them alphabetically WallTypeComparer wallComp = new WallTypeComparer(); m_wallTypes.Sort(wallComp); // get all the ViewPlans m_views = SkipTemplateViews(GetElements()); // sort them alphabetically ViewComparer viewComp = new ViewComparer(); m_views.Sort(viewComp); // get one of the mullion types MullionTypeSet mullTypes = m_document.MullionTypes; foreach (MullionType type in mullTypes) { if (null != type) { BuiltInParameter bip = BuiltInParameter.ALL_MODEL_FAMILY_NAME; Parameter para = type.get_Parameter(bip); if (null != para) { string name = para.AsString().ToLower(); if (name.StartsWith("circular mullion")) { m_gridGeometry.MullionType = type; } } } } } protected List GetElements() where T : Element { List returns = new List(); FilteredElementCollector collector = new FilteredElementCollector(m_document); ICollection founds = collector.OfClass(typeof(T)).ToElements(); foreach (Element elem in founds) { returns.Add(elem as T); } return returns; } /// /// View elements filtered by new iteration will include template views. /// These views are not invalid for test(because they're invisible in project browser) /// Skip template views for regression test /// /// /// private List SkipTemplateViews(List views) where T : Autodesk.Revit.DB.View { List returns = new List(); foreach (Autodesk.Revit.DB.View curView in views) { if (null != curView && !curView.IsTemplate) returns.Add(curView as T); } return returns; } #endregion } }