Revit二次开发之删除元素

mac2024-11-05  20

using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using Autodesk.Revit.DB; using Autodesk.Revit.UI; using Autodesk.Revit.Attributes; using Autodesk.Revit.UI.Selection; namespace ClassLibrary1 { [Autodesk.Revit.Attributes.Transaction(TransactionMode.Manual)] [Autodesk.Revit.Attributes.Regeneration(RegenerationOption.Manual)] public class GetElement : IExternalCommand { public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) { UIDocument uidoc = commandData.Application.ActiveUIDocument; Document doc = uidoc.Document; Selection selection = uidoc.Selection; #region 删除 ICollection<ElementId> ids = selection.GetElementIds(); using (Transaction ts = new Transaction(doc)) { ts.Start("删除元素"); foreach(var item in ids) { ICollection<ElementId> ids_delete = doc.Delete(item); } ts.Commit(); } #endregion return Result.Succeeded; } } }

 

最新回复(0)