public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
{
Document revitDoc = commandData.Application.ActiveUIDocument.Document;
View view = revitDoc.ActiveView ;
List<Element> duct =new FilteredElementCollector(revitDoc).OfCategory(BuiltInCategory.OST_DuctCurves).ToList();
List<Element> ductTerminal = new FilteredElementCollector(revitDoc).OfCategory(BuiltInCategory.OST_DuctTerminal).ToList();
List<Element> ductFitting = new FilteredElementCollector(revitDoc).OfCategory(BuiltInCategory.OST_DuctFitting).ToList();
List<Element> ductInsulation = new FilteredElementCollector(revitDoc).OfCategory(BuiltInCategory.OST_DuctInsulations).ToList();
List<Element> ductLining = new FilteredElementCollector(revitDoc).OfCategory(BuiltInCategory.OST_DuctLinings).ToList();
List<Element> ductAccessory = new FilteredElementCollector(revitDoc).OfCategory(BuiltInCategory.OST_DuctAccessory).ToList();
ICollection<ElementId> hideElementSet = new List<ElementId>();
ICollection<ElementId> unHideElementSet = new List<ElementId>();
using (Transaction tr = new Transaction(revitDoc, "duct"))
{
tr.Start();
foreach (Element element in duct)
{
if (element.CanBeHidden(view))
{
if (element.IsHidden(view))
{
unHideElementSet.Add(element.Id);
}
hideElementSet.Add(element.Id);
}
}
foreach (Element element in ductTerminal)
{
if (element.CanBeHidden(view))
{
if (element.IsHidden(view))
{
unHideElementSet.Add(element.Id);
}
hideElementSet.Add(element.Id);
}
}
foreach (Element element in ductFitting)
{
if (element.CanBeHidden(view))
{
if (element.IsHidden(view))
{
unHideElementSet.Add(element.Id);
}
hideElementSet.Add(element.Id);
}
}
foreach (Element element in ductInsulation)
{
if (element.CanBeHidden(view))
{
if (element.IsHidden(view))
{
unHideElementSet.Add(element.Id);
}
hideElementSet.Add(element.Id);
}
}
foreach (Element element in ductLining)
{
if (element.CanBeHidden(view))
{
if (element.IsHidden(view))
{
unHideElementSet.Add(element.Id);
}
hideElementSet.Add(element.Id);
}
}
foreach (Element element in ductAccessory)
{
if (element.CanBeHidden(view))
{
if (element.IsHidden(view))
{
unHideElementSet.Add(element.Id);
}
hideElementSet.Add(element.Id);
}
}
if (hideElementSet.Any())
{
view.HideElements(hideElementSet);
}
if (unHideElementSet.Any())
{
view.UnhideElements(unHideElementSet);
}
hideElementSet.Clear();
unHideElementSet.Clear();
tr.Commit();
}
return Result.Succeeded;
}
revit二次开发一键隐藏风管
最新推荐文章于 2024-11-12 23:38:30 发布