Files
ShrlAlgoToolkit/RvAddinTest/HideElementsAllViews.cs
2024-09-22 11:05:41 +08:00

49 lines
1.7 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Autodesk.Revit.Attributes;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;
namespace RvAddinTest
{
[Transaction(TransactionMode.Manual)]
[Regeneration(RegenerationOption.Manual)]
internal class HideElementsAllViews : IExternalCommand
{
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
{
//程序UI界面
UIApplication uiapp = commandData.Application;
//获取元素(选择) 显示元素 视图(活动视图)管理(对象)
UIDocument uidoc = uiapp.ActiveUIDocument;
//程序
Autodesk.Revit.ApplicationServices.Application app = uiapp.Application;
//获取位置和场地 视图(多个视图)管理 获取元素Revit 项目里的全部元素)
Document doc = uidoc.Document;
//获取所有打开文档
DocumentSet docset = uiapp.Application.Documents;
//当前视图
View view = doc.ActiveView;
IEnumerable<View> col = new FilteredElementCollector(doc).OfClass(typeof(View))
.WhereElementIsNotElementType()
.Cast<View>()
.Where(v => !v.IsTemplate);
using (Transaction ts = new Transaction(doc, "隐藏"))
{
ts.Start();
foreach (View v in col)
{
v.HideElements(uidoc.Selection.GetElementIds());
}
ts.Commit();
}
return Result.Succeeded;
}
}
}