Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RevitMarkingElements: Создание плагина #141

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions .github/workflows/publish.RevitMarkingElements.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: publish RevitMarkingElements

on:
workflow_dispatch:
pull_request:
types: [ closed, synchronize, review_requested ]
branches: [ main, master ]
paths:
- '**RevitMarkingElements**.cs'
- '**RevitMarkingElements**.xaml'

env:
plugin-name: "RevitMarkingElements"

jobs:
build:
name: build
runs-on: windows-latest
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0

# Install the .NET workload
- name: Install .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: 8.0.x

# Add DevExrepress package source: https://nuget.devexpress.com/
- name: Add DevExpress package source
run: dotnet nuget add source https://nuget.devexpress.com/api -n DXFeed -u DevExpress -p ${{ secrets.DEVEXPRESS_FEED_AUTHORIZATION_KEY }}

- name: Run './build.cmd '
run: ./build.cmd publish --profile ${{ env.plugin-name }} --pull-request-merged ${{ github.event.pull_request.merged }} --extensions-app-token ${{ secrets.EXTENSIONS_APP_TOKEN }} --revit-plugins-app-token ${{ secrets.REVIT_PLUGINS_APP_TOKEN }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
15 changes: 15 additions & 0 deletions .nuke/parameters.RevitMarkingElements.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"$schema": "./build.schema.json",
"Solution": "RevitPlugins.sln",
"PluginName": "RevitMarkingElements",
"PublishDirectory": "03.KR.extension\\КР.tab\\bin",
"RevitVersions": [
"Rv2022",
"Rv2023",
"Rv2024"
],
"IconUrl": "https://icons8.com/icon/59856/pencil",
"BundleName": "Маркировка элементов",
"BundleType": "InvokeButton",
"BundleOutput": "03.KR.extension\\КР.tab\\Документация.panel\\Маркировка.pulldown"
}
16 changes: 16 additions & 0 deletions RevitPlugins.sln
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "RevitValueModifier", "src\R
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "RevitMirroredElements", "src\RevitMirroredElements\RevitMirroredElements.csproj", "{827319DD-D76C-4757-9DF0-220BCB852135}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "RevitMarkingElements", "src\RevitMarkingElements\RevitMarkingElements.csproj", "{9107CDD3-CC16-4AC3-A811-A0C29D415F2A}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
D2020|x64 = D2020|x64
Expand Down Expand Up @@ -950,6 +952,20 @@ Global
{827319DD-D76C-4757-9DF0-220BCB852135}.Debug|x64.Build.0 = D2020|x64
{827319DD-D76C-4757-9DF0-220BCB852135}.Release|x64.ActiveCfg = D2020|x64
{827319DD-D76C-4757-9DF0-220BCB852135}.Release|x64.Build.0 = D2020|x64
{9107CDD3-CC16-4AC3-A811-A0C29D415F2A}.D2020|x64.ActiveCfg = D2020|x64
{9107CDD3-CC16-4AC3-A811-A0C29D415F2A}.D2020|x64.Build.0 = D2020|x64
{9107CDD3-CC16-4AC3-A811-A0C29D415F2A}.D2021|x64.ActiveCfg = D2021|x64
{9107CDD3-CC16-4AC3-A811-A0C29D415F2A}.D2021|x64.Build.0 = D2021|x64
{9107CDD3-CC16-4AC3-A811-A0C29D415F2A}.D2022|x64.ActiveCfg = D2022|x64
{9107CDD3-CC16-4AC3-A811-A0C29D415F2A}.D2022|x64.Build.0 = D2022|x64
{9107CDD3-CC16-4AC3-A811-A0C29D415F2A}.D2023|x64.ActiveCfg = D2023|x64
{9107CDD3-CC16-4AC3-A811-A0C29D415F2A}.D2023|x64.Build.0 = D2023|x64
{9107CDD3-CC16-4AC3-A811-A0C29D415F2A}.D2024|x64.ActiveCfg = D2024|x64
{9107CDD3-CC16-4AC3-A811-A0C29D415F2A}.D2024|x64.Build.0 = D2024|x64
{9107CDD3-CC16-4AC3-A811-A0C29D415F2A}.Debug|x64.ActiveCfg = D2020|x64
{9107CDD3-CC16-4AC3-A811-A0C29D415F2A}.Debug|x64.Build.0 = D2020|x64
{9107CDD3-CC16-4AC3-A811-A0C29D415F2A}.Release|x64.ActiveCfg = D2020|x64
{9107CDD3-CC16-4AC3-A811-A0C29D415F2A}.Release|x64.Build.0 = D2020|x64
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
15 changes: 15 additions & 0 deletions src/RevitMarkingElements/Localization/Language.en-GB.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:system="clr-namespace:System;assembly=mscorlib">

<!-- Пример перевода на английский британский язык (google translate) -->

<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.TransactionName">Numbering of elements.</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>
<system:String x:Key="MainWindow.ButtonCancel">Cancel</system:String>
</ResourceDictionary>
15 changes: 15 additions & 0 deletions src/RevitMarkingElements/Localization/Language.en-US.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:system="clr-namespace:System;assembly=mscorlib">

<!-- Пример перевода на английский американский язык (google translate) -->

<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.TransactionName">Numbering of elements.</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>
<system:String x:Key="MainWindow.ButtonCancel">Cancel</system:String>
</ResourceDictionary>
15 changes: 15 additions & 0 deletions src/RevitMarkingElements/Localization/Language.ru-RU.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:system="clr-namespace:System;assembly=mscorlib">

<!-- Пример перевода на русский язык (google translate) -->

<system:String x:Key="MainWindow.Title">Маркировка элементов</system:String>
<system:String x:Key="MainWindow.CategoriesElements">Категория элементов:</system:String>
<system:String x:Key="MainWindow.TransactionName">Нумерация элементов.</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>
<system:String x:Key="MainWindow.ButtonCancel">Отмена</system:String>
</ResourceDictionary>
29 changes: 29 additions & 0 deletions src/RevitMarkingElements/Models/PluginConfig.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
using Autodesk.Revit.DB;

using dosymep.Bim4Everyone;
using dosymep.Bim4Everyone.ProjectConfigs;
using dosymep.Serializers;

using pyRevitLabs.Json;

namespace RevitMarkingElements.Models {
internal class PluginConfig : ProjectConfig<RevitSettings> {
[JsonIgnore] public override string ProjectConfigPath { get; set; }

[JsonIgnore] public override IConfigSerializer Serializer { get; set; }

public static PluginConfig GetPluginConfig() {
return new ProjectConfigBuilder()
.SetSerializer(new ConfigSerializer())
.SetPluginName(nameof(RevitMarkingElements))
.SetRevitVersion(ModuleEnvironment.RevitVersion)
.SetProjectConfigName(nameof(PluginConfig) + ".json")
.Build<PluginConfig>();
}
}

internal class RevitSettings : ProjectSettings {
public override string ProjectName { get; set; }
public ElementId SelectedCategoryId { get; set; }
}
}
109 changes: 109 additions & 0 deletions src/RevitMarkingElements/Models/RevitRepository.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
using System.Collections.Generic;
using System.Linq;

using Autodesk.Revit.ApplicationServices;
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) {
UIApplication = uiApplication;
}

public UIApplication UIApplication { get; }
public UIDocument ActiveUIDocument => UIApplication.ActiveUIDocument;
public Application Application => UIApplication.Application;
public Document Document => ActiveUIDocument.Document;

public List<Category> GetCategoriesWithMarkParam() {

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)
.GroupBy(category => category.Id)
.Select(group => group.First())
.ToList();

return categories;
}

public List<Element> GetElementsIntersectingLine(List<Element> elements, CurveElement lineElement) {
var line = lineElement.GeometryCurve;
if(line == null) {
return new List<Element>();
}

return elements.Where(element => {
var bbox = element.get_BoundingBox(null);
if(bbox == null)
return false;

var center = (bbox.Min + bbox.Max) / 2.0;
var lineToObjectDistance = 13.3;
return line.Project(center)?.Distance < lineToObjectDistance;
}).ToList();
}

public Transaction CreateTransaction(string transactionName) {
return new Transaction(Document, transactionName);
}

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

FilteredElementCollector collector = new FilteredElementCollector(Document);

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

public List<CurveElement> GetLinesAndSplines() {
KGubin marked this conversation as resolved.
Show resolved Hide resolved
var selectedElementIds = ActiveUIDocument.Selection.GetElementIds();

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))
.Reverse()
.ToList();
}

public XYZ GetElementCoordinates(Element element) {
var locationPoint = element.Location as LocationPoint;
if(locationPoint != null) {
return locationPoint.Point;
}

var locationCurve = element.Location as LocationCurve;
if(locationCurve != null) {
return locationCurve.Curve.Evaluate(0.5, true);
}

return null;
}
}
}
12 changes: 12 additions & 0 deletions src/RevitMarkingElements/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# RevitMarkingElements (Маркировка элементов)
Нумерация выделенных линией элементов на активном виде или всех доступных элементов

# Сборка проекта
```
nuke compile --profile RevitMarkingElements
```

# Публикация проекта
```
nuke publish --profile RevitMarkingElements
```
5 changes: 5 additions & 0 deletions src/RevitMarkingElements/RevitMarkingElements.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<UseDevExpress>false</UseDevExpress>
</PropertyGroup>
</Project>
61 changes: 61 additions & 0 deletions src/RevitMarkingElements/RevitMarkingElementsCommand.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Interop;

using Autodesk.Revit.ApplicationServices;
using Autodesk.Revit.Attributes;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;

using dosymep.Bim4Everyone;
using dosymep.Bim4Everyone.SimpleServices;
using dosymep.SimpleServices;
using dosymep.WPF.Views;
using dosymep.Xpf.Core.Ninject;

using Ninject;

using RevitMarkingElements.Models;
using RevitMarkingElements.ViewModels;
using RevitMarkingElements.Views;

namespace RevitMarkingElements {
[Transaction(TransactionMode.Manual)]
public class RevitMarkingElementsCommand : BasePluginCommand {
public RevitMarkingElementsCommand() {
PluginName = "RevitMarkingElements";
}

protected override void Execute(UIApplication uiApplication) {
using(IKernel kernel = uiApplication.CreatePlatformServices()) {
kernel.Bind<RevitRepository>()
.ToSelf()
.InSingletonScope();

kernel.Bind<PluginConfig>()
.ToMethod(c => PluginConfig.GetPluginConfig());

kernel.Bind<MainViewModel>().ToSelf();
kernel.Bind<MainWindow>().ToSelf()
.WithPropertyValue(nameof(Window.DataContext),
c => c.Kernel.Get<MainViewModel>())
.WithPropertyValue(nameof(PlatformWindow.LocalizationService),
c => c.Kernel.Get<ILocalizationService>());

string assemblyName = Assembly.GetExecutingAssembly().GetName().Name;

kernel.UseXtraLocalization(
$"/{assemblyName};component/Localization/Language.xaml",
CultureInfo.GetCultureInfo("ru-RU"));

Notification(kernel.Get<MainWindow>());
}
}
}
}
Loading