Message 1 of 6
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
My code works but I don't believe it's as efficient as it could be. Specifically the Try/catch area of the code. If I don't try/catch each line separately it misses some of the doors. Like to reduce the regeneration time too if possible. Any pointers are appreciated. Thanks.
// Get doors
FilteredElementCollector collector = new FilteredElementCollector(doc);
List<Element> coll = collector.OfClass(typeof(FamilyInstance))
.OfCategory(BuiltInCategory.OST_Doors)
.ToList();
// Filtered element collector is iterable
foreach (Element e in coll)
{
// Get the parameter name
Parameter s_parameter = e.LookupParameter("Swing Angle");
Parameter s1_parameter = e.LookupParameter("Swing Angle_Door 1");
Parameter s2_parameter = e.LookupParameter("Swing Angle_Door 2");
using (Transaction t = new Transaction(doc, "parameters"))
// Modify document within a transaction
using (Transaction tx = new Transaction(doc))
{
tx.Start("Change door swing angles to 45");
try
{
s_parameter.Set(0.785398163);
}
catch { }
try
{
s1_parameter.Set(0.785398163);
}
catch { }
try
{
s2_parameter.Set(0.785398163);
}
catch { }
tx.Commit();
}
}
TaskDialog.Show("Completed", "Door swings changed to 45°.");
return Result.Succeeded;
Solved! Go to Solution.