2024-09-22 11:05:41 +08:00
|
|
|
|
using System.Windows;
|
|
|
|
|
|
using Autodesk.Revit.DB;
|
|
|
|
|
|
using CommunityToolkit.Mvvm.ComponentModel;
|
|
|
|
|
|
using CommunityToolkit.Mvvm.Input;
|
|
|
|
|
|
using Nice3point.Revit.Toolkit.External.Handlers;
|
|
|
|
|
|
|
2026-02-22 20:03:42 +08:00
|
|
|
|
namespace ShrlAlgoToolkit.RevitAddins.DrawSheet;
|
2024-09-22 11:05:41 +08:00
|
|
|
|
|
|
|
|
|
|
public partial class VisibilityViewModel : ObservableObject
|
|
|
|
|
|
{
|
|
|
|
|
|
public ActionEventHandler VisibilityHandler { get; } = new();
|
|
|
|
|
|
|
|
|
|
|
|
[ObservableProperty]
|
2025-10-04 08:52:23 +08:00
|
|
|
|
public partial bool WallChecked { get; set; }
|
2024-09-22 11:05:41 +08:00
|
|
|
|
|
|
|
|
|
|
[ObservableProperty]
|
2025-10-04 08:52:23 +08:00
|
|
|
|
public partial bool FloorChecked { get; set; }
|
2024-09-22 11:05:41 +08:00
|
|
|
|
|
|
|
|
|
|
[ObservableProperty]
|
2025-10-04 08:52:23 +08:00
|
|
|
|
public partial bool BeamChecked { get; set; }
|
2024-09-22 11:05:41 +08:00
|
|
|
|
|
|
|
|
|
|
[ObservableProperty]
|
2025-10-04 08:52:23 +08:00
|
|
|
|
public partial bool MechanicalChecked { get; set; }
|
2024-09-22 11:05:41 +08:00
|
|
|
|
|
|
|
|
|
|
[ObservableProperty]
|
2025-10-04 08:52:23 +08:00
|
|
|
|
public partial bool ColumnChecked { get; set; }
|
2024-09-22 11:05:41 +08:00
|
|
|
|
|
|
|
|
|
|
[ObservableProperty]
|
2025-10-04 08:52:23 +08:00
|
|
|
|
public partial bool PlumbingChecked { get; set; }
|
2024-09-22 11:05:41 +08:00
|
|
|
|
|
|
|
|
|
|
[ObservableProperty]
|
2025-10-04 08:52:23 +08:00
|
|
|
|
public partial bool CableTrayChecked { get; set; }
|
2024-09-22 11:05:41 +08:00
|
|
|
|
|
|
|
|
|
|
[ObservableProperty]
|
2025-10-04 08:52:23 +08:00
|
|
|
|
public partial bool ConduitChecked { get; set; }
|
2024-09-22 11:05:41 +08:00
|
|
|
|
|
|
|
|
|
|
partial void OnBeamCheckedChanged(bool value)
|
|
|
|
|
|
{
|
|
|
|
|
|
VisibilityHandler.Raise(uiapp =>
|
|
|
|
|
|
{
|
|
|
|
|
|
UIDocument uidoc = uiapp.ActiveUIDocument;
|
|
|
|
|
|
var doc = uidoc.Document;
|
|
|
|
|
|
if (doc.ActiveView.ViewTemplateId != ElementId.InvalidElementId)
|
|
|
|
|
|
{
|
|
|
|
|
|
MessageBox.Show("当前视图已应用视图样板,无法修改其可见性", "提示");
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
doc.Invoke(
|
|
|
|
|
|
_ =>
|
|
|
|
|
|
{
|
2024-10-08 16:21:39 +08:00
|
|
|
|
foreach (var builtInCategory in beamCategory)
|
|
|
|
|
|
{
|
|
|
|
|
|
var categoryId = Category.GetCategory(doc, builtInCategory).Id;
|
|
|
|
|
|
|
|
|
|
|
|
uidoc.ActiveView.SetCategoryHidden(categoryId, value == false);
|
|
|
|
|
|
}
|
2024-09-22 11:05:41 +08:00
|
|
|
|
},
|
|
|
|
|
|
"梁显隐"
|
|
|
|
|
|
);
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
partial void OnCableTrayCheckedChanged(bool value)
|
|
|
|
|
|
{
|
|
|
|
|
|
VisibilityHandler.Raise(uiapp =>
|
|
|
|
|
|
{
|
|
|
|
|
|
UIDocument uidoc = uiapp.ActiveUIDocument;
|
|
|
|
|
|
var doc = uidoc.Document;
|
|
|
|
|
|
if (doc.ActiveView.ViewTemplateId != ElementId.InvalidElementId)
|
|
|
|
|
|
{
|
|
|
|
|
|
MessageBox.Show("当前视图已应用视图样板,无法修改其可见性", "提示");
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
doc.Invoke(
|
|
|
|
|
|
_ =>
|
|
|
|
|
|
{
|
2024-10-08 16:21:39 +08:00
|
|
|
|
foreach (var builtInCategory in cabletrayCategory)
|
|
|
|
|
|
{
|
|
|
|
|
|
var categoryId = Category.GetCategory(doc, builtInCategory).Id;
|
|
|
|
|
|
|
|
|
|
|
|
uidoc.ActiveView.SetCategoryHidden(categoryId, value == false);
|
|
|
|
|
|
}
|
2024-09-22 11:05:41 +08:00
|
|
|
|
},
|
|
|
|
|
|
"桥架显隐"
|
|
|
|
|
|
);
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
partial void OnColumnCheckedChanged(bool value)
|
|
|
|
|
|
{
|
|
|
|
|
|
VisibilityHandler.Raise(uiapp =>
|
|
|
|
|
|
{
|
|
|
|
|
|
UIDocument uidoc = uiapp.ActiveUIDocument;
|
|
|
|
|
|
var doc = uidoc.Document;
|
|
|
|
|
|
if (doc.ActiveView.ViewTemplateId != ElementId.InvalidElementId)
|
|
|
|
|
|
{
|
|
|
|
|
|
MessageBox.Show("当前视图已应用视图样板,无法修改其可见性", "提示");
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
doc.Invoke(
|
|
|
|
|
|
_ =>
|
|
|
|
|
|
{
|
2024-10-08 16:21:39 +08:00
|
|
|
|
foreach (var builtInCategory in columnsCategory)
|
|
|
|
|
|
{
|
|
|
|
|
|
var categoryId = Category.GetCategory(doc, builtInCategory).Id;
|
|
|
|
|
|
|
|
|
|
|
|
uidoc.ActiveView.SetCategoryHidden(categoryId, value == false);
|
|
|
|
|
|
}
|
2024-09-22 11:05:41 +08:00
|
|
|
|
},
|
|
|
|
|
|
"柱显隐"
|
|
|
|
|
|
);
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
partial void OnWallCheckedChanged(bool value)
|
|
|
|
|
|
{
|
|
|
|
|
|
VisibilityHandler.Raise(uiapp =>
|
|
|
|
|
|
{
|
|
|
|
|
|
UIDocument uidoc = uiapp.ActiveUIDocument;
|
|
|
|
|
|
var doc = uidoc.Document;
|
|
|
|
|
|
if (doc.ActiveView.ViewTemplateId != ElementId.InvalidElementId)
|
|
|
|
|
|
{
|
|
|
|
|
|
MessageBox.Show("当前视图已应用视图样板,无法修改其可见性", "提示");
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
doc.Invoke(
|
|
|
|
|
|
_ =>
|
|
|
|
|
|
{
|
2024-10-08 16:21:39 +08:00
|
|
|
|
foreach (var builtInCategory in wallCategory)
|
|
|
|
|
|
{
|
|
|
|
|
|
var categoryId = Category.GetCategory(doc, builtInCategory).Id;
|
|
|
|
|
|
|
|
|
|
|
|
uidoc.ActiveView.SetCategoryHidden(categoryId, value == false);
|
|
|
|
|
|
}
|
2024-09-22 11:05:41 +08:00
|
|
|
|
},
|
|
|
|
|
|
"墙显隐"
|
|
|
|
|
|
);
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
partial void OnFloorCheckedChanged(bool value)
|
|
|
|
|
|
{
|
|
|
|
|
|
VisibilityHandler.Raise(uiapp =>
|
|
|
|
|
|
{
|
|
|
|
|
|
UIDocument uidoc = uiapp.ActiveUIDocument;
|
|
|
|
|
|
var doc = uidoc.Document;
|
|
|
|
|
|
if (doc.ActiveView.ViewTemplateId != ElementId.InvalidElementId)
|
|
|
|
|
|
{
|
|
|
|
|
|
MessageBox.Show("当前视图已应用视图样板,无法修改其可见性", "提示");
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
doc.Invoke(
|
|
|
|
|
|
_ =>
|
|
|
|
|
|
{
|
2024-10-08 16:21:39 +08:00
|
|
|
|
foreach (var builtInCategory in floorCategory)
|
|
|
|
|
|
{
|
|
|
|
|
|
var categoryId = Category.GetCategory(doc, builtInCategory).Id;
|
|
|
|
|
|
|
|
|
|
|
|
uidoc.ActiveView.SetCategoryHidden(categoryId, value == false);
|
|
|
|
|
|
}
|
2024-09-22 11:05:41 +08:00
|
|
|
|
},
|
|
|
|
|
|
"楼板显隐"
|
|
|
|
|
|
);
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
partial void OnConduitCheckedChanged(bool value)
|
|
|
|
|
|
{
|
|
|
|
|
|
VisibilityHandler.Raise(uiapp =>
|
|
|
|
|
|
{
|
|
|
|
|
|
UIDocument uidoc = uiapp.ActiveUIDocument;
|
|
|
|
|
|
var doc = uidoc.Document;
|
|
|
|
|
|
if (doc.ActiveView.ViewTemplateId != ElementId.InvalidElementId)
|
|
|
|
|
|
{
|
|
|
|
|
|
MessageBox.Show("当前视图已应用视图样板,无法修改其可见性", "提示");
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
doc.Invoke(
|
|
|
|
|
|
_ =>
|
|
|
|
|
|
{
|
2024-10-08 16:21:39 +08:00
|
|
|
|
foreach (var builtInCategory in conduitCategory)
|
|
|
|
|
|
{
|
|
|
|
|
|
var categoryId = Category.GetCategory(doc, builtInCategory).Id;
|
|
|
|
|
|
|
|
|
|
|
|
uidoc.ActiveView.SetCategoryHidden(categoryId, value == false);
|
|
|
|
|
|
}
|
2024-09-22 11:05:41 +08:00
|
|
|
|
},
|
|
|
|
|
|
"线管显隐"
|
|
|
|
|
|
);
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
partial void OnMechanicalCheckedChanged(bool value)
|
|
|
|
|
|
{
|
|
|
|
|
|
VisibilityHandler.Raise(uiapp =>
|
|
|
|
|
|
{
|
|
|
|
|
|
UIDocument uidoc = uiapp.ActiveUIDocument;
|
|
|
|
|
|
var doc = uidoc.Document;
|
|
|
|
|
|
if (doc.ActiveView.ViewTemplateId != ElementId.InvalidElementId)
|
|
|
|
|
|
{
|
|
|
|
|
|
MessageBox.Show("当前视图已应用视图样板,无法修改其可见性", "提示");
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
doc.Invoke(
|
|
|
|
|
|
_ =>
|
|
|
|
|
|
{
|
2024-10-08 16:21:39 +08:00
|
|
|
|
foreach (var builtInCategory in mechanicalCategory)
|
|
|
|
|
|
{
|
|
|
|
|
|
var categoryId = Category.GetCategory(doc, builtInCategory).Id;
|
|
|
|
|
|
|
|
|
|
|
|
uidoc.ActiveView.SetCategoryHidden(categoryId, value == false);
|
|
|
|
|
|
}
|
2024-09-22 11:05:41 +08:00
|
|
|
|
},
|
|
|
|
|
|
"暖通显隐"
|
|
|
|
|
|
);
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
partial void OnPlumbingCheckedChanged(bool value)
|
|
|
|
|
|
{
|
|
|
|
|
|
VisibilityHandler.Raise(uiapp =>
|
|
|
|
|
|
{
|
|
|
|
|
|
UIDocument uidoc = uiapp.ActiveUIDocument;
|
|
|
|
|
|
var doc = uidoc.Document;
|
|
|
|
|
|
if (doc.ActiveView.ViewTemplateId != ElementId.InvalidElementId)
|
|
|
|
|
|
{
|
|
|
|
|
|
MessageBox.Show("当前视图已应用视图样板,无法修改其可见性", "提示");
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
doc.Invoke(
|
|
|
|
|
|
_ =>
|
|
|
|
|
|
{
|
2024-10-08 16:21:39 +08:00
|
|
|
|
foreach (var builtInCategory in pipingCategory)
|
|
|
|
|
|
{
|
|
|
|
|
|
var categoryId = Category.GetCategory(doc, builtInCategory).Id;
|
|
|
|
|
|
|
|
|
|
|
|
uidoc.ActiveView.SetCategoryHidden(categoryId, value == false);
|
|
|
|
|
|
}
|
2024-09-22 11:05:41 +08:00
|
|
|
|
},
|
|
|
|
|
|
"给排水显隐"
|
|
|
|
|
|
);
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public VisibilityViewModel(UIApplication uiapp)
|
|
|
|
|
|
{
|
|
|
|
|
|
UpdateCheckedState(uiapp.ActiveUIDocument.Document);
|
|
|
|
|
|
uiapp.ViewActivated -= Uiapp_ViewActivated;
|
|
|
|
|
|
uiapp.ViewActivated += Uiapp_ViewActivated;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void Uiapp_ViewActivated(object sender, Autodesk.Revit.UI.Events.ViewActivatedEventArgs e)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (!e.Document.IsFamilyDocument)
|
|
|
|
|
|
{
|
|
|
|
|
|
UpdateCheckedState(e.Document);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// true为可见,false为不可见
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="doc"></param>
|
|
|
|
|
|
/// <param name="builtInCategories"></param>
|
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
|
private static bool GetCheckedStatue(Document doc, params BuiltInCategory[] builtInCategories)
|
|
|
|
|
|
{
|
|
|
|
|
|
foreach (var cate in builtInCategories)
|
|
|
|
|
|
{
|
|
|
|
|
|
var category = Category.GetCategory(doc, cate);
|
|
|
|
|
|
return !doc.ActiveView.GetCategoryHidden(category.Id);
|
|
|
|
|
|
}
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
2024-10-08 16:21:39 +08:00
|
|
|
|
readonly BuiltInCategory[] wallCategory = [BuiltInCategory.OST_Walls];
|
|
|
|
|
|
readonly BuiltInCategory[] beamCategory = [BuiltInCategory.OST_StructuralFraming];
|
|
|
|
|
|
readonly BuiltInCategory[] floorCategory = [BuiltInCategory.OST_Floors];
|
|
|
|
|
|
readonly BuiltInCategory[] columnsCategory = [
|
|
|
|
|
|
BuiltInCategory.OST_StructuralColumns,
|
|
|
|
|
|
BuiltInCategory.OST_Columns];
|
|
|
|
|
|
readonly BuiltInCategory[] mechanicalCategory = [
|
|
|
|
|
|
BuiltInCategory.OST_DuctCurves,
|
|
|
|
|
|
BuiltInCategory.OST_DuctAccessory,
|
|
|
|
|
|
BuiltInCategory.OST_DuctFitting,
|
|
|
|
|
|
BuiltInCategory.OST_DuctInsulations,
|
|
|
|
|
|
BuiltInCategory.OST_DuctTerminal,
|
|
|
|
|
|
BuiltInCategory.OST_FlexDuctCurves,
|
|
|
|
|
|
BuiltInCategory.OST_PlaceHolderDucts,BuiltInCategory.OST_MechanicalEquipment];
|
|
|
|
|
|
readonly BuiltInCategory[] pipingCategory = [
|
|
|
|
|
|
BuiltInCategory.OST_PipeCurves,
|
|
|
|
|
|
BuiltInCategory.OST_PipeFitting,
|
|
|
|
|
|
BuiltInCategory.OST_PipeAccessory,
|
|
|
|
|
|
BuiltInCategory.OST_PipeInsulations,
|
|
|
|
|
|
BuiltInCategory.OST_Sprinklers,
|
|
|
|
|
|
BuiltInCategory.OST_FlexPipeCurves,
|
|
|
|
|
|
BuiltInCategory.OST_PlaceHolderPipes,
|
|
|
|
|
|
BuiltInCategory.OST_PlumbingFixtures];
|
|
|
|
|
|
readonly BuiltInCategory[] cabletrayCategory = [
|
|
|
|
|
|
BuiltInCategory.OST_CableTray,
|
|
|
|
|
|
BuiltInCategory.OST_CableTrayFitting,];
|
|
|
|
|
|
readonly BuiltInCategory[] conduitCategory = [
|
|
|
|
|
|
BuiltInCategory.OST_Conduit,
|
|
|
|
|
|
BuiltInCategory.OST_ConduitFitting,];
|
2024-09-22 11:05:41 +08:00
|
|
|
|
|
|
|
|
|
|
private void UpdateCheckedState(Document doc)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (doc.ActiveView.ViewTemplateId != ElementId.InvalidElementId)
|
|
|
|
|
|
{
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
2024-10-08 16:21:39 +08:00
|
|
|
|
WallChecked = GetCheckedStatue(doc, wallCategory);
|
|
|
|
|
|
BeamChecked = GetCheckedStatue(doc, beamCategory);
|
|
|
|
|
|
FloorChecked = GetCheckedStatue(doc, floorCategory);
|
|
|
|
|
|
ColumnChecked = GetCheckedStatue(doc, columnsCategory);
|
|
|
|
|
|
MechanicalChecked = GetCheckedStatue(doc, mechanicalCategory);
|
|
|
|
|
|
PlumbingChecked = GetCheckedStatue(doc, pipingCategory);
|
|
|
|
|
|
CableTrayChecked = GetCheckedStatue(doc, cabletrayCategory);
|
|
|
|
|
|
ConduitChecked = GetCheckedStatue(doc, conduitCategory);
|
2024-09-22 11:05:41 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
[RelayCommand]
|
|
|
|
|
|
private void Closing()
|
|
|
|
|
|
{
|
|
|
|
|
|
VisibilityHandler.Raise(uiapp => uiapp.ViewActivated -= Uiapp_ViewActivated);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|