Revit二次开发示例:DeleteObject
生活随笔
收集整理的這篇文章主要介紹了
Revit二次开发示例:DeleteObject
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
在本例中,通過命令可以刪除選中的元素。
需要注意的是要在代碼中加入Transaction,否則的話會出現Modifying? is forbidden because the document has no open transaction的錯誤。
?
#region Namespaces using System; using System.Collections; using System.Collections.Generic; using System.Diagnostics; using Autodesk.Revit.ApplicationServices; using Autodesk.Revit.Attributes; using Autodesk.Revit.DB; using Autodesk.Revit.UI; using Autodesk.Revit.UI.Selection; #endregionnamespace DeleteObject {[Autodesk.Revit.Attributes.Transaction(TransactionMode.Manual)][Autodesk.Revit.Attributes.Regeneration(RegenerationOption.Manual)][Autodesk.Revit.Attributes.Journaling(JournalingMode.NoCommandData)]public class Command : IExternalCommand{public Result Execute(ExternalCommandData commandData,ref string message,ElementSet elements){UIApplication revit = commandData.Application;ElementSet collection = revit.ActiveUIDocument.Selection.Elements;if (collection.Size < 1){message = "Plase select object(s) before delete.";return Result.Cancelled;}bool error = true;try{error = true;IEnumerator e = collection.GetEnumerator();Transaction transactoin = new Transaction(commandData.Application.ActiveUIDocument.Document, "DeleteObject");transactoin.Start();bool MoreValue = e.MoveNext();while (MoreValue){Element component = e.Current as Element;revit.ActiveUIDocument.Document.Delete(component.Id);MoreValue = e.MoveNext();}transactoin.Commit();error = false;}catch (Exception){foreach (Element c in collection){elements.Insert(c);}message = "object(s) can't be deleted.";return Result.Failed;}finally{if (error){TaskDialog.Show("Error", "Delete failed.");}}return Result.Succeeded;}} }轉載于:https://www.cnblogs.com/xpvincent/p/3605574.html
總結
以上是生活随笔為你收集整理的Revit二次开发示例:DeleteObject的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: LLVM language 参考手册 翻
- 下一篇: python在windows安装para