From f421adcd40cc24fcef2e6446cf51591f27e1f08e Mon Sep 17 00:00:00 2001 From: KGubin Date: Wed, 15 Jan 2025 15:51:50 +0300 Subject: [PATCH] =?UTF-8?q?=D0=92=D0=BD=D0=B5=D1=81=20=D0=B8=D0=B7=D0=BC?= =?UTF-8?q?=D0=B5=D0=BD=D0=B5=D0=BD=D0=B8=D1=8F=20=D0=BF=D0=BE=D1=81=D0=BB?= =?UTF-8?q?=D0=B5=20=D1=80=D0=B5=D0=B2=D1=8C=D1=8E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Localization/Language.en-GB.xaml | 3 +- .../Localization/Language.en-US.xaml | 3 +- .../Localization/Language.ru-RU.xaml | 3 +- .../Models/RevitRepository.cs | 65 ++++++++++--------- src/RevitMarkingElements/README.md | 2 +- .../ViewModels/MainViewModel.cs | 38 +++++------ .../Views/MainWindow.xaml | 6 +- 7 files changed, 59 insertions(+), 61 deletions(-) diff --git a/src/RevitMarkingElements/Localization/Language.en-GB.xaml b/src/RevitMarkingElements/Localization/Language.en-GB.xaml index 6803b6ae..9edfaf73 100644 --- a/src/RevitMarkingElements/Localization/Language.en-GB.xaml +++ b/src/RevitMarkingElements/Localization/Language.en-GB.xaml @@ -6,9 +6,8 @@ Marking of elements Element category: - There are no matching elements and lines. Numbering of elements. - It is necessary to mark the elements with lines. + It is necessary to select the numbering lines. Number unmarked elements Renumber already numbered elements OK diff --git a/src/RevitMarkingElements/Localization/Language.en-US.xaml b/src/RevitMarkingElements/Localization/Language.en-US.xaml index 81e2517a..1137bed5 100644 --- a/src/RevitMarkingElements/Localization/Language.en-US.xaml +++ b/src/RevitMarkingElements/Localization/Language.en-US.xaml @@ -6,9 +6,8 @@ Marking of elements Element category: - There are no matching elements and lines. Numbering of elements. - It is necessary to mark the elements with lines. + It is necessary to select the numbering lines. Number unmarked elements Renumber already numbered elements OK diff --git a/src/RevitMarkingElements/Localization/Language.ru-RU.xaml b/src/RevitMarkingElements/Localization/Language.ru-RU.xaml index 1016ab43..20b60c9a 100644 --- a/src/RevitMarkingElements/Localization/Language.ru-RU.xaml +++ b/src/RevitMarkingElements/Localization/Language.ru-RU.xaml @@ -6,9 +6,8 @@ Маркировка элементов Категория элементов: - Нет подходящих элементов и линий. Нумерация элементов. - Необходимо пометить элементы линиями. + Необходимо выбрать линии для нумерации. Нумеровать элементы, не помеченные линиями Перенумеровать уже нумерованные ОК diff --git a/src/RevitMarkingElements/Models/RevitRepository.cs b/src/RevitMarkingElements/Models/RevitRepository.cs index b7f79d50..f1093809 100644 --- a/src/RevitMarkingElements/Models/RevitRepository.cs +++ b/src/RevitMarkingElements/Models/RevitRepository.cs @@ -5,6 +5,11 @@ using Autodesk.Revit.DB; using Autodesk.Revit.UI; +using dosymep.Bim4Everyone; +using dosymep.Revit; + +using RevitMarkingElements.ViewModels; + namespace RevitMarkingElements.Models { internal class RevitRepository { public RevitRepository(UIApplication uiApplication) { @@ -17,13 +22,22 @@ public RevitRepository(UIApplication uiApplication) { public Document Document => ActiveUIDocument.Document; public List GetCategoriesWithMarkParam() { - return new FilteredElementCollector(Document) + + var markParam = MainViewModel.MarkParam; + List categories = new List(); + + categories = new FilteredElementCollector(Document) .OfClass(typeof(FamilyInstance)) .WhereElementIsNotElementType() + .Cast() + .Where(element => element.IsExistsParam(markParam)) .Select(element => element.Category) - .Where(category => category != null && HasMarkParameter(category)) - .Distinct() + .Where(category => category != null) + .GroupBy(category => category.Id) + .Select(group => group.First()) .ToList(); + + return categories; } public List GetElementsIntersectingLine(List elements, CurveElement lineElement) { @@ -38,57 +52,44 @@ public List GetElementsIntersectingLine(List elements, CurveEl return false; var center = (bbox.Min + bbox.Max) / 2.0; - return line.Project(center)?.Distance < 13.3; + var lineToObjectDistance = 13.3; + return line.Project(center)?.Distance < lineToObjectDistance; }).ToList(); } - public bool HasMarkParameter(Category category) { - var collector = new FilteredElementCollector(Document) - .OfCategoryId(category.Id) - .WhereElementIsNotElementType() - .FirstOrDefault(); - - if(collector != null) { - var param = collector.get_Parameter(BuiltInParameter.ALL_MODEL_MARK); - return param != null; - } - - return false; - } - public Transaction CreateTransaction(string transactionName) { return new Transaction(Document, transactionName); } - public Category GetCategoryById(ElementId categoryId) { - return Document.Settings.Categories - .Cast() - .FirstOrDefault(cat => cat.Id == categoryId); - } - - public List GetElements(Category category) { - if(category == null) { + public List GetElements(ElementId categoryId) { + if(categoryId == null) { return new List(); } FilteredElementCollector collector = new FilteredElementCollector(Document); return collector - .WherePasses(new ElementCategoryFilter(category.Id)) + .WherePasses(new ElementCategoryFilter(categoryId)) .WhereElementIsNotElementType() .ToElements() .ToList(); } public List GetLinesAndSplines() { - FilteredElementCollector collector = new FilteredElementCollector(Document); + var selectedElementIds = ActiveUIDocument.Selection.GetElementIds(); - return collector - .OfClass(typeof(CurveElement)) - .Cast() + if(!selectedElementIds.Any()) { + return new List(); + } + + return selectedElementIds + .Select(id => Document.GetElement(id)) + .OfType() .Where(curveElement => curveElement.GeometryCurve != null && - (curveElement is ModelLine || curveElement is ModelNurbSpline)).ToList(); + (curveElement is ModelLine || curveElement is ModelNurbSpline)) + .Reverse() + .ToList(); } public XYZ GetElementCoordinates(Element element) { diff --git a/src/RevitMarkingElements/README.md b/src/RevitMarkingElements/README.md index ef8e5bf4..d1a40f6a 100644 --- a/src/RevitMarkingElements/README.md +++ b/src/RevitMarkingElements/README.md @@ -1,5 +1,5 @@ # RevitMarkingElements (Маркировка элементов) -Описание проекта +Нумерация выделенных линией элементов на активном виде или всех доступных элементов # Сборка проекта ``` diff --git a/src/RevitMarkingElements/ViewModels/MainViewModel.cs b/src/RevitMarkingElements/ViewModels/MainViewModel.cs index bb531f12..13b54fae 100644 --- a/src/RevitMarkingElements/ViewModels/MainViewModel.cs +++ b/src/RevitMarkingElements/ViewModels/MainViewModel.cs @@ -16,19 +16,21 @@ namespace RevitMarkingElements.ViewModels { internal class MainViewModel : BaseViewModel { + public const BuiltInParameter MarkParam = BuiltInParameter.ALL_MODEL_MARK; + private const BuiltInCategory _structuralColumns = BuiltInCategory.OST_StructuralColumns; + private readonly PluginConfig _pluginConfig; private readonly RevitRepository _revitRepository; private readonly ILocalizationService _localizationService; - private const BuiltInParameter _markParam = BuiltInParameter.ALL_MODEL_MARK; - private const BuiltInCategory _structuralColumns = BuiltInCategory.OST_StructuralColumns; - private string _errorText; private string _selectedCategoryName; - private List _categoriesNames; + private List _categories; private ElementId _selectedCategoryId; private bool _includeUnselected; private bool _renumberAll; + private List MarkingElements { get; set; } + private List Lines { get; set; } public MainViewModel( PluginConfig pluginConfig, @@ -51,15 +53,17 @@ public string ErrorText { set => this.RaiseAndSetIfChanged(ref _errorText, value); } - public List CategoriesNames { - get => _categoriesNames; - set => this.RaiseAndSetIfChanged(ref _categoriesNames, value); + public List Categories { + get => _categories; + set => this.RaiseAndSetIfChanged(ref _categories, value); } + public string SelectedCategoryName { get => _selectedCategoryName; set { this.RaiseAndSetIfChanged(ref _selectedCategoryName, value); - SelectedCategoryId = _revitRepository.GetCategoriesWithMarkParam() + + SelectedCategoryId = _categories .FirstOrDefault(category => category.Name == value)?.Id; } } @@ -79,16 +83,11 @@ public bool RenumberAll { set => this.RaiseAndSetIfChanged(ref _renumberAll, value); } - public List MarkingElements { get; set; } - public List Lines { get; set; } - private void LoadCategories() { var allCategories = _revitRepository.GetCategoriesWithMarkParam(); - SelectedCategoryName = allCategories - .FirstOrDefault(x => x.Id.GetIdValue() == (int) _structuralColumns)?.Name; - - CategoriesNames = allCategories.Select(x => x.Name).Distinct().ToList(); + Categories = allCategories.ToList(); + SelectedCategoryName = allCategories.FirstOrDefault(x => x.Id.AsBuiltInCategory() == _structuralColumns)?.Name; } private void NumberMarkingElements() { @@ -98,7 +97,7 @@ private void NumberMarkingElements() { transaction.Start(); int counter = StartingCounter(); - var processedElements = ProcessElementsByLines(ref counter); + List processedElements = ProcessElementsByLines(ref counter); ProcessUnselectedElements(ref counter, processedElements); transaction.Commit(); @@ -107,8 +106,7 @@ private void NumberMarkingElements() { } private void PrepareMarkingElements() { - var category = _revitRepository.GetCategoryById(SelectedCategoryId); - MarkingElements = _revitRepository.GetElements(category); + MarkingElements = _revitRepository.GetElements(SelectedCategoryId); Lines = _revitRepository.GetLinesAndSplines(); } @@ -139,7 +137,7 @@ private List ProcessElementsByLines(ref int counter) { private int AssignMarksToElements(List elements, int counter, List processedElements) { foreach(var markingElement in elements) { - var markParam = markingElement.GetParam(_markParam); + var markParam = markingElement.GetParam(MarkParam); if(markParam != null && !markParam.IsReadOnly) { markParam.Set($"{counter++}"); processedElements.Add(markingElement); @@ -164,7 +162,7 @@ private void ProcessUnselectedElements(ref int counter, List processedE private int GetLastMarkNumber() { var filledMarks = MarkingElements - .Select(markingElement => markingElement.GetParamValue(_markParam)) + .Select(markingElement => markingElement.GetParamValue(MarkParam)) .Where(mark => !string.IsNullOrEmpty(mark) && int.TryParse(mark, out _)) .Select(mark => int.Parse(mark)) .ToList(); diff --git a/src/RevitMarkingElements/Views/MainWindow.xaml b/src/RevitMarkingElements/Views/MainWindow.xaml index e9e68f1a..9e101d1b 100644 --- a/src/RevitMarkingElements/Views/MainWindow.xaml +++ b/src/RevitMarkingElements/Views/MainWindow.xaml @@ -43,8 +43,10 @@ Text="{DynamicResource MainWindow.CategoriesElements}" Margin="0,0,0,5" />