添加项目文件。
This commit is contained in:
99
RevitKits/WBSCoder/ComponentCodeAddedCheckerViewModel.cs
Normal file
99
RevitKits/WBSCoder/ComponentCodeAddedCheckerViewModel.cs
Normal file
@@ -0,0 +1,99 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using Autodesk.Revit.DB;
|
||||
using Autodesk.Revit.UI;
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
using CommunityToolkit.Mvvm.Input;
|
||||
|
||||
namespace Sai.Common.Shared.WBSCoder
|
||||
{
|
||||
public partial class ComponentCodeAddedCheckerViewModel : ObservableObject
|
||||
{
|
||||
public ComponentCodeAddedCheckerViewModel(CheckCodeViewModel viewModel)
|
||||
{
|
||||
uidoc = viewModel.Uidoc;
|
||||
pjFileName = viewModel.ProjectPath;
|
||||
allElements = viewModel.AllElements;
|
||||
LastTaskItems = viewModel.LastTaskItems;
|
||||
}
|
||||
|
||||
private readonly IList<Element> allElements;
|
||||
private readonly string pjFileName;
|
||||
private readonly UIDocument uidoc;
|
||||
|
||||
public ObservableCollection<TaskItem> LastTaskItems;
|
||||
private RelayCommand<object> showElement;
|
||||
|
||||
|
||||
public ObservableCollection<Element> ElementsWithErrorCode { get; set; } = new();
|
||||
|
||||
private bool CanCheckComponent()
|
||||
{
|
||||
//检查构件是否存在没有编码的情况
|
||||
return pjFileName != null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 检查构件是否都编码
|
||||
/// </summary>
|
||||
/// <param name="obj"></param>
|
||||
[RelayCommand(CanExecute = nameof(CanCheckComponent))]
|
||||
private void CheckComponents(object obj)
|
||||
{
|
||||
ElementsWithErrorCode.Clear();
|
||||
foreach (var ele in allElements)
|
||||
{
|
||||
bool hasCoded = false;
|
||||
var temp = ele.get_Parameter(BuiltInParameter.ALL_MODEL_MARK)?.AsString();
|
||||
if (temp == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
string code = WbsCoderUtils.FormatWbsCode(temp);
|
||||
foreach (var task in LastTaskItems)
|
||||
{
|
||||
if (task.WBSCode == code)
|
||||
{
|
||||
hasCoded = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!hasCoded)
|
||||
{
|
||||
ElementsWithErrorCode.Add(ele);
|
||||
}
|
||||
//var select = from task in LastTaskItems
|
||||
// where task.WBSCode == code
|
||||
// select task;
|
||||
//if (!param.HasValue || select.Count() == 0)
|
||||
//{
|
||||
// ElementsWithErrorCode.Add(ele);
|
||||
//}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 定位元素
|
||||
/// </summary>
|
||||
/// <param name="obj"></param>
|
||||
[RelayCommand]
|
||||
private void LocationElement(object obj)
|
||||
{
|
||||
try
|
||||
{
|
||||
Element element = (Element)obj;
|
||||
List<ElementId> ids = new List<ElementId>();
|
||||
ids.Add(element.Id);
|
||||
uidoc.Selection.SetElementIds(ids);
|
||||
uidoc.ShowElements(element);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
TaskDialog.Show("定位失败", $"{ex.Message}");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user