Start transaction not working with Revit 2014

时间:2022-05-03
本文章向大家介绍Start transaction not working with Revit 2014,主要内容包括其使用实例、应用技巧、基本知识点总结和需要注意事项,具有一定的参考价值,需要的朋友可以参考一下。
You're right, it's not being used correctly.

The Transaction needs to take place inside the Idling event.

The button click handler and Idling event handler should look something like this in Revit 2014:



void revitApp_Idling(object sender, Autodesk.Revit.UI.Events.IdlingEventArgs e)
{
UIApplication uiapp = sender as UIApplication;

UIDocument uidoc = uiapp.ActiveUIDocument;

ElementSet elems = uidoc.Selection.Elements;

if (elems != null)
{
label1.Text = elems.Size.ToString() + " items selected.";
}
else
{
label1.Text = "No elements selected.";
}

if (shouldRun)
{
using (Transaction trans = new Transaction(uidoc.Document, "Hide elements"))
{
trans.Start();
uidoc.Document.ActiveView.HideElements((from Element el in elems select el.Id).ToList());
uidoc.RefreshActiveView();
trans.Commit();
}

shouldRun = false;
}
}

private void button1_Click(object sender, EventArgs e)
{
shouldRun = true;
}