Compare to old way of selecting elements(http://blog.revitapp.com/2010/06/get-selected-elements/), Revit 2011 API provides a new way to select element(s).
Add a new line before the namespace: using Autodesk.Revit.UI.Selection;
Add a new class named WallFilter:
public class WallFilter : ISelectionFilter
{
/// <summary>
/// Allow Wall to be selected
/// </summary>
/// <param name=”element”>A candidate element in selection operation.</param>
/// <returns>Return true for wall. Return false for non wall element.</returns>
public bool AllowElement(Element element)
{
return element is Wall;
}
/// <summary>
/// Allow all the reference to be selected
/// </summary>
/// <param name=”refer”>A candidate reference in selection operation.</param>
/// <param name=”point”>The 3D position of the mouse on the candidate reference.</param>
/// <returns>Return true to allow the user to select this candidate reference.</returns>
public bool AllowReference(Reference refer, XYZ point)
{
return true;
}
}
Replace the code in class Class1 as:
// Select elements. Click “Finish” or “Cancel” buttons on the dialog bar to complete the selection operation.
List<ElementId> elemDeleteList = new List<ElementId>();
WallFilter wfilter = new WallFilter();
Reference eRef = commandData.Application.ActiveUIDocument.Selection.PickObject(ObjectType.Element, wfilter, “Please pick a wall.”);
if (eRef != null && eRef.Element != null)
{
MessageBox.Show(eRef.Element.Name);
}
return Result.Succeeded;
Then open a document, execute the external tools command, select a wall and you can see the pop up dialog. Also you can see prompt in the status bar.
Comments
Leave a comment