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

 

相关文章:

  • 2021-06-12
  • 2022-12-23
  • 2021-07-27
  • 2021-08-26
  • 2021-10-09
  • 2021-08-12
猜你喜欢
  • 2022-12-23
  • 2022-01-14
  • 2021-07-14
  • 2022-12-23
  • 2021-05-17
  • 2021-09-13
  • 2021-08-16
相关资源
相似解决方案