using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Autodesk.Revit;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;
using Autodesk.Revit.DB.Structure;
using Autodesk.Revit.UI.Selection;
namespace ContextualAnalyticalModel
{
///
/// Utility methods
///
public static class Utilities
{
///
/// Selects a Revit element and returns its ElementId
///
/// UIDocument
/// status message
/// ElementId of the selected element
public static ElementId GetSelectedObject(UIDocument uiDoc, string msg)
{
ElementId selectedElementId = ElementId.InvalidElementId;
Reference refElem = uiDoc.Selection.PickObject(ObjectType.Element, msg);
if (refElem != null)
{
selectedElementId = refElem.ElementId;
}
return selectedElementId;
}
///
/// Selects multiple Revit elements and returns the ElementIds
///
/// UIDocument
/// status message
/// List of ElementId of the selected elements
public static ISet GetSelectedObjects(UIDocument uiDoc, string msg)
{
ISet selectedElementIdList = new HashSet();
IList refElemList = uiDoc.Selection.PickObjects(ObjectType.Element, msg);
if (refElemList != null)
{
selectedElementIdList = refElemList.Select(x => x.ElementId).ToHashSet();
}
return selectedElementIdList;
}
}
}