using Autodesk.Revit.Attributes;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;
using Autodesk.Revit.UI.Selection;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace LearnTime
{
//必备写法
[Transaction(TransactionMode.Manual)]
[Journaling(JournalingMode.NoCommandData)]
[Regeneration(RegenerationOption.Manual)]
//删除选择集
class _11_delect : IExternalCommand
{
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
{
UIDocument uiDoc = commandData.Application.ActiveUIDocument;
Document projectDoc = commandData.Application.ActiveUIDocument.Document;
Selection selection = uiDoc.Selection;
List<Element> collection = selection.GetElementIds().Select(x => projectDoc.GetElement(x) as Element).ToList();
List<ElementId> elementsToDelete = new List<ElementId>();
using (Transaction tran = new Transaction(projectDoc, "Delete the selected elements."))
{
tran.Start();
foreach (Element elem in collection)
{
elementsToDelete.Add(elem.Id);
}
ICollection<ElementId> deletedElements = projectDoc.Delete(elementsToDelete);
tran.Commit();
}
return Result.Succeeded;
}
}
}