C

Selection

Description:
Contains the current user selection of elements within the project.
Remarks:
The Selection object is used to retrieve the current user selected elements when an external API command is executed.
Inheritance Hierarchy:
System.Object
  Autodesk.Revit.UI.Selection.Selection
public class Selection : IDisposable
[Autodesk.Revit.Attributes.Transaction(Autodesk.Revit.Attributes.TransactionMode.ReadOnly)]
public class Document_Selection : IExternalCommand
{
    public Autodesk.Revit.UI.Result Execute(ExternalCommandData commandData,
        ref string message, ElementSet elements)
    {
        try
        {
            // Select some elements in Revit before invoking this command

            // Get the handle of current document.
            UIDocument uidoc = commandData.Application.ActiveUIDocument;

            // Get the element selection of current document.
            Selection selection = uidoc.Selection;
            ICollection<ElementId> selectedIds = uidoc.Selection.GetElementIds();

            if (0 == selectedIds.Count)
            {
                // If no elements selected.
                TaskDialog.Show("Revit","You haven't selected any elements.");
            }
            else
            {
                String info = "Ids of selected elements in the document are: ";
                foreach (ElementId id in selectedIds)
                {
                   info += "\n\t" + id.ToString();
                }

                TaskDialog.Show("Revit",info);
            }
        }
        catch (Exception e)
        {
            message = e.Message;
            return Autodesk.Revit.UI.Result.Failed;
        }

        return Autodesk.Revit.UI.Result.Succeeded;
    }
    /// </ExampleMethod>
}
Name Return Type Description
M Dispose() None Releases all resources used by the
M GetElementIds() ICollection<ElementId> Returns the ids of the elements that are currently selected within the project. The selection may not be complete. See GetReferences for more options.
M GetReferences() IList<Reference> Returns the references that are currently selected.
M PickBox(PickBoxStyle) PickedBox Invokes a general purpose two-click editor that lets the user to specify a rectangular area on the screen.
M PickBox(PickBoxStyle, String) PickedBox Invokes a general purpose two-click editor that lets the user to specify a rectangular area on the screen.
M PickElementsByRectangle() IList<Element> Prompts the user to select multiple elements by drawing a rectangle.
M PickElementsByRectangle(ISelectionFilter) IList<Element> Prompts the user to select multiple elements by drawing a rectangle which pass a customer filter.
M PickElementsByRectangle(ISelectionFilter, String) IList<Element> Prompts the user to select multiple elements by drawing a rectangle which pass a customer filter while showing a custom status prompt string.
M PickElementsByRectangle(String) IList<Element> Prompts the user to select multiple elements by drawing a rectangle while showing a custom status prompt string.
M PickObject(ObjectType) Reference Prompts the user to select one object.
M PickObject(ObjectType, ISelectionFilter) Reference Prompts the user to select one object which passes a custom filter.
M PickObject(ObjectType, ISelectionFilter, String) Reference Prompts the user to select one object which passes a custom filter while showing a custom status prompt string.
M PickObject(ObjectType, String) Reference Prompts the user to select one object while showing a custom status prompt string.
M PickObjects(ObjectType) IList<Reference> Prompts the user to select multiple objects.
M PickObjects(ObjectType, ISelectionFilter) IList<Reference> Prompts the user to select multiple objects which pass a customer filter.
M PickObjects(ObjectType, ISelectionFilter, String) IList<Reference> Prompts the user to select multiple objects which pass a custom filter while showing a custom status prompt string.
M PickObjects(ObjectType, ISelectionFilter, String, IList<Reference>) IList<Reference> Prompts the user to select multiple objects which pass a custom filter while showing a custom status prompt string. A preselected set of objects may be supplied and will be selected at the start of the selection.
M PickObjects(ObjectType, String) IList<Reference> Prompts the user to select multiple objects while showing a custom status prompt string.
M PickPoint() XYZ Prompts the user to pick a point on the active work plane.
M PickPoint(ObjectSnapTypes) XYZ Prompts the user to pick a point on the active work plane using specified snap settings.
M PickPoint(ObjectSnapTypes, String) XYZ Prompts the user to pick a point on the active work plane using specified snap settings while showing a custom status prompt string.
M PickPoint(String) XYZ Prompts the user to pick a point on the active work plane while showing a custom status prompt string.
M SetElementIds(ICollection<ElementId>) None Selects the elements.
M SetReferences(IList<Reference>) None Selects the references. The references can be an element or a subelement in the host or a linked document.
Name Return Type Description
P IsValidObject bool Specifies whether the .NET object represents a valid Revit entity.