//
// (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.Text;
using System.Collections;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using Autodesk.Revit;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;
using Autodesk.Revit.ApplicationServices;
namespace Revit.SDK.Samples.SpotDimension.CS
{
///
/// Store all the views and spot dimensions in Revit.
///
public class SpotDimensionsData
{
UIApplication m_revit; // Store the reference of the application in Revit
List m_views = new List();
List m_spotDimensions = new List(); //a list to store all SpotDimensions in the project
///
/// a list of all the SpotDimensions in the project
///
public ReadOnlyCollection SpotDimensions
{
get
{
return new ReadOnlyCollection(m_spotDimensions);
}
}
///
/// a list of all the views that have SpotDimentions in the project
///
public ReadOnlyCollection Views
{
get
{
return new ReadOnlyCollection(m_views);
}
}
///
/// Constructor
///
///
public SpotDimensionsData(ExternalCommandData commandData)
{
m_revit = commandData.Application;
GetSpotDimensions();
}
///
/// try to find all the SpotDimensions and add them to the list
///
private void GetSpotDimensions()
{
//get the active document
Document document = m_revit.ActiveUIDocument.Document;
FilteredElementIterator elementIterator = (new FilteredElementCollector(document)).OfClass(typeof(Autodesk.Revit.DB.SpotDimension)).GetElementIterator();
elementIterator.Reset();
while (elementIterator.MoveNext())
{
//find all the SpotDimensions and views
Autodesk.Revit.DB.SpotDimension tmpSpotDimension = elementIterator.Current as Autodesk.Revit.DB.SpotDimension;
if (null != tmpSpotDimension)
{
m_spotDimensions.Add(tmpSpotDimension);
if (m_views.Contains(tmpSpotDimension.View.Name) == false)
{
m_views.Add(tmpSpotDimension.View.Name);
}
}
}
}
}
}