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;
}

本文参与腾讯云自媒体分享计划,欢迎正在阅读的你也加入,一起分享。

发表于

我来说两句

0 条评论
登录 后参与评论

相关文章

扫描关注云+社区