//
// (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 Autodesk.Revit;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;
using Autodesk.Revit.ApplicationServices;
namespace Revit.SDK.Samples.WindowWizard.CS
{
///
/// A common class for users to get some specified element
///
class Utility
{
///
/// This method is used to allow user to get reference plane by name,if there is no proper reference plane,will return null
///
/// the name property of reference plane
/// the application
/// the document
/// the reference plane or null
public static ReferencePlane GetRefPlaneByName(string name, UIApplication app,Document doc)
{
ReferencePlane r = null;
FilteredElementCollector collector = new FilteredElementCollector(app.ActiveUIDocument.Document);
collector.OfClass(typeof(ReferencePlane));
FilteredElementIterator eit = collector.GetElementIterator();
eit.Reset();
while (eit.MoveNext())
{
r = eit.Current as ReferencePlane;
if (r.Name.Equals(name))
{
break;
}
}
return r;
}
///
/// This method allows user to get view by name
///
/// the name property of view
/// the application
/// the document
/// the view or null
public static View GetViewByName(string name,UIApplication app,Document doc)
{
View v = null;
FilteredElementCollector collector = new FilteredElementCollector(app.ActiveUIDocument.Document);
collector.OfClass(typeof(View));
FilteredElementIterator eit = collector.GetElementIterator();
eit.Reset();
while (eit.MoveNext())
{
v = eit.Current as View;
if (v.Name.Equals(name))
{
break;
}
}
return v;
}
///
/// This method is used to get elements by type filter
///
/// the type
/// the application
/// the document
/// the list of elements
public static List GetElements(UIApplication app,Document doc) where T : Autodesk.Revit.DB.Element
{
List elements = new List();
FilteredElementCollector collector = new FilteredElementCollector(app.ActiveUIDocument.Document);
collector.OfClass(typeof(T));
FilteredElementIterator eit = collector.GetElementIterator();
eit.Reset();
while (eit.MoveNext())
{
T element = eit.Current as T;
if (element != null)
{
elements.Add(element);
}
}
return elements;
}
///
/// This function is used to convert from metric to imperial
///
/// the metric value
/// the result
public static double MetricToImperial(double value)
{
return value / 304.8; //* 0.00328;
}
///
/// This function is used to convert from imperial to metric
///
/// the imperial value
/// the result
public static double ImperialToMetric(double value)
{
return value*304.8;
}
}
}