学习地址:https://www.bilibili.com/video/BV1mf4y1S72o?p=9
本章内容
- 事务类型
- 事务开始、提交、回滚
- 事务容错处理
事务类型
事务开始、提交、回滚
事务容错处理
实例练习
using System; using System.Collections.Generic; using System.Linq; using System.Text; using Autodesk.Revit.UI; using Autodesk.Revit.DB; using Autodesk.Revit.ApplicationServices; using Autodesk.Revit.Attributes; using System.Windows.Forms; using Autodesk.Revit.UI.Selection; namespace RevitDevTV { /// <summary> /// 事务练习 /// </summary> [TransactionAttribute(TransactionMode.Manual)] [RegenerationAttribute(RegenerationOption.Manual)] public class Trans : IExternalCommand { public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) { UIDocument uiDoc = commandData.Application.ActiveUIDocument; Document doc = uiDoc.Document; TransactionGroup tg = new TransactionGroup(doc, "TG"); tg.Start(); //开启事务 Transaction t1 = new Transaction(doc, "T1"); t1.Start(); //开启事务 Wall.Create(doc, Line.CreateBound(new XYZ(), new XYZ(0, 10, 0)), Level.Create(doc, 0).Id, false); t1.Commit(); TaskDialog.Show("提示", "已生成第一道墙"); Transaction t2 = new Transaction(doc, "T2"); t2.Start(); //开启事务 Wall.Create(doc, Line.CreateBound(new XYZ(), new XYZ(0, 10, 0)), Level.Create(doc, 0).Id, false); t2.Commit(); tg.Assimilate(); //tg.Commit(); Transaction tt = new Transaction(doc,"Transaction"); tt.Start(); SubTransaction st1 = new SubTransaction(doc); st1.Start(); SubTransaction st2 = new SubTransaction(doc); st2.Start(); st2.Commit(); TaskDialog.Show("提示", "t2已提交"); st1.Commit(); TaskDialog.Show("提示", "t1已提交"); tt.Commit(); return Result.Succeeded; } } }