463 lines
14 KiB
C#
463 lines
14 KiB
C#
|
|
using Autodesk.Revit.DB;
|
|||
|
|
using Autodesk.Revit.UI;
|
|||
|
|
using Autodesk.Revit.UI.Selection;
|
|||
|
|
|
|||
|
|
namespace Szmedi.RvKits.DisplayTools
|
|||
|
|
{
|
|||
|
|
#region 隐藏对象
|
|||
|
|
|
|||
|
|
internal class HideElementsHandler : IExternalEventHandler
|
|||
|
|
{
|
|||
|
|
public void Execute(UIApplication app)
|
|||
|
|
{
|
|||
|
|
//RevitCommandId cmdId = RevitCommandId.LookupPostableCommandId(PostableCommand.HideElements);
|
|||
|
|
//app.PostCommand(cmdId);
|
|||
|
|
UIDocument uidoc = app.ActiveUIDocument;
|
|||
|
|
Document doc = app.ActiveUIDocument.Document;
|
|||
|
|
Selection selection = uidoc.Selection;
|
|||
|
|
ICollection<ElementId> selectedIds = selection.GetElementIds();
|
|||
|
|
using Transaction trans = new(doc);
|
|||
|
|
trans.Start("隐藏对象");
|
|||
|
|
uidoc.Document.ActiveView.HideElements(selectedIds);
|
|||
|
|
trans.Commit();
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
public string GetName()
|
|||
|
|
{
|
|||
|
|
return "隐藏对象";
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
#endregion 隐藏对象
|
|||
|
|
|
|||
|
|
#region 隐藏类别
|
|||
|
|
|
|||
|
|
internal class HideCategoriesHandler : IExternalEventHandler
|
|||
|
|
{
|
|||
|
|
public void Execute(UIApplication app)
|
|||
|
|
{
|
|||
|
|
//RevitCommandId cmdId = RevitCommandId.LookupPostableCommandId(PostableCommand.HideCategory);
|
|||
|
|
//app.PostCommand(cmdId);
|
|||
|
|
UIDocument uidoc = app.ActiveUIDocument;
|
|||
|
|
Document doc = app.ActiveUIDocument.Document;
|
|||
|
|
//得到选择的对象
|
|||
|
|
Selection selection = uidoc.Selection;
|
|||
|
|
//得到选择对象的ID
|
|||
|
|
ICollection<ElementId> SelectedIds = selection.GetElementIds();
|
|||
|
|
Element seledElement = null;
|
|||
|
|
using Transaction trans = new(doc);
|
|||
|
|
trans.Start("隐藏类别");
|
|||
|
|
//未选择对象时
|
|||
|
|
if (0 == SelectedIds.Count)
|
|||
|
|
{
|
|||
|
|
//TaskDialog.Show("提示", "请选择单个或多个对象");
|
|||
|
|
}
|
|||
|
|
else
|
|||
|
|
{
|
|||
|
|
foreach (ElementId elemId in SelectedIds)
|
|||
|
|
{
|
|||
|
|
seledElement = doc.GetElement(elemId);
|
|||
|
|
|
|||
|
|
Category category = seledElement.Category;
|
|||
|
|
//下方已经应用过滤器,此处新建收集器避免遍历时使用下方已赋值的过滤器
|
|||
|
|
FilteredElementCollector collector = new(doc);
|
|||
|
|
|
|||
|
|
BuiltInCategory enumCategory = (BuiltInCategory)category.Id.IntegerValue;
|
|||
|
|
collector.OfCategory(enumCategory);
|
|||
|
|
//相当于在VV菜单中关闭类别显示
|
|||
|
|
//uidoc.doc.ActiveView.SetCategoryHidden(category.Id,true);
|
|||
|
|
|
|||
|
|
uidoc.Document.ActiveView.HideElements(collector.ToElementIds());
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
trans.Commit();
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
public string GetName()
|
|||
|
|
{
|
|||
|
|
return "隐藏类别";
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
#endregion 隐藏类别
|
|||
|
|
|
|||
|
|
#region 隔离对象
|
|||
|
|
|
|||
|
|
internal class IsolateElementsHandler : IExternalEventHandler
|
|||
|
|
{
|
|||
|
|
public void Execute(UIApplication app)
|
|||
|
|
{
|
|||
|
|
UIDocument uidoc = app.ActiveUIDocument;
|
|||
|
|
Document doc = app.ActiveUIDocument.Document;
|
|||
|
|
Selection selection = uidoc.Selection;
|
|||
|
|
ICollection<ElementId> selectedIds = selection.GetElementIds();
|
|||
|
|
|
|||
|
|
ElementClassFilter instanceFitler = new(typeof(FamilyInstance));
|
|||
|
|
ElementClassFilter hostFilter = new(typeof(HostObject));
|
|||
|
|
LogicalOrFilter orFilter = new(instanceFitler, hostFilter);
|
|||
|
|
|
|||
|
|
FilteredElementCollector collector = new FilteredElementCollector(doc).WherePasses(orFilter);
|
|||
|
|
|
|||
|
|
collector.Excluding(selectedIds);
|
|||
|
|
using Transaction trans = new(doc);
|
|||
|
|
trans.Start("隔离对象");
|
|||
|
|
if (selectedIds.Count == 0)
|
|||
|
|
{
|
|||
|
|
}
|
|||
|
|
else
|
|||
|
|
{
|
|||
|
|
uidoc.ActiveView.HideElements(collector.ToElementIds());
|
|||
|
|
|
|||
|
|
trans.Commit();
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
public string GetName()
|
|||
|
|
{
|
|||
|
|
return "隔离对象";
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
#endregion 隔离对象
|
|||
|
|
|
|||
|
|
#region 隔离类别
|
|||
|
|
|
|||
|
|
internal class IsolateCategoriesHandler : IExternalEventHandler
|
|||
|
|
{
|
|||
|
|
public void Execute(UIApplication app)
|
|||
|
|
{
|
|||
|
|
UIDocument uidoc = app.ActiveUIDocument;
|
|||
|
|
Document doc = app.ActiveUIDocument.Document;
|
|||
|
|
//得到选择的对象
|
|||
|
|
Selection selection = uidoc.Selection;
|
|||
|
|
//得到选择对象的ID
|
|||
|
|
ICollection<ElementId> selectedIds = selection.GetElementIds();
|
|||
|
|
|
|||
|
|
ElementClassFilter instanceFitler = new(typeof(FamilyInstance));
|
|||
|
|
ElementClassFilter hostFilter = new(typeof(HostObject));
|
|||
|
|
LogicalOrFilter andFilter = new(instanceFitler, hostFilter);
|
|||
|
|
|
|||
|
|
FilteredElementCollector collector = new FilteredElementCollector(doc).WherePasses(andFilter);
|
|||
|
|
Element seledElement = null;
|
|||
|
|
using Transaction trans = new(doc);
|
|||
|
|
trans.Start("隔离类别");
|
|||
|
|
//未选择对象时
|
|||
|
|
if (selectedIds.Count == 0)
|
|||
|
|
{
|
|||
|
|
//TaskDialog.Show("提示", "请选择单个或多个对象");
|
|||
|
|
}
|
|||
|
|
else
|
|||
|
|
{
|
|||
|
|
uidoc.ActiveView.HideElements(collector.ToElementIds());
|
|||
|
|
foreach (ElementId elemId in selectedIds)
|
|||
|
|
{
|
|||
|
|
seledElement = doc.GetElement(elemId);
|
|||
|
|
|
|||
|
|
Category category = seledElement.Category;
|
|||
|
|
|
|||
|
|
FilteredElementCollector collection = new(doc);
|
|||
|
|
|
|||
|
|
BuiltInCategory enumCategory = (BuiltInCategory)category.Id.IntegerValue;
|
|||
|
|
|
|||
|
|
collection.OfCategory(enumCategory).ToElementIds();
|
|||
|
|
|
|||
|
|
uidoc.Document.ActiveView.UnhideElements(collection.ToElementIds());
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
trans.Commit();
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
public string GetName()
|
|||
|
|
{
|
|||
|
|
return "隔离类别";
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
#endregion 隔离类别
|
|||
|
|
|
|||
|
|
#region 显示隐藏
|
|||
|
|
|
|||
|
|
internal class RevealHiddenHandler : IExternalEventHandler
|
|||
|
|
{
|
|||
|
|
public void Execute(UIApplication app)
|
|||
|
|
{
|
|||
|
|
Document doc = app.ActiveUIDocument.Document;
|
|||
|
|
|
|||
|
|
ElementClassFilter instanceFilter = new(typeof(FamilyInstance));
|
|||
|
|
FilteredElementCollector collection = new(doc);
|
|||
|
|
|
|||
|
|
doc.Invoke(
|
|||
|
|
ts =>
|
|||
|
|
{
|
|||
|
|
try
|
|||
|
|
{
|
|||
|
|
if (doc.IsFamilyDocument)
|
|||
|
|
{
|
|||
|
|
ElementClassFilter formFilter = new(typeof(GenericForm));
|
|||
|
|
ElementClassFilter combineFilter = new(typeof(GeomCombination));
|
|||
|
|
|
|||
|
|
LogicalOrFilter logicalOrFilter = new([instanceFilter, formFilter, combineFilter]);
|
|||
|
|
collection.WherePasses(logicalOrFilter);
|
|||
|
|
}
|
|||
|
|
else
|
|||
|
|
{
|
|||
|
|
ElementClassFilter hostFilter = new(typeof(HostObject));
|
|||
|
|
//逻辑过滤器
|
|||
|
|
LogicalOrFilter orFilter = new(instanceFilter, hostFilter);
|
|||
|
|
//收集器应用过滤器(未应用过滤器,收集器会报错)
|
|||
|
|
collection.WherePasses(orFilter);
|
|||
|
|
}
|
|||
|
|
foreach (Element item in collection)
|
|||
|
|
{
|
|||
|
|
if (item.IsHidden(doc.ActiveView))
|
|||
|
|
{
|
|||
|
|
doc.ActiveView.UnhideElements([item.Id]);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
catch (System.Exception)
|
|||
|
|
{
|
|||
|
|
|
|||
|
|
throw;
|
|||
|
|
}
|
|||
|
|
},
|
|||
|
|
"显示隐藏");
|
|||
|
|
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
public string GetName()
|
|||
|
|
{
|
|||
|
|
return "显示隐藏";
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
#endregion 显示隐藏
|
|||
|
|
|
|||
|
|
#region 对象剖切
|
|||
|
|
|
|||
|
|
internal class ElementsSectionHandler : IExternalEventHandler
|
|||
|
|
{
|
|||
|
|
public void Execute(UIApplication app)
|
|||
|
|
{
|
|||
|
|
UIDocument uidoc = app.ActiveUIDocument;
|
|||
|
|
Document doc = uidoc.Document;
|
|||
|
|
//Selection selection = uidoc.Selection;
|
|||
|
|
//View view = doc.ActiveView;
|
|||
|
|
//Element elem = doc.GetElement(uidoc.Selection.PickObject(ObjectType.Element, "请选择一个构件"));
|
|||
|
|
//if (view is View3D)
|
|||
|
|
//{
|
|||
|
|
// BoundingBoxXYZ box = elem.get_BoundingBox(null);
|
|||
|
|
//}
|
|||
|
|
//else
|
|||
|
|
//{
|
|||
|
|
//}
|
|||
|
|
//Transaction trans = new Transaction(doc, "剖面框");
|
|||
|
|
//trans.Start();
|
|||
|
|
//view.SetSectionBox(box);
|
|||
|
|
|
|||
|
|
//trans.Commit();
|
|||
|
|
//uidoc.ActiveView = view3D;
|
|||
|
|
RevitCommandId cmdId = RevitCommandId.LookupPostableCommandId(PostableCommand.SelectionBox);
|
|||
|
|
app.PostCommand(cmdId);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
public string GetName()
|
|||
|
|
{
|
|||
|
|
return "对象剖切";
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
#endregion 对象剖切
|
|||
|
|
|
|||
|
|
#region 锁定对象
|
|||
|
|
|
|||
|
|
internal class PinElementsHandler : IExternalEventHandler
|
|||
|
|
{
|
|||
|
|
public void Execute(UIApplication app)
|
|||
|
|
{
|
|||
|
|
//RevitCommandId cmdId = RevitCommandId.LookupPostableCommandId(PostableCommand.Pin);
|
|||
|
|
//app.PostCommand(cmdId);
|
|||
|
|
UIDocument uidoc = app.ActiveUIDocument;
|
|||
|
|
Document doc = app.ActiveUIDocument.Document;
|
|||
|
|
Selection selection = uidoc.Selection;
|
|||
|
|
ICollection<ElementId> selectedIds = selection.GetElementIds();
|
|||
|
|
using Transaction trans = new(doc);
|
|||
|
|
trans.Start("锁定对象");
|
|||
|
|
if (selectedIds.Count == 0)
|
|||
|
|
{
|
|||
|
|
}
|
|||
|
|
else
|
|||
|
|
{
|
|||
|
|
foreach (ElementId eleId in selectedIds)
|
|||
|
|
{
|
|||
|
|
Element ele = doc.GetElement(eleId);
|
|||
|
|
if (ele.Pinned == false)
|
|||
|
|
{
|
|||
|
|
ele.Pinned = true;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
trans.Commit();
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
public string GetName()
|
|||
|
|
{
|
|||
|
|
return "锁定对象";
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
#endregion 锁定对象
|
|||
|
|
|
|||
|
|
#region 解锁全部
|
|||
|
|
|
|||
|
|
internal class UnpinAllElementsHandler : IExternalEventHandler
|
|||
|
|
{
|
|||
|
|
public void Execute(UIApplication app)
|
|||
|
|
{
|
|||
|
|
Document doc = app.ActiveUIDocument.Document;
|
|||
|
|
UIDocument uidoc = app.ActiveUIDocument;
|
|||
|
|
|
|||
|
|
ElementClassFilter instanceFitler = new(typeof(FamilyInstance));
|
|||
|
|
ElementClassFilter hostFilter = new(typeof(HostObject));
|
|||
|
|
|
|||
|
|
LogicalOrFilter andFilter = new(instanceFitler, hostFilter);
|
|||
|
|
|
|||
|
|
FilteredElementCollector collector = new FilteredElementCollector(doc).WherePasses(andFilter);
|
|||
|
|
|
|||
|
|
ICollection<ElementId> elesIds = [];
|
|||
|
|
|
|||
|
|
View view = uidoc.Document.ActiveView;
|
|||
|
|
using Transaction t = new(doc);
|
|||
|
|
t.Start("解锁全部");
|
|||
|
|
foreach (Element elem in collector)
|
|||
|
|
{
|
|||
|
|
if (elem.Pinned)
|
|||
|
|
{
|
|||
|
|
elem.Pinned = false;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
t.Commit();
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
public string GetName()
|
|||
|
|
{
|
|||
|
|
return "解锁全部";
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
#endregion 解锁全部
|
|||
|
|
|
|||
|
|
#region 锁定类别
|
|||
|
|
|
|||
|
|
internal class PinCategoriesHandler : IExternalEventHandler
|
|||
|
|
{
|
|||
|
|
public void Execute(UIApplication app)
|
|||
|
|
{
|
|||
|
|
UIDocument uidoc = app.ActiveUIDocument;
|
|||
|
|
Document doc = app.ActiveUIDocument.Document;
|
|||
|
|
//得到选择的对象
|
|||
|
|
Selection selection = uidoc.Selection;
|
|||
|
|
//得到选择对象的ID
|
|||
|
|
ICollection<ElementId> SelectedIds = selection.GetElementIds();
|
|||
|
|
|
|||
|
|
Element seledElement = null;
|
|||
|
|
using Transaction trans = new(doc);
|
|||
|
|
trans.Start("锁定类别");
|
|||
|
|
//未选择对象时
|
|||
|
|
if (0 == SelectedIds.Count)
|
|||
|
|
{
|
|||
|
|
//TaskDialog.Show("提示", "请选择单个或多个对象");
|
|||
|
|
}
|
|||
|
|
else
|
|||
|
|
{
|
|||
|
|
foreach (ElementId elemId in SelectedIds)
|
|||
|
|
{
|
|||
|
|
seledElement = doc.GetElement(elemId);
|
|||
|
|
|
|||
|
|
Category category = seledElement.Category;
|
|||
|
|
|
|||
|
|
FilteredElementCollector collector = new(doc);
|
|||
|
|
|
|||
|
|
BuiltInCategory enumCategory = (BuiltInCategory)category.Id.IntegerValue;
|
|||
|
|
collector.OfCategory(enumCategory);
|
|||
|
|
|
|||
|
|
foreach (Element elem in collector)
|
|||
|
|
{
|
|||
|
|
if (elem.Pinned == false)
|
|||
|
|
{
|
|||
|
|
elem.Pinned = true;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
trans.Commit();
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
public string GetName()
|
|||
|
|
{
|
|||
|
|
return "锁定类别";
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
#endregion 锁定类别
|
|||
|
|
|
|||
|
|
#region 解锁类别
|
|||
|
|
|
|||
|
|
internal class UnpinCategoriesHandler : IExternalEventHandler
|
|||
|
|
{
|
|||
|
|
public void Execute(UIApplication app)
|
|||
|
|
{
|
|||
|
|
UIDocument uidoc = app.ActiveUIDocument;
|
|||
|
|
Document doc = app.ActiveUIDocument.Document;
|
|||
|
|
//得到选择的对象
|
|||
|
|
Selection selection = uidoc.Selection;
|
|||
|
|
//得到选择对象的ID
|
|||
|
|
ICollection<ElementId> SelectedIds = selection.GetElementIds();
|
|||
|
|
|
|||
|
|
Element seledElement = null;
|
|||
|
|
using Transaction trans = new(doc);
|
|||
|
|
trans.Start("解锁类别");
|
|||
|
|
//未选择对象时
|
|||
|
|
if (0 == SelectedIds.Count)
|
|||
|
|
{
|
|||
|
|
//TaskDialog.Show("提示", "请选择单个或多个对象");
|
|||
|
|
}
|
|||
|
|
else
|
|||
|
|
{
|
|||
|
|
foreach (ElementId elemId in SelectedIds)
|
|||
|
|
{
|
|||
|
|
seledElement = doc.GetElement(elemId);
|
|||
|
|
|
|||
|
|
Category category = seledElement.Category;
|
|||
|
|
|
|||
|
|
FilteredElementCollector collector = new(doc);
|
|||
|
|
|
|||
|
|
BuiltInCategory enumCategory = (BuiltInCategory)category.Id.IntegerValue;
|
|||
|
|
collector.OfCategory(enumCategory);
|
|||
|
|
|
|||
|
|
foreach (Element elem in collector)
|
|||
|
|
{
|
|||
|
|
if (elem.Pinned)
|
|||
|
|
{
|
|||
|
|
elem.Pinned = false;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
trans.Commit();
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
public string GetName()
|
|||
|
|
{
|
|||
|
|
return "解锁类别";
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
#endregion 解锁类别
|
|||
|
|
}
|