188 lines
8.0 KiB
C#
188 lines
8.0 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Collections.ObjectModel;
|
|
using System.Linq;
|
|
using System.Runtime.InteropServices;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using System.Windows.Data;
|
|
|
|
using Autodesk.Revit.DB;
|
|
|
|
using CommunityToolkit.Mvvm.ComponentModel;
|
|
using CommunityToolkit.Mvvm.Input;
|
|
|
|
using Nice3point.Revit.Toolkit.External.Handlers;
|
|
|
|
using Szmedi.RevitToolkit.Approval.Models;
|
|
|
|
|
|
namespace Szmedi.RevitToolkit.Approval.ViewModels
|
|
{
|
|
public partial class ReviewMetroSignViewModel : ObservableObject
|
|
{
|
|
public ReviewMetroSignViewModel(Document doc)
|
|
{
|
|
var allElements = doc.OfParentModelCollector();
|
|
if (allElements == null)
|
|
{
|
|
return;
|
|
}
|
|
var reviewItems = allElements.Select(e => new ReviewItem(e)).OrderBy(item => item.Element.Category.Name);
|
|
Signs = GlobalAssists.GetMetroSigns();
|
|
Items = [.. reviewItems];
|
|
var cv = CollectionViewSource.GetDefaultView(Items);
|
|
cv.GroupDescriptions.Add(new PropertyGroupDescription("Sign"));
|
|
//cv.SortDescriptions.Add(new System.ComponentModel.SortDescription("Sign", System.ComponentModel.ListSortDirection.Ascending));
|
|
}
|
|
[ObservableProperty]
|
|
public partial List<string> Signs { get; set; }
|
|
//[ObservableProperty]
|
|
//private Dictionary<string, List<Element>> keyValues;
|
|
public ObservableCollection<ReviewItem> Items { get; set; }
|
|
|
|
|
|
|
|
[RelayCommand]
|
|
private void LocationElement(object obj)
|
|
{
|
|
if (obj is Element elem)
|
|
{
|
|
RvApp.Handler.Raise(
|
|
uiapp =>
|
|
{
|
|
var uidoc = uiapp.ActiveUIDocument;
|
|
uidoc.ShowElements([elem.Id]);
|
|
uidoc.Selection.SetElementIds([elem.Id]);
|
|
});
|
|
}
|
|
}
|
|
[RelayCommand]
|
|
private void UpdateCode()
|
|
{
|
|
RvApp.Handler
|
|
.Raise(
|
|
uiapp =>
|
|
{
|
|
StringBuilder sb = new StringBuilder();
|
|
var doc = uiapp.ActiveUIDocument.Document;
|
|
var allClassifications = GlobalAssists.GetMetroClassificationModels();
|
|
doc.Invoke(
|
|
ts =>
|
|
{
|
|
var elems = doc.OfAllModelCollector().ToList();
|
|
foreach (var item in elems)
|
|
{
|
|
var paras = item.GetParameters("深圳构件标识");
|
|
var categoryName = string.Empty;
|
|
|
|
if (paras.Count > 0)
|
|
{
|
|
foreach (var param in paras)
|
|
{
|
|
if (param.HasValue)
|
|
{
|
|
categoryName = param.GetValue().ToString();
|
|
if (!string.IsNullOrEmpty(categoryName))
|
|
{
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
if (string.IsNullOrEmpty(categoryName))
|
|
{
|
|
sb.AppendLine(
|
|
$"元素{item.Id} {item.Name}的深圳构件标识参数未设置,无法更新分类编码。");
|
|
continue;
|
|
}
|
|
var codesParams = item.GetParameters("AM-100-EAM分类编码");
|
|
var classification =
|
|
allClassifications.FirstOrDefault(d => d.CategoryName == categoryName);
|
|
if (classification == null)
|
|
{
|
|
sb.AppendLine(
|
|
$"元素{item.Id} {item.Name}的深圳构件标识参数值为{categoryName},未找到对应的分类编码。");
|
|
continue;
|
|
}
|
|
if (codesParams.Count == 0)
|
|
{
|
|
sb.AppendLine(
|
|
$"元素{item.Id} {item.Name}的深圳构件标识参数值为{categoryName},未找到分类编码参数。");
|
|
continue;
|
|
}
|
|
if (codesParams.Count > 0)
|
|
{
|
|
var codeParams = codesParams.Where(p => !p.IsReadOnly).ToList();
|
|
foreach (var param in codeParams)
|
|
{
|
|
if (param.HasValue && param.GetValue().ToString() != classification?.Code)
|
|
{
|
|
param.SetValue(classification?.Code);
|
|
}
|
|
|
|
}
|
|
}
|
|
}
|
|
},
|
|
"更新标识的编码");
|
|
if (sb.Length > 0)
|
|
{
|
|
System.Windows.MessageBox.Show(sb.ToString(), "更新编码结果", System.Windows.MessageBoxButton.OK,
|
|
System.Windows.MessageBoxImage.Information);
|
|
}
|
|
else
|
|
{
|
|
System.Windows.MessageBox.Show("所有元素的编码已更新。", "更新编码结果", System.Windows.MessageBoxButton.OK,
|
|
System.Windows.MessageBoxImage.Information);
|
|
}
|
|
});
|
|
}
|
|
|
|
[RelayCommand]
|
|
private void ShowElement(object obj)
|
|
{
|
|
if (obj is not ReviewItem model)
|
|
{
|
|
return;
|
|
}
|
|
if (model.Element.IsValidObject)
|
|
{
|
|
|
|
RvApp.Handler.Raise(uiapp =>
|
|
{
|
|
var uidoc = uiapp.ActiveUIDocument;
|
|
var doc = uidoc.Document;
|
|
List<ElementId> ids = [model.Element.Id];
|
|
//if (model.Element.IsHidden(uidoc.ActiveView))
|
|
//{
|
|
// return;
|
|
//}
|
|
if (uidoc.ActiveView is not View3D view3d)
|
|
{
|
|
view3d =
|
|
doc.QueryElementsByType<View3D>()
|
|
.FirstOrDefault(e => FilteredElementCollector.IsViewValidForElementIteration(doc, e.Id)) as View3D;
|
|
}
|
|
|
|
uidoc.ActiveView = view3d;
|
|
|
|
doc.Invoke(_ =>
|
|
{
|
|
var box = model.Element.get_BoundingBox(uidoc.ActiveGraphicalView);
|
|
var uiView = uidoc.GetOpenUIViews().FirstOrDefault(v => v.ViewId == uidoc.ActiveGraphicalView.Id);
|
|
XYZ extendXyz = new(1, 1, 1);
|
|
uiView?.ZoomAndCenterRectangle(box.Min - extendXyz, box.Max + extendXyz);
|
|
uidoc.Selection.SetElementIds(ids);
|
|
});
|
|
|
|
});
|
|
}
|
|
else
|
|
{
|
|
Items.Remove(model);
|
|
}
|
|
}
|
|
}
|
|
}
|