Skip to content

Commit

Permalink
Внес изменения после ревью
Browse files Browse the repository at this point in the history
  • Loading branch information
KGubin committed Jan 15, 2025
1 parent d51b716 commit f421adc
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 61 deletions.
3 changes: 1 addition & 2 deletions src/RevitMarkingElements/Localization/Language.en-GB.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@

<system:String x:Key="MainWindow.Title">Marking of elements</system:String>
<system:String x:Key="MainWindow.CategoriesElements">Element category:</system:String>
<system:String x:Key="MainWindow.HelloCheck">There are no matching elements and lines.</system:String>
<system:String x:Key="MainWindow.TransactionName">Numbering of elements.</system:String>
<system:String x:Key="MainWindow.ErrorNoElements">It is necessary to mark the elements with lines.</system:String>
<system:String x:Key="MainWindow.ErrorNoElements">It is necessary to select the numbering lines.</system:String>
<system:String x:Key="MainWindow.NumberUnmarkedElements">Number unmarked elements</system:String>
<system:String x:Key="MainWindow.RenumberMarkedElements">Renumber already numbered elements</system:String>
<system:String x:Key="MainWindow.ButtonOk">OK</system:String>
Expand Down
3 changes: 1 addition & 2 deletions src/RevitMarkingElements/Localization/Language.en-US.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@

<system:String x:Key="MainWindow.Title">Marking of elements</system:String>
<system:String x:Key="MainWindow.CategoriesElements">Element category:</system:String>
<system:String x:Key="MainWindow.HelloCheck">There are no matching elements and lines.</system:String>
<system:String x:Key="MainWindow.TransactionName">Numbering of elements.</system:String>
<system:String x:Key="MainWindow.ErrorNoElements">It is necessary to mark the elements with lines.</system:String>
<system:String x:Key="MainWindow.ErrorNoElements">It is necessary to select the numbering lines.</system:String>
<system:String x:Key="MainWindow.NumberUnmarkedElements">Number unmarked elements</system:String>
<system:String x:Key="MainWindow.RenumberMarkedElements">Renumber already numbered elements</system:String>
<system:String x:Key="MainWindow.ButtonOk">OK</system:String>
Expand Down
3 changes: 1 addition & 2 deletions src/RevitMarkingElements/Localization/Language.ru-RU.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@

<system:String x:Key="MainWindow.Title">Маркировка элементов</system:String>
<system:String x:Key="MainWindow.CategoriesElements">Категория элементов:</system:String>
<system:String x:Key="MainWindow.HelloCheck">Нет подходящих элементов и линий.</system:String>
<system:String x:Key="MainWindow.TransactionName">Нумерация элементов.</system:String>
<system:String x:Key="MainWindow.ErrorNoElements">Необходимо пометить элементы линиями.</system:String>
<system:String x:Key="MainWindow.ErrorNoElements">Необходимо выбрать линии для нумерации.</system:String>
<system:String x:Key="MainWindow.NumberUnmarkedElements">Нумеровать элементы, не помеченные линиями</system:String>
<system:String x:Key="MainWindow.RenumberMarkedElements">Перенумеровать уже нумерованные</system:String>
<system:String x:Key="MainWindow.ButtonOk">ОК</system:String>
Expand Down
65 changes: 33 additions & 32 deletions src/RevitMarkingElements/Models/RevitRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -17,13 +22,22 @@ public RevitRepository(UIApplication uiApplication) {
public Document Document => ActiveUIDocument.Document;

public List<Category> GetCategoriesWithMarkParam() {
return new FilteredElementCollector(Document)

var markParam = MainViewModel.MarkParam;
List<Category> categories = new List<Category>();

categories = new FilteredElementCollector(Document)
.OfClass(typeof(FamilyInstance))
.WhereElementIsNotElementType()
.Cast<FamilyInstance>()
.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<Element> GetElementsIntersectingLine(List<Element> elements, CurveElement lineElement) {
Expand All @@ -38,57 +52,44 @@ public List<Element> GetElementsIntersectingLine(List<Element> 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<Category>()
.FirstOrDefault(cat => cat.Id == categoryId);
}

public List<Element> GetElements(Category category) {
if(category == null) {
public List<Element> GetElements(ElementId categoryId) {
if(categoryId == null) {
return new List<Element>();
}

FilteredElementCollector collector = new FilteredElementCollector(Document);

return collector
.WherePasses(new ElementCategoryFilter(category.Id))
.WherePasses(new ElementCategoryFilter(categoryId))
.WhereElementIsNotElementType()
.ToElements()
.ToList();
}

public List<CurveElement> GetLinesAndSplines() {
FilteredElementCollector collector = new FilteredElementCollector(Document);
var selectedElementIds = ActiveUIDocument.Selection.GetElementIds();

return collector
.OfClass(typeof(CurveElement))
.Cast<CurveElement>()
if(!selectedElementIds.Any()) {
return new List<CurveElement>();
}

return selectedElementIds
.Select(id => Document.GetElement(id))
.OfType<CurveElement>()
.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) {
Expand Down
2 changes: 1 addition & 1 deletion src/RevitMarkingElements/README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# RevitMarkingElements (Маркировка элементов)
Описание проекта
Нумерация выделенных линией элементов на активном виде или всех доступных элементов

# Сборка проекта
```
Expand Down
38 changes: 18 additions & 20 deletions src/RevitMarkingElements/ViewModels/MainViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<string> _categoriesNames;
private List<Category> _categories;
private ElementId _selectedCategoryId;
private bool _includeUnselected;
private bool _renumberAll;
private List<Element> MarkingElements { get; set; }
private List<CurveElement> Lines { get; set; }

public MainViewModel(
PluginConfig pluginConfig,
Expand All @@ -51,15 +53,17 @@ public string ErrorText {
set => this.RaiseAndSetIfChanged(ref _errorText, value);
}

public List<string> CategoriesNames {
get => _categoriesNames;
set => this.RaiseAndSetIfChanged(ref _categoriesNames, value);
public List<Category> 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;
}
}
Expand All @@ -79,16 +83,11 @@ public bool RenumberAll {
set => this.RaiseAndSetIfChanged(ref _renumberAll, value);
}

public List<Element> MarkingElements { get; set; }
public List<CurveElement> 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() {
Expand All @@ -98,7 +97,7 @@ private void NumberMarkingElements() {
transaction.Start();

int counter = StartingCounter();
var processedElements = ProcessElementsByLines(ref counter);
List<Element> processedElements = ProcessElementsByLines(ref counter);
ProcessUnselectedElements(ref counter, processedElements);

transaction.Commit();
Expand All @@ -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();
}

Expand Down Expand Up @@ -139,7 +137,7 @@ private List<Element> ProcessElementsByLines(ref int counter) {

private int AssignMarksToElements(List<Element> elements, int counter, List<Element> 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);
Expand All @@ -164,7 +162,7 @@ private void ProcessUnselectedElements(ref int counter, List<Element> processedE

private int GetLastMarkNumber() {
var filledMarks = MarkingElements
.Select(markingElement => markingElement.GetParamValue<string>(_markParam))
.Select(markingElement => markingElement.GetParamValue<string>(MarkParam))
.Where(mark => !string.IsNullOrEmpty(mark) && int.TryParse(mark, out _))
.Select(mark => int.Parse(mark))
.ToList();
Expand Down
6 changes: 4 additions & 2 deletions src/RevitMarkingElements/Views/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,10 @@
Text="{DynamicResource MainWindow.CategoriesElements}"
Margin="0,0,0,5" />
<ComboBox
ItemsSource="{Binding CategoriesNames}"
SelectedItem="{Binding SelectedCategoryName}"
ItemsSource="{Binding Categories}"
DisplayMemberPath="Name"
SelectedValue="{Binding SelectedCategoryName}"
SelectedValuePath="Name"
Margin="0,0,0,10" />

<CheckBox
Expand Down

0 comments on commit f421adc

Please sign in to comment.